Day 14-15: Messenger ChatBot that responds with kitten images

#100DaysOfCode

As you might have guessed by now, weekends I like to work on a single project and this weekend was all about incrementally adding more intelligence to the messenger ChatBot. Checkout the first part of this app here in my previous post.

All the code for this project can be found on my github

Project: Messenger chat bot with AI to reply with rich messages and whats more interesting than a bot that replies with kitten images! Use the send/receive API that allows rich messages containing images and buttons for custom actions.

Step 1: Kitten message logic

We will build a simple method that takes in the keyword kitten and image size to responds with a cute kitten image of the requested size along with buttons with call to action for like.

Step 2: Update the message loop of ChatBot

Modify your Day 13 project’s message loop to allow this new method which will continue to echo the message in case kitten is not requested.

if (event.message && event.message.text) { 
if (!kittenMessage(event.sender.id, event.message.text)) {
sendMessage(event.sender.id,
{text: “Echo: “ + event.message.text});
}
}

Step 3: Deploy the app

git add .
git commit -m ‘Adding kitten images response’
git push heroku master

Now your chatbot should reply with kitten image when you give it “kitten size size”.

Day 14 & 15 of #100DaysofCode DONE

If you enjoyed this, please click 👏 so that others can enjoy it as well. Follow me on Twitter @HariniLabs to get the latest updates or just to say Hi :)

PS: I curate a bi-weekly #WomenInTech newsletter for a dose of inspiration from the world of tech and yes men can signup too! Get it here :)