Socket
Socket
Sign inDemoInstall

fb-bot

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fb-bot

SDK wrapper to verifyRequest, send message, recieve with Facebook Messenger Bots.


Version published
Weekly downloads
1
Maintainers
1
Created
Weekly downloads
 

Readme

Source

fb-bot

SDK wrapper to verifyRequest, send message, recieve with Facebook Messenger Bots.

NPM

Install

$ npm install --save fb-bot

Initializing

This link initializing module parameters.


var express = require('express');
var facebookModule = require('fb-bot.js');
var app = express();
    
facebookModule.init({
  APP_SECRET: 'YOUR_APP_SECRET',
  VALIDATION_TOKEN: 'YOUR_VALIDATION_TOKEN',
  PAGE_ACCESS_TOKEN: 'YOUR_PAGE_ACCESS_TOKEN',
  SERVER_URL: 'YOUR_SERVER_UR'
});

app.use(bodyParser.json({ verify: facebookModule.verifyRequestSignature }));

Usage

 ### 2 important funtions
    facebookModule.sendTextMessage(_senderId, _message).then( ... )
    facebookModule.messageListener(data, callback)

Send an Echo message back to user

//Facebook message 
app.post('/webhook', facebookModule.parsePOST, function (req, res) {
  var dataList = req.afterParse ;
  dataList.forEach(function(data){
    facebookModule.messageListener(data, function(){
      facebookModule.sendTextMessage(data.senderId, data.message.text);
    });
  });
  res.sendStatus(200);
});

Send url of attachments back to user

//Facebook message 
app.post('/webhook', facebookModule.parsePOST, function (req, res) {
  var dataList = req.afterParse ;
  dataList.forEach(function(data){
    facebookModule.messageListener(data, function(){
      facebookModule.sendTextMessage(data.senderId, data.message.attachments[0].payload.url);
    });
  });
  res.sendStatus(200);
});

Two import routes

Important
  • GET /webhook
  • POST /webhook
  • /webhook is default url routes where facebook send verification to
##  Verification

app.get('/webhook', facebookModule.authGET, function (req, res, next) {
    res.status(200).send(req.query['hub.challenge']);
});

## Recieve Message

app.post('/webhook', facebookModule.parsePOST, function (req, res) {
  var dataList = req.afterParse ;
  dataList.forEach(function(data){
      // ....
  });
  res.sendStatus(200);
});

License

MIT

Keywords

FAQs

Last updated on 10 Nov 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc