A NON official node client for Facebook Messenger Platform
Init an instance of Messenger with at least the Facebook token and your verify string
const Messenger = require('messenger');
const messenger = new Messenger({ token: 'your_token', verify: 'your_verify_string'});
You can send messages with just text :
messenger.sendMessage('recipient_id', {
text: 'My first bot message'
}).then(response => console.log(response));
You can send messages with text and attachment (or just attachment):
messenger.sendMessage('recipient_id', {
text: 'My first bot message',
attachment: {
url: 'http://example.com/myimage.png',
type: 'image'
}
}).then(response => console.log(response));
You can send messages with text and buttons (what FB call the button template):
const buttons = new Buttons();
buttons.add({
title: 'My Website',
url: 'http://mywebsite.com'
});
messenger.sendMessage('recipient_id', {
text: 'My first bot message',
buttons: buttons
}).then(response => console.log(response));
You can send an action in order to keep your user in touch with what your bot is doing. Possible actions : mark_seen, typing_on, typing_off
messenger.sendAction('recipient_id', 'typing_on').then(response => console.log(response));
Or even more easy for setting if your typing or stop showing the typing indicator :
messenger.setTyping('recipient_id', true).then(response => console.log(response));
More infos about generic template here: https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic
//Init Elements
const elements = new Elements();
//Add at least one element (and max 10)
elements.add({
title: '', //The title of the element
subtitle: '', //The subtitle of the element
image: '' //The url of the image
})
//Send a Generic template
messenger.sendGenericTempalte('recipient_id', elements, {sharable: false, imageRatio: 'square'}).then(response => console.log(response));
More about this api here: https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api
messenger.setGetStarted(<PAYLOAD>).then(response => console.log(response));
More about this part of the API here : https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol