Skip to content

Instantly share code, notes, and snippets.

@MichaelBarney
Last active May 1, 2020 19:45
Show Gist options
  • Save MichaelBarney/2165aa305af5734f4d023cb07977a2cf to your computer and use it in GitHub Desktop.
Save MichaelBarney/2165aa305af5734f4d023cb07977a2cf to your computer and use it in GitHub Desktop.
A simple implementation of a Botkit configuration for Facebook Messenger
// Import Botkit
const { Botkit } = require('botkit');
// Import Facebook Adapter
const { FacebookAdapter, FacebookEventTypeMiddleware } = require('botbuilder-adapter-facebook');
// Load process.env values from .env file
require('dotenv').config();
// Configure Facebook Adapter
const adapter = new FacebookAdapter({
enable_incomplete: true,
verify_token: process.env.FACEBOOK_VERIFY_TOKEN,
access_token: process.env.FACEBOOK_ACCESS_TOKEN,
app_secret: process.env.FACEBOOK_APP_SECRET,
})
// emit events based on the type of facebook event being received
adapter.use(new FacebookEventTypeMiddleware());
const controller = new Botkit({
webhook_uri: '/api/messages',
adapter: adapter
});
// Once the bot has booted up its internal services, you can use them to do stuff.
controller.ready(() => {
// load traditional developer-created local custom feature modules
controller.loadModules(__dirname + '/features');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment