Skip to content

Instantly share code, notes, and snippets.

const debug = require('debug')('hello-world:app');
const { Messenger, responses } = require('launch-vehicle-fbm');
const messenger = new Messenger();
messenger.start();
// EVENT HANDLERS
/////////////////
const debug = require('debug')('hello-world:app');
const { Messenger, responses } = require('launch-vehicle-fbm');
const messenger = new Messenger();
messenger.start();
// EVENT HANDLERS
/////////////////
const debug = require('debug')('hello-world:app');
const { Messenger, responses } = require('launch-vehicle-fbm');
const messenger = new Messenger();
messenger.start();
// EVENT HANDLERS
/////////////////
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.`);
const { Messenger } = require('launch-vehicle-fbm');
const messenger = new Messenger();
messenger.start();
// Object
function Generic(elements) {
this.attachment = {
type: ‘template’,
payload: {
template_type: ‘generic’,
elements: elements
}
};
}
// Object
function Image(url) {
this.attachment = {
type: ‘image’,
payload: { url }
};
}
// Application Usage
messenger.send(senderId, new Image(imageUrl)));
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) {
@stripethree
stripethree / event-subscriber-message-image.js
Last active February 25, 2017 17:52
Event subscriber example for a user sending an image.
messenger.on(‘message.image’, ({senderId, url, session}) => {
// cool bot stuff
// reply to the user!
messenger.send(userId, { text: ‘something a robot would say’ } );
});
/*
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';