Free project quoteFill out the enquiry form and we'll get back to you as soon as possible.
Contact Us: 858-683-3692
Updated: June 15, 2017
Isn’t it frustrating that you have to search for a product for hours? What if you could just chat and get your desired product, without having to tear your hair trying to figure out where to look? And what if additionally, you could win 75% cashback by just the click of a button? Way too much too ask right? What if I told you that you could build a chatbot to do this in just 20 minutes, without a single line of code!
So let’s build a retail Messenger chatbot which chats with customers and offers promo codes and coupons for all products. For our demo, we will build the bot for an imaginary retailer named: AbcElectronix, which sells TVs, Washing Machines, Home Appliances, and other electronic goods.
To begin, here is the flow diagram of our bot.
The tech stack that will be used for this bot is:
So without further ado, let’s begin.
Begin by watching this 3 min video to get an idea of how API.ai works.
Then, log in to your API.ai account and create a new agent called PromoBot. Select Intents, and create the following intents:
An Intent is a list of examples of user inputs. Let’s say, to begin a chat, a user might say: “Hi”, “Hi there”, “Wassup”, “Hello” or “Anybody there?”. So these examples are fed in the Intent, and API.ai uses Machine Learning to learn for them. Thus, when we launch the app if the user says “Hey”, API.ai recognizes it because it has learned from similar examples.
Let’s now take a concrete example and develop the Default Welcome Intent. User says, enter the following examples:
Then, scroll down and under Text Response, type: “You can win exciting up to 75% cashback offers on any product :)”.
Save, then test it by typing “Hi” in Try it now…. As you can see our bot detected the intent, then gave the correct response!
Similarly, you can add Text Responses to each Intent mentioned earlier and test them. So until now, using API.ai, we have created a powerful bot that understands the user input and gives an appropriate text response.
Download the code from here and extract the zipped file. Now let’s deploy the code on Heroku. First, you will need to install the Heroku
Toolbelt. Then log in to Heroku and create a new app:
In-App Name, input the desired name for your bot and then click Create App.
Now return to your terminal and deploy your app on Heroku:
cd path_to_files_downloaded heroku login git init heroku git:remote -a replace_this_with_bot_name git add. git commit -m “Initial Commit” git push heroku master heroku config:set WEB_CONCURRENCY = 3
Important: When you push your changes to Heroku, you will be provided with a URL. Store it somewhere for you will need it in the next step.
First, start by creating a Facebook Page here. If you have one, ignore, and proceed. Next go to the Facebook Developers Page, under My Apps on the top right corner select Add a New App. When a dialog box opens, under Display Name ID enter any name you want to be displayed on Facebook. Fill out the rest of the fields and create your App Id. Under Add Products on the left, click on Messenger and get started.
Now let’s set up the webhook. A webhook is basically a URL. Paste the URL you had from Heroku, and under Verify Token, enter: “my_voice_is_my_password_verify_me”. Aso, tick on messages and messaging_postbacks. Finally, verify and save.
Now, let’s get the Page Access Token. From the drop-down, select your page, and copy the code generated.
In the files downloaded, open: promobot.py, and paste the code in for the variable: PAT.
Open API.ai, and click on the gear design on the top left. From API keys, copy the Client access token and paste it in the code in the quotes of the variable CLIENT_ACCESS_TOKEN.
Finally, add, commit, and push the changes to Heroku:
git add . git commit -m “Update” git push heroku master
Now go to your Facebook page, and enjoy chatting!
You can customize the bot to your preference. In promobot.py, there are 3 methods which are key and which you should modify:
By modifying just these 3 sections, you can tailor and expand your chatbot to your need!
Good or bad, we’d love to hear your thoughts. Find us on Twitter (@Bitcot) or write into – [email protected]
Read More Article:
Need help? We design, build, and grow digital products across Android,iOS, and web.
Talk to Our ExpertsNeed support? Get in touch today and let’s discuss your business technology needs.
In today’s fast-paced and highly competitive business world, automation has become a necessity rather…
The opportunities in the tech world today are simply mind-boggling. There are already over 2 billion Android…
Contact Us: 858-683-3692
I have Known BitCot for 4 years and have been impressed with the diversity and quality of BitCot work. With that solid foundation it was really easy to select BitCot as our development partner.
OUR WORK WAS FEATURED ON