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

Harini Janakiraman
May 23, 2016 · 2 min read

#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”.

Image for post
Image for post

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 :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store