Techsload
Facebook twitter
Featured Posts

Featured Featured
whatsapp-data-subscription-for-mtn-airtel-9mobile-glo
Whatsapp Data Subscription For MTN, Airtel, 9mobile And Glo
rewards-to-top-most-active-contributors-for-september-2017
Rewards to Top Most Active Contributors for September 2017
TeeXclusive Premium Responsonsive Blogger Template
TeeXclusive Premium Responsonsive Blogger Template
How to See Photos on Facebook Free Mode
How to See Photos on Facebook Free Mode


Check Out Our Unlimited Wapka Codes HERE
Check Out Our Unlimited Blogger Gadget Codes HERE
Download The Best Ever Blogger Template HERE
Check Out Our Best Unlimited Cloned Scripts HERE

Friday, 1 December 2017

Step-by-Step Instructions for Building a Basic Facebook Chat Bot


By: Okereke Ifeanyi ifetex | Time: December 01, 2017 | Label: |



Let’s build a chat-bot using FB Messenger, API.ai and PythonAnywhere in about 10 minutes. No server setup, 60 lines of code — easy.

Techsload boat
What we’ll need:
*.an api.ai account
*.a PythonAnywhere account
*.your Facebook account

Once you’ve registered for these, we can begin.
Please follow the stepsin orderas the FB Messenger setup requires our webApp to respond.
Techsload apiai
Create an ‘agent’ on api.ai, call it ‘MyAgent
Click ‘Domains’ to import a few conversational domains: “Small Talk” and “Wisdom”.
create api
Click on “Intents” and let’s create a simple intent:
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1600/1*F1x-2YxhGQsi0Ie7Qo_UQA.png?ssl=1" alt ="simple techsload intent" >
and its response: 42
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1600/1*bqxEcpL6A-VJcE1AbPaNhw.png?ssl=1" alt ="techsload" >
Click “Save” then test it by using “Try it now…” in the upper right.
We now have a simple chat-bot.
To call it from our code we’ll need its “Client access token”. To see this information, click on the gear to the right of ‘MyAgent’ in the upper-left.
< img src ="https://i0.wp.com/cdn-images-1.medium.com/max/1600/1*2nmpCxZB8JxKxraUMDUXZA.png?ssl=1" alt ="Techsload test" >
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1200/1*pqlvhAYp37tUjvoin3fbvg.png?ssl=1" alt ="Techsload payonany" >
The next step is to run a WebApp (our ‘webHook) using Python and Flask on pythonanywhere. This will be the back-end to our chat-bot.
Add a new WebApp.
< img src ="https://i0.wp.com/cdn-images-1.medium.com/max/1600/1*07d9sd01uAEumS283YGO3A.png?ssl=1" alt ="techsload" >
Provide a prefix for your WebApp:some-name. pythonanywhere.co m
Select ‘Flask’ for a framework, onPython 3.5
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1200/1*XFK524G5310PzF7LIJL1Ug.png?ssl=1" alt ="techs load" >
You should see a defaultflask_app.pyin your WebApp files directory. Click to edit it.
Here’s our 60 lines of code to handle the flow between FB messenger and api.ai:
use your FB and api.ai credentials
You will need to pip install packages (eg. apiai) in your pythonanywhere Bash console, as follows:
< img src ="https://i0.wp.com/cdn-images-1.medium.com/max/1600/1*nWtp-7VBe0s4Q72KyzOngA.png?ssl=1" alt ="TEchsLOAD" >
installing apiai in Bash console
Also remember to restart your pythonanywhere web app anytime you alter the code. Click on the circular button in the upper-right, as shown below:
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1600/1*9muloRAD6tu9qoROQ1wk9A.png?ssl=1" alt ="TL" >
pythonanywhere shortcuts
If everything is in place you should be able to ping your new Flask app:
< img src ="https://i2.wp.com/cdn-images-1.medium.com/max/1600/1*cz4hpgZK9CX9vaCccwei3A.png?ssl=1" alt ="tl" >
be sure to use your URL prefix instead of ‘gk.’
Now we can setup a FB page and messenger setup.
This will take 5 quick steps.

Step 1: Create a new FB page
(click on the link above to create a new page) Give it a name, like ‘BuildBot10mins’, or something less idiotic.
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1600/1*koR8cPIy2rwvimjSPtaszg.png?ssl=1" alt ="TL" >
Step 2: create a FB App
Click “Skip and Create App ID” at the top right. Then create a new Facebook App for your bot and give your app a name, category and contact email.

Step 3: create a new access token

Create a new token (for the FB page created in step 1):
< img src ="https://i1.wp.com/cdn-images-1.medium.com/max/1600/1*cBhykWzV2lXln4hgZ9E9tg.png?ssl=1" alt ="fb token" >
Copy this new Access Token andPaste itin your pythonanywhere code (line 4: under # FB messenger credentials)

Step 4: create our WebHook, click “Setup Webhooks”
< img src ="https://i0.wp.com/cdn-images-1.medium.com/max/1600/1*ik-tHU2Tw6AgdlfiQ9Rsrg.png?ssl=1" alt ="TL" >
Provide your Callback URL (be sure to use https://)
Use the same verify token specified in your pythonanywhere code.
< img src ="https://i2.wp.com/cdn-images-1.medium.com/max/1600/1*XOSL2V7SOnRdaWXMphLL5A.png?ssl=1" alt ="TL" >
be sure to specify https:// for the Callback URL





No comments:

Post a Comment

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();