I am trying to add emojis to web chat response from the bot. I have tried markdown but that doesn't seem to work. What would be the best way to include emojis in the response for a WebChat?
Asked
Active
Viewed 5,411 times
4
-
Are you using C# or NodeJS? Where are you editing your code? – Corina Mar 12 '17 at 06:40
1 Answers
15
To get emoji to work, you can use Unicode emoji for web chat. If you are creating the bot in C#, it is important to note that Unicode is denoted through an escape sequence. I edited my bot in Visual Studio.
The code for the reply looks like this:
Activity reply = activity.CreateReply($"You sent {activity.Text}. \U0001F600 Your greeting status is {SentGreeting}");
In this case, the emoji I am using is within the code as: \U0001F600
\U
is the escape sequence that C# will recognize, and note the three 000
's that are added in place of the '+' when retrieving emoji from Unicode.org standard format.
Edit: from @mgbennet: For Nodejs, you can use the surrogates of the emoji unicode to get them to display using String.fromCharCode(0xD83D, 0xDE01)

Corina
- 844
- 7
- 15
-
3If you want add a Unicode emoji in Node.js, you can use `"Message text with a " + String.fromCharCode(0xD83D, 0xDE01) + " in it"` to get "Message text with a in it". See [this thread](http://stackoverflow.com/questions/6985851/how-to-render-32bit-unicode-characters-in-google-v8-and-nodejs). – mgbennet Mar 13 '17 at 20:39
-
1to be more specific, you don't really want "fromCharCode" as then you need to deal with more unicode complexity than you want - epecially for high value codepoints. You really want the function that can just take the 32-bit codepoint, which is much easier: Docs found here: https://learn.microsoft.com/en-us/scripting/javascript/reference/string-fromcodepoint-function-javascript ... or here (with good examples): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint – Chris M. Mar 13 '17 at 23:43
-
Direct on Visual Studio works fine, but if the codes comes from a variable I was not able to make it work from a text stored in database. var response = "You sent \U0001F600" Activity reply = activity.CreateReply(response); – Fernando.M Sep 18 '18 at 20:29