Reputation: 61
I am developing a bot with the Bot Framework. When receiving a message I need to detect emojis sent in the incoming message.
I was thinking of using a regex to do this but I am not able to. The problem is that different channels send the emoji differently to the bot. I have registered a listener to the 'receive' event and took a look at the text provided for different channels sending the same smile emoji:
:smile:
<ss type="smile">:)<ss>
😀
I need to identify which emoji I am receiving and act accrodingly. What I ideally would like is to receive the unicode character for the emoji no matter what channel I am using. Is there a way of doing this?
Upvotes: 2
Views: 1798
Reputation: 782
I think you can inspect the user response with middleware and then convert (based on the channel your message was sent) to any universal emoji.
In your sample:
Your result may be an: ":)". It can be extremely complex to cover all the emojis from all the channels supported.
var bot = new builder.UniversalBot(connector, [
function (session) {
builder.Prompts.text(session, 'Please send an emoji...');
},
function (session, result) {
console.log(result.response);
}
]);
const convertEmoji = (event) => {
if (event.source === "skype") {
if (/laugh/g.test(event.text)) {
event.text = ':D';
}
}
};
bot.use({
receive: function (event, next) {
convertEmoji(event);
next();
}
});
Take in consideration that this will apply to all messages user sent to bot.
Upvotes: 2