0.1.5 • Published 6 years ago

fb-messenger-platform v0.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Build Status Coverage Status code style: prettier

messenger-platform

A NON official node client for Facebook Messenger Platform

Init

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'});

Send

Send a message

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));

Send an action

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));

Send a Generic Template

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));

Messenger Profile API

More about this api here: https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api

Set the Get Started payload

Facebook Doc

messenger.setGetStarted(<PAYLOAD>).then(response => console.log(response));

Set the Greeting text

Facebook Doc

Set the whitelisted domains

Facebook Doc

Set the persistent menu

Facebook Doc

Handover Procotol

More about this part of the API here : https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol

Take the thread

Facebook Doc

Pass the thread

Facebook Doc

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

7 years ago