UNPKG

bootbot

Version:

Facebook Messenger Bot Framework

33 lines (28 loc) 795 B
'use strict'; const BootBot = require('../'); const config = require('config'); const fetch = require('node-fetch'); const GIPHY_URL = `http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=`; const bot = new BootBot({ accessToken: config.get('access_token'), verifyToken: config.get('verify_token'), appSecret: config.get('app_secret') }); bot.hear(['hello', 'hi', 'hey'], (payload, chat) => { chat.say('Hello there!'); }); bot.hear(/gif (.*)/i, (payload, chat, data) => { const query = data.match[1]; chat.say('Searching for the perfect gif...'); fetch(GIPHY_URL + query) .then(res => res.json()) .then(json => { chat.say({ attachment: 'image', url: json.data.image_url }, { typing: true }); }); }); bot.start();