Add explain command
Closed this issue · 0 comments
Emojibot can sometimes react with emojis that are quite a mental leap from the input text. It would be handy if it could explain itself sometimes.
This could be implemented using a Slack slash command taking the input text and the received emoji. For example:
/explain Today is a good day to code :meat_on_bone:
It would respond with a possible explanation:
good => :meat_on_bone:
To implement we could reuse the logic in bot.js. When mapping from input words to emojis we could store the path taken during the map-reduce. For example, in the above input text 'good' is the only source of emojis, so the possible paths are:
['good', '+1']
['good', 'accept']
['good', 'chart_with_upwards_trend']
['good', 'meat_on_bone']
['good', 'ok']
['good', 'sparkle']
['good', 'sparkles']
['good', 'star2']
We then filter the paths by the received emoji to get:
['good', 'meat_on_bone']
Which we can then translate into human readable form as above. It's possible to obtain multiple possible paths for a given input text and received emoji, in which case we choose one by random. This is fine since the bot chooses an emoji by random from the possible choices so we'll never know the actual path taken.
Reusing the bot map-reduce logic means that the current responding logic just takes the last component of the path, whereas explain will use the full path.