Dialogflow Restaurant Chatbot Tutorial | 3

Part 3: Small Talk and Integration with Facebook & Telegram

Adi Cucolaș
Chatbots Life

--

OBJECTIVES

In this part, the bot will become more conversational by adding Small Talk and we’ll also integrate it with Facebook and Telegram. I choose to make the integration early in the series, so you can test the bot not only on Dialogflow, but actually see it in action on a platform. You can skip this part and come back later if you prefer it that way tho.

SMALL TALK

Small talk makes your bot more conversational by having responses for casual conversation topics like greetings or jokes, etc. instead of redirecting the user to a fallback response.

There are more options for adding small talk to your Agent, I will only show you two of them: the easiest one and the one I prefer.

SMALL TALK 1

The first option is the easiest, just go to Small Talk tab, Enable it and press Save.

The answers are predefined by Dialogflow, but you can’t see the default values. You can customize the responses by going through each category and add your desired answers.

If you add multiple answers, Dialogflow will randomise and display only one. Don’t forget to Save.

Top 3 Bot Tutorials

1. Which are the best chatbot frameworks?

2. How we wrote a Wirecutter-like bot with Reply.ai in just a few hours

3. How to Create a Facebook Messenger Bot with Ruby on Rails

Although this option is very straightforward and easy to implement, I would not recommend you to use it, because you don’t have enough control over the small talk and you can’t export it to other Agents.

SMALL TALK 2

The second option is the one I prefer to use, it allows you to choose which answers you want the bot to be able to respond to and export these Intents to any other Agent, so you don’t have to write all these answers for each Agent you have.

This time we are going to use a Prebuilt Agent. Prebuilt Agents already contain Intents and Entities which can help you accelerate the process of building the bot.

Step 1: Add a Prebuilt Agent

Go to Prebuilt Agents tab, search for Small Talk and press Import.

Press OK.

Press on PROCEED TO AGENT.

Great, now you have an agent with all the small talk Intents. You can customize them to fit your general needs an the import them to different agents. This allows you to be more structured. You can even delete the ones you don’t want to use or add new ones.

Step 2: Import Small-Talk to your Agent

You can import as many Intents as you want or none. I choose to import only the ones for greetings. To do that search greetings in the search bar.

Then select the ones you want by hovering over them and ticking the box in the left or select all of them by ticking the highest box.

Press on Copy, select your Agent and press Start.

You don’t need to select all the checkboxes in this case, because we don’t have what to overwrite. Press on PROCEED TO AGENT and that’s it!

We now have two Intents which have “hi”/”hello” as training phrases, so we have to do something about it. Go to Default Welcome Intent and delete them from there. We still want this greeting to show up when a user interacts with our bot, so add FACEBOOK_WELCOME and TELEGRAM_WELCOME to Events.

Don’t forget to Save.

Using the 2nd option you will be able to see what Intent is triggered by any training phrase just by typing it in the test console (the one on the right), but if you want to search the responses of those Intents, Deborah Kay has a great tutorial on how to do it using Google Sheets.

INTEGRATE TELEGRAM

We’ll start with Telegram, because it’s easier.

Go on Telegram on whatever version you prefer (phone/windows/web/etc.) and search for @botfather or follow this link https://telegram.me/botfather.

Type /start and Bot Father will show you a list of commands.

We are only interested in /newbot command so go ahead and type it. You will have to choose a display name for the bot (you can change it later) and a username (which can help people find your bot on Telegram).

Now copy the access token (the one I hid for obvious reasons) and go back to Dialogflow.

Go to Integrations tab and press on Telegram. Enable the integration by toggling it in the right upper corner and paste in the access token you got from the Bot Father. Press Start and you’re ready to go.

We’ll test the bot after we integrate Facebook as well.

INTEGRATE FACEBOOK

Integrating Facebook is a bit more complicated, it requires you to have a Facebook page and a Developers account. I will not go through the whole process, but I will leave some useful links.

I will imply that you already have a page and a developers account.

Step 1: Create a Facebook App

Go to Facebook Developers (https://developers.facebook.com/apps/). And press on Add a new App.

Enter a display name for the app and your contact email. Press Create App ID and complete the captcha.

Press Set up on Messenger.

Go to Token Generation section and choose the Facebook page you want to connect the chatbot to.

Copy the token, then open a new tab in your browser and go to your Dialogflow agent.

Step 2: Set up Dialogflow Integration

Go to Integrations tab in Dialogflow. Enable the integration by toggling it in the right upper corner and paste in the access token you got from Facebook Developers. For security reasons type in a Verify Token and press Start.

Keep the Callback URL and Verify Token handy.

Step 3: Configure the Webhook

Return to the Facebook Developer Console, scroll down to Webhooks and press on Setup Webhooks.

Copy&Paste the Callback URL and Verify Token from Dialogflow and check the messages and messaging_postbacks options under Subscription Fields.

Press on Verify and Save and you’re done!

This is everything you need to do in order to test your chatbot. It requires more steps in order to properly publish the app and let other people access it through Facebook Messenger. Let me know if you’d be interested in a tutorial for that!

TRY OUT

Now that both integrations are set, it’s time to test what we’ve done so far. Search the username of your bot on Telegram or just follow the link The Bot Father gave you and start a conversation with your bot. When you’re tired of talking to your bot on Telegram, move to Facebook. Find the page you connected the bot to and send a message.

CONCLUSION

The bot is now able to respond to common user inputs which makes it more conversational. Also, you’ve learned how to integrate the Agent on 2 of the most used messaging platforms Facebook and Telegram. Although not everyone can see your bot on Facebook yet, you can share your work using Telegram and show your friends how cool your bot is.

As always, if you have any questions don’t hesitate to leave them in the comments sections and give some claps if you liked this part.

--

--