This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = require('debug')('hello-world:app'); | |
const { Messenger, responses } = require('launch-vehicle-fbm'); | |
const messenger = new Messenger(); | |
messenger.start(); | |
// EVENT HANDLERS | |
///////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = require('debug')('hello-world:app'); | |
const { Messenger, responses } = require('launch-vehicle-fbm'); | |
const messenger = new Messenger(); | |
messenger.start(); | |
// EVENT HANDLERS | |
///////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = require('debug')('hello-world:app'); | |
const { Messenger, responses } = require('launch-vehicle-fbm'); | |
const messenger = new Messenger(); | |
messenger.start(); | |
// EVENT HANDLERS | |
///////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Messenger, responses } = require('launch-vehicle-fbm'); | |
const messenger = new Messenger(); | |
messenger.start(); | |
// EVENT HANDLERS | |
///////////////// | |
messenger.on('text.greeting', ({senderId, session, firstName, surName, fullName}) => { | |
const greeting = new responses.Text(`🤖 beep bop boop. Hello ${fullName}, I am a bot.`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Messenger } = require('launch-vehicle-fbm'); | |
const messenger = new Messenger(); | |
messenger.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object | |
function Generic(elements) { | |
this.attachment = { | |
type: ‘template’, | |
payload: { | |
template_type: ‘generic’, | |
elements: elements | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object | |
function Image(url) { | |
this.attachment = { | |
type: ‘image’, | |
payload: { url } | |
}; | |
} | |
// Application Usage | |
messenger.send(senderId, new Image(imageUrl))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routeEachMessage(messagingEvent) { | |
const cacheKey = messagingEvent.sender.id; | |
return cache.get(cacheKey) | |
.then((session = {_key: cacheKey, count: 0}) => { | |
// check if profile info is already in the session, | |
// if not, fetch it from Graph API | |
}) | |
.then((session) => { | |
session.count++; | |
if (messagingEvent.message) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
messenger.on(‘message.image’, ({senderId, url, session}) => { | |
// cool bot stuff | |
… | |
// reply to the user! | |
messenger.send(userId, { text: ‘something a robot would say’ } ); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Example Facebook Messenger app that pulls the user's public profile and echoes back any messages sent | |
with the user's first and last name. This one uses BotKit. | |
So if I sent the bot "Good morning!" it will reply to me with "Echoing message from Jeff Israel: Good morning!" | |
*/ | |
const reqPromise = require('request-promise'); | |
const graphApiUrl = 'https://graph.facebook.com/v2.6'; |
NewerOlder