![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
messaging-api-messenger
Advanced tools
Messaging API client for Messenger
npm i --save messaging-api-messenger
or
yarn add messaging-api-messenger
const { MessengerClient } = require('messaging-api-messenger');
// get accessToken from facebook developers website
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.
All methods return a Promise.
Send request raw body using the Send API.
Type: Object
client.sendRawBody({
recipient: {
id: USER_ID,
},
message: {
text: 'Hello!',
},
});
Send messages to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: Object
client.send(USER_ID, {
text: 'Hello!',
});
Send plain text messages to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String
Type: Object
Type: String
Value: ISSUE_RESOLUTION
client.sendText(USER_ID, 'Hello!');
Or sending text message with a tag:
client.sendText(USER_ID, 'Hello!', { tag: 'ISSUE_RESOLUTION' });
Send attachment messages to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: Object
client.sendAttachment(USER_ID, {
type: 'image',
payload: {
url: 'https://example.com/pic.png',
},
});
Send sounds to specified user by uploading them or sharing a URL using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String | Buffer | ReadStream | AttachmentPayload
Send audio using url string:
client.sendAudio(USER_ID, 'https://example.com/audio.mp3');
using AttachmentPayload
to send cached attachment:
client.sendAudio(USER_ID, { attachment_id: '55688' });
or using ReadStream
created from local file:
const fs = require('fs');
client.sendAudio(USER_ID, fs.createReadStream('audio.mp3'));
Send images to specified user by uploading them or sharing a URL using the Send API. Supported formats are jpg, png and gif.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String | Buffer | ReadStream | AttachmentPayload
Send image using url string:
client.sendImage(USER_ID, 'https://example.com/vr.jpg');
using AttachmentPayload
to send cached attachment:
client.sendImage(USER_ID, { attachment_id: '55688' });
or using ReadStream
created from local file:
const fs = require('fs');
client.sendImage(USER_ID, fs.createReadStream('vr.jpg'));
Send videos to specified user by uploading them or sharing a URL using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String | Buffer | ReadStream | AttachmentPayload
Send video using url string:
client.sendVideo(USER_ID, 'https://example.com/video.mp4');
using AttachmentPayload
to send cached attachment:
client.sendVideo(USER_ID, { attachment_id: '55688' });
or using ReadStream
created from local file:
const fs = require('fs');
client.sendVideo(USER_ID, fs.createReadStream('video.mp4'));
Send files to specified user by uploading them or sharing a URL using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String | Buffer | ReadStream | AttachmentPayload
Send file using url string:
client.sendFile(USER_ID, 'https://example.com/receipt.pdf');
using AttachmentPayload
to send cached attachment:
client.sendFile(USER_ID, { attachment_id: '55688' });
or using ReadStream
created from local file:
const fs = require('fs');
client.sendFile(USER_ID, fs.createReadStream('receipt.pdf'));
Send structured message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: Object
client.sendTemplate(USER_ID, {
template_type: 'button',
text: 'title',
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'USER_DEFINED_PAYLOAD',
},
],
});
Send button message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String
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',
},
]);
Send generic message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: Array<Object>
Type: String
Value: horizontal | square
Default: horizontal
Type: Object
Type: String
Value: SHIPPING_UPDATE | RESERVATION_UPDATE | ISSUE_RESOLUTION APPOINTMENT_UPDATE | GAME_EVENT | TRANSPORTATION_UPDATE | FEATURE_FUNCTIONALITY_UPDATE | TICKET_UPDATE
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',
},
],
},
],
{ image_aspect_ratio: 'square' }
);
Adding a tag to a message allows you to send it outside the 24+1 window, for a limited number of use cases, per Messenger Platform policy.
client.sendGenericTemplate(
USER_ID,
[
{
// ...
},
],
{ tag: 'ISSUE_RESOLUTION' }
);
Send list message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: Array<Object>
Type: Array<Object>
Type: Object
Type: String
Value: large | compact
Default: large
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',
},
],
{ top_element_style: 'compact' }
);
Send open graph message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
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',
},
],
},
]);
Send receipt message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
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,
},
],
});
Send airline boarding pass message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
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',
},
},
},
],
});
Send airline checkin message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
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',
});
Send airline itinerary message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
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',
});
Send airline flight update message templates to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
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',
},
},
});
Send messages with quick replies to specified user using the Send API.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: Object
Type: Array<Object>
client.sendQuickReplies(USER_ID, { text: 'Pick a color:' }, [
{
content_type: 'text',
title: 'Red',
payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED',
},
]);
Send sender actions to specified user using the Send API, to let users know you are processing their request.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
Type: String
Name of the action.
client.sendSenderAction(USER_ID, 'typing_on');
Mark last message as read for specified user.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
client.markSeen(USER_ID);
Turn typing indicators on for specified user.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
client.typingOn(USER_ID);
Turn typing indicators off for specified user.
Type: String | Object
Page-scoped user ID of the recipient or recipient object.
client.typingOff(USER_ID);
Upload specified type attachment using URL address.
Type: String
Value: image | video | audio | file
Type: String
URL address of the attachment.
client.uploadAttachment('image', 'http://www.example.com/image.jpg');
Upload audio attachment using URL address.
Type: String
URL address of the audio.
client.uploadAudio('http://www.example.com/audio.mp3');
Upload image attachment using URL address.
Type: String
URL address of the image.
client.uploadImage('http://www.example.com/image.jpg');
Upload video attachment using URL address.
Type: String
URL address of the video.
client.uploadVideo('http://www.example.com/video.mp4');
Upload file attachment using URL address.
Type: String
URL address of the file.
client.uploadFile('http://www.example.com/file.pdf');
Getting tags list via an API.
client.getMessageTags().then(tags => {
console.log(tags);
// [
// {
// tag: 'SHIPPING_UPDATE',
// description:
// 'The shipping_update tag may only be used to provide a shipping status notification for a product that has already been purchased. For example, when the product is shipped, in-transit, delivered, or delayed. This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// {
// tag: 'RESERVATION_UPDATE',
// description:
// 'The reservation_update tag may only be used to confirm updates to an existing reservation. For example, when there is a change in itinerary, location, or a cancellation (such as when a hotel booking is canceled, a car rental pick-up time changes, or a room upgrade is confirmed). This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// {
// tag: 'ISSUE_RESOLUTION',
// description:
// 'The issue_resolution tag may only be used to respond to a customer service issue surfaced in a Messenger conversation after a transaction has taken place. This tag is intended for use cases where the business requires more than 24 hours to resolve an issue and needs to give someone a status update and/or gather additional information. This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements, nor can businesses use the tag to proactively message people to solicit feedback).',
// },
// {
// tag: 'APPOINTMENT_UPDATE',
// description:
// 'The appointment_update tag may only be used to provide updates about an existing appointment. For example, when there is a change in time, a location update or a cancellation (such as when a spa treatment is canceled, a real estate agent needs to meet you at a new location or a dental office proposes a new appointment time). This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// {
// tag: 'GAME_EVENT',
// description:
// 'The game_event tag may only be used to provide an update on user progression, a global event in a game or a live sporting event. For example, when a person’s crops are ready to be collected, their building is finished, their daily tournament is about to start or their favorite soccer team is about to play. This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// {
// tag: 'TRANSPORTATION_UPDATE',
// description:
// 'The transportation_update tag may only be used to confirm updates to an existing reservation. For example, when there is a change in status of any flight, train or ferry reservation (such as “ride canceled”, “trip started” or “ferry arrived”). This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// {
// tag: 'FEATURE_FUNCTIONALITY_UPDATE',
// description:
// 'The feature_functionality_update tag may only be used to provide an update on new features or functionality that become available in a bot. For example, announcing the ability to talk to a live agent in a bot, or that the bot has a new skill. This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// {
// tag: 'TICKET_UPDATE',
// description:
// 'The ticket_update tag may only be used to provide updates pertaining to an event for which a person already has a ticket. For example, when there is a change in time, a location update or a cancellation (such as when a concert is canceled, the venue has changed or a refund opportunity is available). This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements).',
// },
// ]
});
Retrieving a Person's Profile.
Type: String
Page-scoped user ID of the recipient.
client.getUserProfile(USER_ID).then(user => {
console.log(user);
// {
// first_name: 'Johnathan',
// last_name: 'Jackson',
// profile_pic: 'https://example.com/pic.png',
// locale: 'en_US',
// timezone: 8,
// gender: 'male',
// }
});
Retrieves the current value of one or more Messenger Profile properties by name.
Type: Array<String>
Value: account_linking_url | persistent_menu | get_started | greeting | whitelisted_domains | payment_settings | target_audience | home_url
client.getMessengerProfile(['get_started', 'persistent_menu']).then(profile => {
console.log(profile);
// [
// {
// get_started: {
// payload: 'GET_STARTED',
// },
// },
// {
// persistent_menu: [
// {
// locale: 'default',
// composer_input_disabled: true,
// call_to_actions: [
// {
// type: 'postback',
// title: 'Restart Conversation',
// payload: 'RESTART',
// },
// ],
// },
// ],
// },
// ]
});
Sets the values of one or more Messenger Profile properties. Only properties set in the request body will be overwritten.
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',
},
],
},
],
});
Deletes one or more Messenger Profile properties. Only properties specified in the fields array will be deleted.
Type: Array<String>
Value: account_linking_url | persistent_menu | get_started | greeting | whitelisted_domains | payment_settings | target_audience | home_url
client.deleteMessengerProfile(['get_started', 'persistent_menu']);
Retrieves the current value of persistent menu.
client.getPersistentMenu().then(menu => {
console.log(menu);
// [
// {
// locale: 'default',
// composer_input_disabled: true,
// call_to_actions: [
// {
// type: 'postback',
// title: 'Restart Conversation',
// payload: 'RESTART',
// },
// {
// type: 'web_url',
// title: 'Powered by ALOHA.AI, Yoctol',
// url: 'https://www.yoctol.com/',
// },
// ],
// },
// ]
});
Sets the values of persistent 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',
},
],
},
],
},
]);
Note: You must set a get started button to use the persistent menu.
Deletes persistent menu.
client.deletePersistentMenu();
Retrieves the current value of get started button.
client.getGetStartedButton().then(getStarted => {
console.log(getStarted);
// {
// payload: 'GET_STARTED',
// }
});
Sets the values of get started button.
Type: String
client.setGetStartedButton('GET_STARTED');
Deletes get started button.
client.deleteGetStartedButton();
Retrieves the current value of greeting text.
client.getGreetingText().then(greeting => {
console.log(greeting);
// [
// {
// locale: 'default',
// text: 'Hello!',
// },
// ]
});
Sets the values of greeting text.
Type: Array<Object>
client.setGreetingText([
{
locale: 'default',
text: 'Hello!',
},
]);
Deletes greeting text.
client.deleteGreetingText();
Retrieves the current value of domain whitelist.
client.getDomainWhitelist().then(domains => {
console.log(domains);
// ['http://www.example.com/']
});
Sets the values of domain whitelist.
Type: Array<String>
client.setDomainWhitelist(['www.example.com']);
Deletes domain whitelist.
client.deleteDomainWhitelist();
Retrieves the current value of account linking URL.
client.getAccountLinkingURL().then(accountLinking => {
console.log(accountLinking);
// {
// account_linking_url:
// 'https://www.example.com/oauth?response_type=code&client_id=1234567890&scope=basic',
// }
});
Sets the values of account linking URL.
Type: String
client.setAccountLinkingURL(
'https://www.example.com/oauth?response_type=code&client_id=1234567890&scope=basic'
);
Deletes account linking URL.
client.deleteAccountLinkingURL();
Retrieves the current value of payment settings.
client.getPaymentSettings().then(settings => {
console.log(settings);
// {
// privacy_url: 'www.facebook.com',
// public_key: 'YOUR_PUBLIC_KEY',
// test_users: ['12345678'],
// }
});
Sets the values of payment privacy policy URL.
Type: String
client.setPaymentPrivacyPolicyURL('https://www.example.com');
Sets the values of payment public key.
Type: String
client.setPaymentPublicKey('YOUR_PUBLIC_KEY');
Sets the values of payment test users.
Type: Array<String>
client.setPaymentTestUsers(['12345678']);
Deletes payment settings.
client.deletePaymentSettings();
Retrieves the current value of target audience.
client.getTargetAudience().then(targetAudience => {
console.log(targetAudience);
// {
// audience_type: 'custom',
// countries: {
// whitelist: ['US', 'CA'],
// },
// }
});
Sets the values of target audience.
Type: String
Type: Array<String>
Type: Array<String>
client.setTargetAudience('custom', ['US', 'CA'], ['UK']);
Deletes target audience.
client.deleteTargetAudience();
Retrieves the current value of chat extension home URL.
client.getChatExtensionHomeURL().then(chatExtension => {
console.log(chatExtension);
// {
// url: 'http://petershats.com/send-a-hat',
// webview_height_ratio: 'tall',
// in_test: true,
// }
});
Sets the values of chat extension home URL.
Type: String
Type: Object
client.setChatExtensionHomeURL('http://petershats.com/send-a-hat', {
webview_height_ratio: 'tall',
in_test: true,
});
Deletes chat extension home URL.
client.deleteChatExtensionHomeURL();
Generating a Messenger code.
Type: Object
Type: Number
Type: Object
client
.generateMessengerCode({
data: {
ref: 'billboard-ad',
},
image_size: 1000,
})
.then(code => {
console.log(code);
// {
// "uri": "YOUR_CODE_URL_HERE"
// }
});
Passes thread control from your app to another app.
Type: String
Page-scoped user ID of the recipient.
Type: Number
Type: String
client.passThreadControl(USER_ID, APP_ID, 'free formed text for another app');
Takes control of a specific thread from a Secondary Receiver app.
Type: String
Page-scoped user ID of the recipient.
Type: String
client.passThreadControl(USER_ID, 'free formed text for another app');
Retrieves the list of apps that are Secondary Receivers for a page.
client.getSecondaryReceivers().then(receivers => {
console.log(receivers);
// [
// {
// "id": "12345678910",
// "name": "David's Composer"
// },
// {
// "id": "23456789101",
// "name": "Messenger Rocks"
// }
// ]
});
Retrieves a count of the unique active threads your app participated in per day.
client.getDailyUniqueActiveThreadCounts().then(counts => {
console.log(counts);
// [
// {
// "name": "page_messages_active_threads_unique",
// "period": "day",
// "values": [
// {
// "value": 83111,
// "end_time": "2017-02-02T08:00:00+0000"
// },
// {
// "value": 85215,
// "end_time": "2017-02-03T08:00:00+0000"
// },
// {
// "value": 87175,
// "end_time": "2017-02-04T08:00:00+0000"
// }
// ],
// "title": "Daily unique active threads count by thread fbid",
// "description": "Daily: total unique active threads created between users and page.",
// "id": "1234567/insights/page_messages_active_threads_unique/day"
// }
// ]
});
Retrieves a count of actions that were initiated by people your app was in an active thread with per day.
client.getDailyUniqueConversationCounts().then(counts => {
console.log(counts);
// [
// {
// "name": "page_messages_feedback_by_action_unique",
// "period": "day",
// "values": [
// {
// "value": {
// "TURN_ON": 40,
// "TURN_OFF": 167,
// "DELETE": 720,
// "OTHER": 0,
// "REPORT_SPAM": 0
// },
// "end_time": "2017-02-02T08:00:00+0000"
// },
// {
// "value": {
// "TURN_ON": 38,
// "DELETE": 654,
// "TURN_OFF": 155,
// "REPORT_SPAM": 1,
// "OTHER": 0
// },
// "end_time": "2017-02-03T08:00:00+0000"
// }
// ],
// "title": "Daily unique conversation count broken down by user feedback actions",
// "description": "Daily: total unique active threads created between users and page.",
// "id": "1234567/insights/page_messages_active_threads_unique/day"
// }
// ],
});
Set values of NLP configs.
Type: Object
Type: Boolean
Type: String
client.setNLPConfigs({
nlp_enabled: true,
});
Enabling Built-in NLP.
client.enableNLP();
Disabling Built-in NLP.
client.disableNLP();
0.3.1 / 2017-08-31
AttachmentPayload
to send cached attachment:client.sendImage(USER_ID, { attachment_id: '55688' });
client.sendAudio(USER_ID, { attachment_id: '55688' });
client.sendVideo(USER_ID, { attachment_id: '55688' });
client.sendFile(USER_ID, { attachment_id: '55688' });
FAQs
Messaging API client for Messenger
The npm package messaging-api-messenger receives a total of 2,446 weekly downloads. As such, messaging-api-messenger popularity was classified as popular.
We found that messaging-api-messenger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.