Skip to content

๐Ÿค‘ Messenger Quick Replies with Wit.ai Integration ๐Ÿ’ฐ To get latest update about the market ๐Ÿ’ธ

License

Notifications You must be signed in to change notification settings

Gauravk2610/ShareMarket-Crypto-Currency-Bot-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ShareMarket-Crypto-Currency-Bot-

Messenger Quick Replies with Wit.ai Integration

AddAudioToVideo1600666759393-001 (1)-min

ShareMarket & CryptoCurrency Bot

Messenger Quick Replies & Wit.ai Integration

This is Written Tutorial on how you can create the same chatbot with perfect explaination


Facebook app allows us to retrieve and post request as well as post data on facebook via Facebook API.

Facebook API provides the interface and methods to interact with the Facebook App.

The Facebook API acts as the interface between the user and the Facebook.

  1. Create A Facebook Page thats a Simple Process
  2. Go To https://developers.facebook.com/
  3. You will see a Awesome interface where you can login to your facebook account. Login button at the top right besides the search icon . Login Through Your Credentials .
  4. Click on My Apps which will navigate you to the Create App page .
  5. So Click on Create App . You will be prompted with 4 options select the one which interests you here we will be using the first one Manage Business Integration option, then continue . Enter your app name EG:- test-app. Now select the app purpose. Then Create App . Now complete the security check recaptcha and submit.
  6. Then you will be navigated to a page were you will be prompted to add products to your App in our case it is messenger . Click on Messenger Setup Button. &. Navigated to the next page were you can add and make changes to the settings . Now scroll down towardds the access token . Create a New Page if you don't have else add a page
  7. Once you login with the credentials you give the test-app the authority yo manage & message to the page . Once completed you will be given your page access token keep it safe . Select the fb page and continue . Click on Generate Token to get your access token .

Time To Set Up Your Project

So This Is A Pure Python Based Tutorial

Requirements

  • Python3 Installed
  • pip install virtualenv
  • create a virtual env and activate it
  • pip intall flask, requests, pymessenger, bs4, wit

So webscrapping will be playing an important role in this


Webhook


So we have to set up a webhook for our application were we will be adding a callback url through which we can handle all kinds of requests . When we setup a webhook we need to verify our callback url .

So in the docs provided at the https://developers.facebook.com/ is in the java format we will be doing it using python

  1. Create a file app.py
  2. Now import all the dependencies and packages and initilaize your flask app
  3. Now check the Veriify function in the app.py file through which we will be verifying our callback url. So the word 'hello' is our callback url token. so when you run the file its runs on the local host for live web interaction we need to take it online for that purpose we need to install ngrok through which you can tunnel up your localhost network .
  4. Visit https://ngrok.com/ and install it once done open the terminal in the file were ngrok is extracted and run the command ngrok.exe http 80
  5. Now you can run your app.py and then then url in ngrok provided enter it at developers.facebook.com for webhook callback url and enter the verifcation token i.e hello and select the webhook services.

bandicam 2020-10-26 09-52-38-374


Event Handling


Now we will handle messaging events. So as you see in the app.py we have setup a app route

bandicam 2020-10-26 10-02-03-374

The Function def webhook(): will be handling all kinds of requests If you want you can event print out the whole request to see how the actually the request is been received

We are actually handling and extracting the data from the json format request and extracting the relevant data

bandicam 2020-10-26 09-14-02-542


Webscrapping


So Now we have to create some other files from were will firstly do some webscrapping and extract the relevant data .

Now you can open the other python files to check what exactly is happening and in which format is exactly the data been stored

For the sharemarket database we will be scrapping data from https://www.moneycontrol.com/ & for crypto-currency https://coinmarketcap.com/ we will be extracting the required data and storing it is a certain format as required and specified in messenger quick replies docs

Open utils.py to get the basic idea how exactly the data is scrapped and filtered out and is stored in the json format bandicam 2020-10-26 09-06-10-557

This What the database looks like

bandicam 2020-10-26 09-56-38-225

Similarly You can check the other python files to see what and how data is filtered out and stored


Wit.ai Integration in python


Now we will be creating and training the bot to analysize the messages firstly open https://wit.ai/ login and create a app and start training it with some local commands and then create entities, entity EG:- price of tcs

Here the entity will be share_market

So go on training to increase the accuracy of your bot

Now open user_response.py now take the access token and see how the response is been handled

bandicam 2020-10-26 09-18-34-138


App.py Now Open This File To Check How All The Responses are handled


bandicam 2020-10-26 09-25-27-468

About

๐Ÿค‘ Messenger Quick Replies with Wit.ai Integration ๐Ÿ’ฐ To get latest update about the market ๐Ÿ’ธ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages