From 7b5f89a6dbd267d96e2ac1868b74f5544517c7c8 Mon Sep 17 00:00:00 2001 From: Maxime Lebastard Date: Tue, 30 Jan 2018 11:03:19 +0100 Subject: [PATCH] Add a method to set Express middlewares through BootBot --- README.md | 20 ++++++++++++++++++++ lib/BootBot.js | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 074285d..a27aa5a 100644 --- a/README.md +++ b/README.md @@ -731,6 +731,26 @@ Removes the Persistent Menu. ---------------------- +### Setup the embedded Express server + +You may only want to set the behavior of the Express server running Bootbot. + +#### `.use(expressMiddleware)` + +Use this method to add middlewares to the embedded Express server + +```javascript +'use strict'; +const BootBot = require('bootbot'); +const cookieParser = require('cookie-parser'); + +const bot = new BootBot(); + +bot.use(cookieParser()); + +bot.start(); +``` + ### Bypassing Express You may only want to use bootbot for the Facebook related config and the simple to use Send API features but handle routing from somewhere else. Or there may be times where you want to send a message out of band, like if you get a postback callback and need to end a conversation flow immediately. diff --git a/lib/BootBot.js b/lib/BootBot.js index 9808bb8..4c32f9b 100644 --- a/lib/BootBot.js +++ b/lib/BootBot.js @@ -26,6 +26,10 @@ class BootBot extends EventEmitter { this._conversations = []; } + use(handlers) { + this.app.use(handlers) + } + start(port) { this._initWebhook(); this.app.set('port', port || 3000);