Giter VIP home page Giter VIP logo

facebook-messenger-chatbot's Introduction

Facebook-Messenger-Chatbot

Facebook Messenger Chatbot tutorial

What is Chatbot ?

A chatbot is a computer program which conducts a conversation via auditory or textual methods. Such programs are often designed to convincingly simulate how a human would behave as a conversational partner, thereby passing the Turing test


This chatbot is for Facebook Messenger
chatbot

Setup


Go to developers.facebook.com
Login with fb account & create an app id
Go to App
Go to Add Products ->Messenger
In Messenger -> go to webhooks

Setup Heroku Account


It will be used in Callback Url of messenger webhook
SignUp/login
Create app
The only purpose for Heroku is that it just provides us a platform to push my code and this would be my webhook in messenger webhook seting. Otherwise , if you have https:// website, you dont need heroku.
Now install herolu-cli
sudo npm install heroku-cli -g
Open a terminal and type : heroku login
Enter your credentials and login
type : git init
type : touch index.php
type :git add .
type : git commit -m "First Commit"
type : heroku git:remote -a nameless-peak-18519 : This will make a git repo
type : git push heroku master
Open the app in Heroku . Copy the Url of app & Paste the url in Callback Url of messenger.
Now generate Token in Facebook by selecting the page
In webhook , select the same page and subscribe it

Install php-curl


sudo apt-get install php7.0-curl
sudo service apache2 restart

Set Up ngrok


Download ngrok from https://ngrok.com/
Go to the downloaded folder & Type : ./ngrok http 80
Now make an index.php and paste it /var/www/html/ . Code is in repo
Now paste this URL generated by ngrok into Messenger CallbackUrl
Generate Page Access Token and subcribe to that same page

First Reply


Now after setting this much open facebook.com/page_on_which_it_was_subscribed
Message something and a reply will come

JSON for setting Get_Started Button

Make the following Curl Request either through git bash or with npm package fb-get-started-button:

curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
 {
  "payload":"first hand shake"
 }
]
}' "https://graph.facebook.com/v2.6/1491142357630044/thread_settings?access_token=<PAGE_ACCCESS_TOKEN>"

JSON for Image sending :

Following is the JSON , if u want to send an image in a reply :

$jsonData= "{
     'recipient':{
	        'id': $userID
		    },
	    'message':{
	  	     'attachment' : {
	  		          'type' : 'image' ,
	  	           'payload' : {
			                  'url': 'https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
	  	             }
	            }
	}   	
	}" ;

To update Webhook


Go to the app on facebook
In the products section on LHS select webhook
Now click on Edit Subscriptions
Add a new CallbackURL or updated CallbackUrl and Token . Save & verify
Now u r done with it. NO need of deleting the app and creating it again

JSON for Sender Acton Response

$senderActionResponse='{
			"recipient":{
    				"id":"'.$userID.'"
  			},
  			"sender_action":"typing_on"
		}';

JSON for sending Button in Response

$response =  '{
			  "recipient":{
			    "id": "'.$userID.'" 
			  },
			  "message":{
			    "attachment":{
			      "type":"template",
			      "payload":{
			        "template_type":"button",
			        "text":"Hi, there ! I\'m a minified version of a Bot . ",
			        "buttons":[
			          {
			            "type":"web_url",
			            "url":"https://www.linkedin.com/in/vidit2709",
			            "title":"Visit Developers LinkedIn"
			          },
			          {
			            "type":"web_url",
			            "url":"https://github.com/vidit-agarwal",
			            "title":"Visit Developers github"
			          },
			          {
			            "type":"web_url",
			            "url":"https://m.facebook.com/vidit.agarwal.79?ref=bookmarks",
			            "title":"Visit Developers Facebook"
			          }
			          
			        ]
			      }
			    }
			  }
			}';

facebook-messenger-chatbot's People

Contributors

vidit-agarwal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.