In Chapter 6, we discussed the basics of chatbots and how they are important to the growth of machine learning. Now, we’ll dive into the nuts and bolts of how you can set up a chatbot yourself. We briefly touched on the overall structure and components of a chatbot, as well as some of the third-party tools that exist to create chatbots, but we want to dive deeper into the concept and give you a strong idea of exactly how you can put down this guide and get to building your first chatbot.
Creating a Facebook Chatbot
Creating a Facebook chatbot from scratch isn’t extremely difficult, but the process can be a technical one. Below, we present two versions of this process: one for individuals who don’t have a high degree of coding knowledge and one for those readers who are more technically proficient.
For those of you who don’t have a technical background or access to a developer, Chatfuel may be the answer for you.
Backed by Yandex, Russian entrepreneurs Dmitrii Dumik and Artem Ptashnik founded . Chatfuel in 2015. Chatfuel builds chatbots on the Facebook Messenger platform. Users can train their own bots in the Chatfuel system. Natural Language Processing (NLP) in the system allows training information from the user to be applied to a larger web of related terms and phrases.
Chatfuel walks you through the same process that developers use as they code their applications. Once you sign up via your Facebook account, you’ll choose a page that you want to associate with your application. You may need to create a page if you intend to test your application before launching it.
The first and most basic setup for the Chatfuel bots is to create and link “blocks.” Blocks are essentially messages sent to users. For example, below is a “welcome” block in the back end of the system:
And what follows is how the block looks in Messenger.
The “link” here is the “Main Menu” button. When you press it, Chatfuel gives you the following:
You’ll remember that this choose-your-own-adventure style of logic is similar to some of the functionality CNN built into its Kik-based news bot.
You’ll get the most value from using the Chatfuel-integrated AI. This section of Chatfuel is the place where you’ll train your chatbot how to handle questions. You can respond with basic text, images, video, and other options.
Chatfuel offers a payments option that makes conversational commerce an option for bot builders.
Connecting to Facebook
The first step in creating your own Facebook chatbot through development is to create a working endpoint that delivers a 200 response code. Put simply, this step lets you talk directly with Facebook. Hartley Brody does a great job walking you through this step with a Github project to help you every step of the way with code. To execute this process, you’ll need Heroku, which is basically a cloud platform that allows companies to essentially become their own app companies by producing, sharing, tracking, and scaling their apps. Heroku offers app developers the advantage of avoiding complicated infrastructure hardware or scaled servers.
Choosing the Right Facebook Page
You’ll see that this is the second basic step to create your chatbot through third-party applications as well. You can use a Facebook page you currently have or begin a new page, but think of this page as the identity of your bot. It’ll be the group of people you can broadcast your bot to, and it’ll be the entity with whom your users will interact. Be careful with your choice and testing.
If you don’t already have one, you need to create a Facebook page. The Facebook Page is the “identity” of your bot, including the name and image that appears when someone chats with it inside Facebook Messenger.
If you’re creating a dummy one for your chatbot, it doesn’t matter what you name it or how you categorize it. You can skip through most of the setup steps.
In order to communicate with your bot, people will need to go through your page, which we’ll look at in a bit.
Create Your Facebook Application
Now you are ready to create a Facebook App for your bot. You’ll need to name your bot, categorize it, and give it some other basic info.
After you’ve created your App ID, you’ll have the option of selecting the product you want when setting up your app. You’ll choose Messenger, which serves as the platform for your chatbot.
Set Up the Messenger Application
All of the steps below need to happen in Facebook before you get into the code portion of your chatbot.
First, create a Page Access Token by clicking through the authentication flow (see below).
You’ll use this token to authenticate your requests when you try to send a message or reply to someone.
You’ll then need to create a webhook. Facebook will ask you for a callback URL, verification token, and subscription hooks. Hartley Brody’s tutorial and Github repository have more information on the specifics of these items. The Facebook Developers portal also has vital information on the Messenger Platform that can help you.
After you’ve configured your webhook, you’ll need to subscribe to the specific page for which you want to receive message notifications.
Get Chatty With Your Bot
Start sending yourself messages through your newly connected application. Go to the Facebook page, and under the options button next to “Share,” select “View Page as Visitor.”
This selection will allow you to message the page as a visitor.
Most developers use Heroku when building Facebook apps because Heroku allows developers to work with the language that’s most natural for them to use when coding.
Beyond Hartley Brody’s framework, you’ll find a few others worth noting that may help you or your developers with some plug-and-play code to get your chatbot talking.
One commonality you’ll notice is the way these chatbots work: They classify anticipated user questions or keywords and match them with responses.
Submit Your App for Review
Before Facebook verifies your application, only you and your page admins can test or launch the chatbot you’re creating. Facebook has to review all apps, but chatbots are especially large security risks. The capabilities to spoof human behavior, send malicious links, and use processes to retrieve private data are too real with this technology.
While you’re testing your bot, only you and other page admins can message the bot directly. You’ll have to go through a review process before your bot is open to the world, ready to chat with anyone.
Facebook seems to be quite thorough in its review process, and with good reason. The code for a messaging bot runs on your own servers and could change at any time, without Facebook knowing it’s changing.
As long as your application is a legitimate chatbot set up to enrich the user experience of people who like your page, you shouldn’t have any issues.
Similar to Chatfuel, Botsify allows you to build a chatbot on Facebook Messenger free. It also offers a paid version of its system to create a chatbot for a website. One of the interesting parts that’s special about Botsify is the ability for bot builders to use what it calls “stories.”
Stories are essentially user stories, but they also serve as the real training data for the bot. The creator builds out an entire possible interaction or series of interactions, with phrase and response alternatives. Within these stories, you’re able to connect outside APIs to bring data into the chatbot. These features are the right mix of user friendliness to allow anyone to build a bot, while also allowing for the maximum amount of customization.
Like Chatfuel, Botsify permits template linking similar to the CNN use case. These links allow information to easily be tied to various communications between bot and user.
Converse and Learning
The Converse and Learning tools in Botisfy bring the AI capabilities of this system to a new level. In this window, you’re able to “teach” your bot based on real conversations within the application that it wasn’t able to answer.
The templates section of the Botsify application will make marketers swoon. These templates feature various ways to maximize interaction with chatbot users.
With templates, you can allow various messages to be tied directly into product options that link to purchase opportunities.
API.AI is another third-party tool that permits chatbot creation; however, the focus here is not firmly centered around Facebook Messenger as the application platform. API.AI is able to build conversational interfaces with a number of applications and devices.
Below, you’ll find the way API.AI layers into the chatbot development process.
As you can see, API.AI serves as a hybrid model between custom-coded chatbots and full third-party service providers, giving you a ton of flexibility.
API.AI receives a query as either text in natural language or an event. The system matches the query to the most suitable intent based on information contained in the information the user enters into the “Intent” module. This area of API.AI is similar to Botsify’s “Stories.” The process of transforming natural language into actionable data is called Natural Language Understanding (NLU).
We’ve covered the subject of creating your own chatbot in quite some detail in this chapter, and we offered you some examples of several tools to consider when developing a chatbot on your own. In the next chapter, we’ll move beyond chatbots a bit and get you on the path to putting machine learning to work for you in your marketing efforts.