messaging-api-messenger
Messaging API client for Messenger
Table of Contents
Installation
npm i --save messaging-api-messenger
or
yarn add messaging-api-messenger
Usage
Initialize
const { MessengerClient } = require('messaging-api-messenger');
const client = MessengerClient.connect(accessToken);
You can specify version of Facebook Graph API using second argument:
const client = MessengerClient.connect(accessToken, 'v2.9');
If it is not specified, version v2.10
will be used as default.
API Reference
All methods return a Promise.
sendRawBody(body)
body
Type: Object
client.sendRawBody({
recipient: {
id: USER_ID,
},
message: {
text: 'Hello!',
},
});
send(userId, message)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
message
Type: Object
client.send(USER_ID, {
text: 'Hello!',
});
sendText(userId, text [, options])
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
text
Type: String
options
Type: Object
client.sendText(USER_ID, 'Hello!');
sendIssueResolutionText(userId, text)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
text
Type: String
client.sendIssueResolutionText(USER_ID, 'Hello!');
sendAttachment(userId, attachment)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
attachment
Type: Object
client.sendAttachment(USER_ID, {
type: 'image',
payload: {
url: 'https://example.com/pic.png',
},
});
sendAudio(userId, audio)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
audio
Type: String | Buffer | ReadStream
Send audio using url string:
client.sendAudio(USER_ID, 'https://example.com/audio.mp3');
or using ReadStream
created from local file:
const fs = require('fs');
client.sendAudio(USER_ID, fs.createReadStream('audio.mp3'));
sendImage(userId, image)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
image
Type: String | Buffer | ReadStream
Send image using url string:
client.sendImage(USER_ID, 'https://example.com/vr.jpg');
or using ReadStream
created from local file:
const fs = require('fs');
client.sendImage(USER_ID, fs.createReadStream('vr.jpg'));
sendVideo(userId, video)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
video
Type: String | Buffer | ReadStream
Send video using url string:
client.sendVideo(USER_ID, 'https://example.com/video.mp4');
or using ReadStream
created from local file:
const fs = require('fs');
client.sendVideo(USER_ID, fs.createReadStream('video.mp4'));
sendFile(userId, file)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
file
Type: String | Buffer | ReadStream
Send file using url string:
client.sendFile(USER_ID, 'https://example.com/receipt.pdf');
or using ReadStream
created from local file:
const fs = require('fs');
client.sendFile(USER_ID, fs.createReadStream('receipt.pdf'));
sendTemplate(userId, template)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
template
Type: Object
client.sendTemplate(USER_ID, {
template_type: 'button',
text: 'title',
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'USER_DEFINED_PAYLOAD',
},
],
});
sendButtonTemplate(userId, title, buttons) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
title
Type: String
buttons
Type: Array<Object>
client.sendButtonTemplate(USER_ID, 'What do you want to do next?', [
{
type: 'web_url',
url: 'https://petersapparel.parseapp.com',
title: 'Show Website',
},
{
type: 'postback',
title: 'Start Chatting',
payload: 'USER_DEFINED_PAYLOAD',
},
]);
sendGenericTemplate(userId, elements) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendGenericTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendTaggedTemplate(userId, elements, tag)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
Type: String
client.sendTaggedTemplate(
USER_ID,
[
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
],
'GAME_EVENT'
);
sendShippingUpdateTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendShippingUpdateTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendReservationUpdateTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendReservationUpdateTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendIssueResolutionTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendIssueResolutionTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendAppointmentUpdateTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendAppointmentUpdateTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendGameEventTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendGameEventTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendTransportationUpdateTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendTransportationUpdateTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendFeatureFunctionalityUpdateTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendFeatureFunctionalityUpdateTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendTicketUpdateTemplate(userId, elements)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendTicketUpdateTemplate(USER_ID, [
{
title: "Welcome to Peter's Hats",
image_url: 'https://petersfancybrownhats.com/company_image.png',
subtitle: "We've got the right hat for everyone.",
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'DEVELOPER_DEFINED_PAYLOAD',
},
],
},
]);
sendListTemplate(userId, items, buttons, topElementStyle) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
items
Type: Array<Object>
buttons
Type: Array<Object>
topElementStyle
Type: String
client.sendListTemplate(
USER_ID,
[
{
title: 'Classic T-Shirt Collection',
image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
subtitle: 'See all our colors',
default_action: {
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/shop_collection',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
buttons: [
{
title: 'View',
type: 'web_url',
url: 'https://peterssendreceiveapp.ngrok.io/collection',
messenger_extensions: true,
webview_height_ratio: 'tall',
fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
},
],
},
],
[
{
type: 'postback',
title: 'Start Chatting',
payload: 'USER_DEFINED_PAYLOAD',
},
],
'compact'
);
sendOpenGraphTemplate(userId, elements) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
elements
Type: Array<Object>
client.sendOpenGraphTemplate(USER_ID, [
{
url: 'https://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb',
buttons: [
{
type: 'web_url',
url: 'https://en.wikipedia.org/wiki/Rickrolling',
title: 'View More',
},
],
},
]);
sendReceiptTemplate(userId, receipt) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
receipt
Type: Object
client.sendReceiptTemplate(USER_ID, {
recipient_name: 'Stephane Crozatier',
order_number: '12345678902',
currency: 'USD',
payment_method: 'Visa 2345',
order_url: 'http://petersapparel.parseapp.com/order?order_id=123456',
timestamp: '1428444852',
elements: [
{
title: 'Classic White T-Shirt',
subtitle: '100% Soft and Luxurious Cotton',
quantity: 2,
price: 50,
currency: 'USD',
image_url: 'http://petersapparel.parseapp.com/img/whiteshirt.png',
},
{
title: 'Classic Gray T-Shirt',
subtitle: '100% Soft and Luxurious Cotton',
quantity: 1,
price: 25,
currency: 'USD',
image_url: 'http://petersapparel.parseapp.com/img/grayshirt.png',
},
],
address: {
street_1: '1 Hacker Way',
street_2: '',
city: 'Menlo Park',
postal_code: '94025',
state: 'CA',
country: 'US',
},
summary: {
subtotal: 75.0,
shipping_cost: 4.95,
total_tax: 6.19,
total_cost: 56.14,
},
adjustments: [
{
name: 'New Customer Discount',
amount: 20,
},
{
name: '$10 Off Coupon',
amount: 10,
},
],
});
sendAirlineBoardingPassTemplate(userId, attributes) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
attributes
Type: Object
client.sendAirlineBoardingPassTemplate(RECIPIENT_ID, {
intro_message: 'You are checked in.',
locale: 'en_US',
boarding_pass: [
{
passenger_name: 'SMITH/NICOLAS',
pnr_number: 'CG4X7U',
travel_class: 'business',
seat: '74J',
auxiliary_fields: [
{
label: 'Terminal',
value: 'T1',
},
{
label: 'Departure',
value: '30OCT 19:05',
},
],
secondary_fields: [
{
label: 'Boarding',
value: '18:30',
},
{
label: 'Gate',
value: 'D57',
},
{
label: 'Seat',
value: '74J',
},
{
label: 'Sec.Nr.',
value: '003',
},
],
logo_image_url: 'https://www.example.com/en/logo.png',
header_image_url: 'https://www.example.com/en/fb/header.png',
qr_code: 'M1SMITH/NICOLAS CG4X7U nawouehgawgnapwi3jfa0wfh',
above_bar_code_image_url: 'https://www.example.com/en/PLAT.png',
flight_info: {
flight_number: 'KL0642',
departure_airport: {
airport_code: 'JFK',
city: 'New York',
terminal: 'T1',
gate: 'D57',
},
arrival_airport: {
airport_code: 'AMS',
city: 'Amsterdam',
},
flight_schedule: {
departure_time: '2016-01-02T19:05',
arrival_time: '2016-01-05T17:30',
},
},
},
{
passenger_name: 'JONES/FARBOUND',
pnr_number: 'CG4X7U',
travel_class: 'business',
seat: '74K',
auxiliary_fields: [
{
label: 'Terminal',
value: 'T1',
},
{
label: 'Departure',
value: '30OCT 19:05',
},
],
secondary_fields: [
{
label: 'Boarding',
value: '18:30',
},
{
label: 'Gate',
value: 'D57',
},
{
label: 'Seat',
value: '74K',
},
{
label: 'Sec.Nr.',
value: '004',
},
],
logo_image_url: 'https://www.example.com/en/logo.png',
header_image_url: 'https://www.example.com/en/fb/header.png',
qr_code: 'M1JONES/FARBOUND CG4X7U nawouehgawgnapwi3jfa0wfh',
above_bar_code_image_url: 'https://www.example.com/en/PLAT.png',
flight_info: {
flight_number: 'KL0642',
departure_airport: {
airport_code: 'JFK',
city: 'New York',
terminal: 'T1',
gate: 'D57',
},
arrival_airport: {
airport_code: 'AMS',
city: 'Amsterdam',
},
flight_schedule: {
departure_time: '2016-01-02T19:05',
arrival_time: '2016-01-05T17:30',
},
},
},
],
});
sendAirlineCheckinTemplate(userId, attributes) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
attributes
Type: Object
client.sendAirlineCheckinTemplate(USER_ID, {
intro_message: 'Check-in is available now.',
locale: 'en_US',
pnr_number: 'ABCDEF',
flight_info: [
{
flight_number: 'f001',
departure_airport: {
airport_code: 'SFO',
city: 'San Francisco',
terminal: 'T4',
gate: 'G8',
},
arrival_airport: {
airport_code: 'SEA',
city: 'Seattle',
terminal: 'T4',
gate: 'G8',
},
flight_schedule: {
boarding_time: '2016-01-05T15:05',
departure_time: '2016-01-05T15:45',
arrival_time: '2016-01-05T17:30',
},
},
],
checkin_url: 'https://www.airline.com/check-in',
});
sendAirlineItineraryTemplate(userId, attributes) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
attributes
Type: Object
client.sendAirlineItineraryTemplate(USER_ID, {
intro_message: "Here's your flight itinerary.",
locale: 'en_US',
pnr_number: 'ABCDEF',
passenger_info: [
{
name: 'Farbound Smith Jr',
ticket_number: '0741234567890',
passenger_id: 'p001',
},
{
name: 'Nick Jones',
ticket_number: '0741234567891',
passenger_id: 'p002',
},
],
flight_info: [
{
connection_id: 'c001',
segment_id: 's001',
flight_number: 'KL9123',
aircraft_type: 'Boeing 737',
departure_airport: {
airport_code: 'SFO',
city: 'San Francisco',
terminal: 'T4',
gate: 'G8',
},
arrival_airport: {
airport_code: 'SLC',
city: 'Salt Lake City',
terminal: 'T4',
gate: 'G8',
},
flight_schedule: {
departure_time: '2016-01-02T19:45',
arrival_time: '2016-01-02T21:20',
},
travel_class: 'business',
},
{
connection_id: 'c002',
segment_id: 's002',
flight_number: 'KL321',
aircraft_type: 'Boeing 747-200',
travel_class: 'business',
departure_airport: {
airport_code: 'SLC',
city: 'Salt Lake City',
terminal: 'T1',
gate: 'G33',
},
arrival_airport: {
airport_code: 'AMS',
city: 'Amsterdam',
terminal: 'T1',
gate: 'G33',
},
flight_schedule: {
departure_time: '2016-01-02T22:45',
arrival_time: '2016-01-03T17:20',
},
},
],
passenger_segment_info: [
{
segment_id: 's001',
passenger_id: 'p001',
seat: '12A',
seat_type: 'Business',
},
{
segment_id: 's001',
passenger_id: 'p002',
seat: '12B',
seat_type: 'Business',
},
{
segment_id: 's002',
passenger_id: 'p001',
seat: '73A',
seat_type: 'World Business',
product_info: [
{
title: 'Lounge',
value: 'Complimentary lounge access',
},
{
title: 'Baggage',
value: '1 extra bag 50lbs',
},
],
},
{
segment_id: 's002',
passenger_id: 'p002',
seat: '73B',
seat_type: 'World Business',
product_info: [
{
title: 'Lounge',
value: 'Complimentary lounge access',
},
{
title: 'Baggage',
value: '1 extra bag 50lbs',
},
],
},
],
price_info: [
{
title: 'Fuel surcharge',
amount: '1597',
currency: 'USD',
},
],
base_price: '12206',
tax: '200',
total_price: '14003',
currency: 'USD',
});
sendAirlineFlightUpdateTemplate(userId, attributes) - Official Docs
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
attributes
Type: Object
client.sendAirlineFlightUpdateTemplate(USER_ID, {
intro_message: 'Your flight is delayed',
update_type: 'delay',
locale: 'en_US',
pnr_number: 'CF23G2',
update_flight_info: {
flight_number: 'KL123',
departure_airport: {
airport_code: 'SFO',
city: 'San Francisco',
terminal: 'T4',
gate: 'G8',
},
arrival_airport: {
airport_code: 'AMS',
city: 'Amsterdam',
terminal: 'T4',
gate: 'G8',
},
flight_schedule: {
boarding_time: '2015-12-26T10:30',
departure_time: '2015-12-26T11:30',
arrival_time: '2015-12-27T07:30',
},
},
});
sendQuickReplies(userId, message, items)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
message
Type: Object
items
Type: Array<Object>
client.sendQuickReplies(USER_ID, { text: 'Pick a color:' }, [
{
content_type: 'text',
title: 'Red',
payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED',
},
]);
sendSenderAction(userId, action)
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
action
Type: String
Name of the action.
client.sendSenderAction(USER_ID, 'typing_on');
markSeen(userId)
Mark last message as read.
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
client.markSeen(USER_ID);
turnTypingIndicatorsOn(userId)
Turn typing indicators on.
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
client.turnTypingIndicatorsOn(USER_ID);
turnTypingIndicatorsOff(userId)
Turn typing indicators off.
userId
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
client.turnTypingIndicatorsOff(USER_ID);
uploadAttachment(type, url)
type
Type: String
url
Type: String
URL address of the attachment.
client.uploadAttachment('image', 'http://www.example.com/image.jpg');
uploadAudio(url)
url
Type: String
URL address of the audio.
client.uploadAudio('http://www.example.com/audio.mp3');
uploadImage(url)
url
Type: String
URL address of the image.
client.uploadImage('http://www.example.com/image.jpg');
uploadVideo(url)
url
Type: String
URL address of the video.
client.uploadVideo('http://www.example.com/video.mp4');
uploadFile(url)
url
Type: String
URL address of the file.
client.uploadFile('http://www.example.com/file.pdf');
getMessageTags
client.getMessageTags().then(tags => {
console.log(tags);
});
getUserProfile(userId)
userId
Type: String
Page-scoped user ID of the recipient.
client.getUserProfile(USER_ID).then(user => {
console.log(user);
});
getMessengerProfile(fields)
fields
Type: Array<String>
client.getMessengerProfile(['get_started', 'persistent_menu']).then(profile => {
console.log(profile);
});
setMessengerProfile(profile)
profile
Type: Object
client.setMessengerProfile({
get_started: {
payload: 'GET_STARTED',
},
persistent_menu: [
{
locale: 'default',
composer_input_disabled: true,
call_to_actions: [
{
type: 'postback',
title: 'Restart Conversation',
payload: 'RESTART',
},
],
},
],
});
deleteMessengerProfile(fields)
fields
Type: Array<String>
client.deleteMessengerProfile(['get_started', 'persistent_menu']);
![](https://scontent-tpe1-1.xx.fbcdn.net/v/t39.2365-6/16686128_804279846389859_443648268883197952_n.png?oh=adde03b0bc7dd524a58cf46016e0267d&oe=59FC90D6)
client.getPersistentMenu().then(menu => {
console.log(menu);
});
Type: Array<Object>
client.setPersistentMenu([
{
locale: 'default',
call_to_actions: [
{
title: 'Play Again',
type: 'postback',
payload: 'RESTART',
},
{
title: 'Language Setting',
type: 'nested',
call_to_actions: [
{
title: '中文',
type: 'postback',
payload: 'CHINESE',
},
{
title: 'English',
type: 'postback',
payload: 'ENGLISH',
},
],
},
{
title: 'Explore D',
type: 'nested',
call_to_actions: [
{
title: 'Explore',
type: 'web_url',
url: 'https://www.youtube.com/watch?v=v',
webview_height_ratio: 'tall',
},
{
title: 'W',
type: 'web_url',
url: 'https://www.facebook.com/w',
webview_height_ratio: 'tall',
},
{
title: 'Powered by YOCTOL',
type: 'web_url',
url: 'https://www.yoctol.com/',
webview_height_ratio: 'tall',
},
],
},
],
},
]);
client.deletePersistentMenu();
getGetStartedButton
client.getGetStartedButton().then(getStarted => {
console.log(getStarted);
});
setGetStartedButton(payload)
payload
Type: String
client.setGetStartedButton('GET_STARTED');
deleteGetStartedButton
client.deleteGetStartedButton();
getGreetingText
client.getGreetingText().then(greeting => {
console.log(greeting);
});
setGreetingText(greeting)
greeting
Type: Array<Object>
client.setGreetingText([
{
locale: 'default',
text: 'Hello!',
},
]);
deleteGreetingText
client.deleteGreetingText();
getDomainWhitelist
client.getDomainWhitelist().then(domains => {
console.log(domains);
});
setDomainWhitelist(domains)
domains
Type: Array<String>
client.setDomainWhitelist(['www.example.com']);
deleteDomainWhitelist
client.deleteDomainWhitelist();
getAccountLinkingURL
client.getAccountLinkingURL().then(accountLinking => {
console.log(accountLinking);
});
setAccountLinkingURL(url)
url
Type: String
client.setAccountLinkingURL(
'https://www.example.com/oauth?response_type=code&client_id=1234567890&scope=basic'
);
deleteAccountLinkingURL
client.deleteAccountLinkingURL();
getPaymentSettings
client.getPaymentSettings().then(settings => {
console.log(settings);
});
setPaymentPrivacyPolicyURL(url)
url
Type: String
client.setPaymentPrivacyPolicyURL('https://www.example.com');
setPaymentPublicKey(key)
key
Type: String
client.setPaymentPublicKey('YOUR_PUBLIC_KEY');
setPaymentTestUsers(users)
users
Type: Array<String>
client.setPaymentTestUsers(['12345678']);
deletePaymentSettings
client.deletePaymentSettings();
getTargetAudience
client.getTargetAudience().then(targetAudience => {
console.log(targetAudience);
});
setTargetAudience(type, whitelist, blacklist)
type
Type: String
whitelist
Type: Array<String>
blacklist
Type: Array<String>
client.setTargetAudience('custom', ['US', 'CA'], ['UK']);
deleteTargetAudience
client.deleteTargetAudience();
getChatExtensionHomeURL
client.getChatExtensionHomeURL().then(chatExtension => {
console.log(chatExtension);
});
setChatExtensionHomeURL(url, attributes)
url
Type: String
attributes
Type: Object
client.setChatExtensionHomeURL('http://petershats.com/send-a-hat', {
webview_height_ratio: 'tall',
in_test: true,
});
deleteChatExtensionHomeURL
client.deleteChatExtensionHomeURL();
![](https://scontent-tpe1-1.xx.fbcdn.net/v/t39.2365-6/16685647_261975084241469_2329165888516784128_n.png?oh=61941dc020355f5c8fe88035d33f1503&oe=59F612D6)
generateMessengerCode(options)
options
Type: Object
options.image_size
Type: Number
options.data
Type: Object
client
.generateMessengerCode({
data: {
ref: 'billboard-ad',
},
image_size: 1000,
})
.then(code => {
console.log(code);
});
Handover Protocol API
passThreadControl(userId, targetAppId, metadata) - Official Docs
userId
Type: String
Page-scoped user ID of the recipient.
targetAppId
Type: Number
metadata
Type: String
client.passThreadControl(USER_ID, APP_ID, 'free formed text for another app');
takeThreadControl(userId, metadata) - Official Docs
userId
Type: String
Page-scoped user ID of the recipient.
metadata
Type: String
client.passThreadControl(USER_ID, 'free formed text for another app');
client.getSecondaryReceivers().then(receivers => {
console.log(receivers);
});
getDailyUniqueActiveThreadCounts
client.getDailyUniqueActiveThreadCounts().then(counts => {
console.log(counts);
});
getDailyUniqueConversationCounts
client.getDailyUniqueConversationCounts().then(counts => {
console.log(counts);
});
setNLPConfigs(config)
config
Type: Object
config.nlp_enabled
Type: Boolean
config.custom_token
Type: String
client.setNLPConfigs({
nlp_enabled: true,
});
enableNLP
client.enableNLP();
disableNLP
client.disableNLP();