项目作者: kassemitani

项目描述 :
Create Simple Facebook ChatBot Messenger using Node.JS
高级语言: JavaScript
项目地址: git://github.com/kassemitani/Facebook-Messenger-ChatBot.git
创建时间: 2017-07-28T08:39:30Z
项目社区:https://github.com/kassemitani/Facebook-Messenger-ChatBot

开源协议:

下载


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:

    1. 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.

    1. 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.

    1. 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.

    1. var express = require('express')
    2. var bodyParser = require('body-parser')
    3. var request = require('request')
    4. var app = express()
    5. app.set('port', (process.env.PORT || 5000))
    6. // Process application/x-www-form-urlencoded
    7. app.use(bodyParser.urlencoded({extended: false}))
    8. // Process application/json
    9. app.use(bodyParser.json())
    10. // Index route
    11. app.get('/', function (req, res) {
    12. res.send('Hello world, I am a chat bot')
    13. })
    14. // for Facebook verification
    15. app.get('/webhook/', function (req, res) {
    16. if (req.query['hub.verify_token'] === 'my_voice_is_my_password_verify_me') {
    17. res.send(req.query['hub.challenge'])
    18. }
    19. res.send('Error, wrong token')
    20. })
    21. // Spin up the server
    22. app.listen(app.get('port'), function() {
    23. console.log('running on port', app.get('port'))
    24. })