Skip to content

kassemitani/Facebook-Messenger-ChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Facebook-Messenger-ChatBot

Create Simple Facebook 🤖 ChatBot 🤖 Messenger using Nodejs on Heroku

Build the server

  1. Install the Heroku toolbelt from here https://toolbelt.heroku.com to launch, stop and monitor instances. Sign up for free at https://www.heroku.com if you don't have an account yet.

  2. Install Node from here https://nodejs.org, this will be the server environment. Then open up Terminal or Command Line Prompt and make sure you've got the very most recent version of npm by installing it again:

    sudo npm install npm -g
    
  3. Create a new folder somewhere and let's create a new Node project. Hit Enter to accept the defaults.

    npm init
    
  4. Install the additional Node dependencies. Express is for the server, request is for sending out messages and body-parser is to process messages.

    npm install express request body-parser --save
    
  5. Create an index.js file in the folder and copy this into it. We will start by authenticating the bot.

    var express = require('express')
    var bodyParser = require('body-parser')
    var request = require('request')
    var app = express()
    
    app.set('port', (process.env.PORT || 5000))
    
    // Process application/x-www-form-urlencoded
    app.use(bodyParser.urlencoded({extended: false}))
    
    // Process application/json
    app.use(bodyParser.json())
    
    // Index route
    app.get('/', function (req, res) {
    	res.send('Hello world, I am a chat bot')
    })
    
    // for Facebook verification
    app.get('/webhook/', function (req, res) {
    	if (req.query['hub.verify_token'] === 'my_voice_is_my_password_verify_me') {
    		res.send(req.query['hub.challenge'])
    	}
    	res.send('Error, wrong token')
    })
    
    // Spin up the server
    app.listen(app.get('port'), function() {
    	console.log('running on port', app.get('port'))
    })
    

About

Create Simple Facebook ChatBot Messenger using Node.JS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published