This is a NodeJS module with Functions for accessing FB API (Send API mostly)
- Install the module with
npm
- Require the module and construct the library
const { FB } = require('messenger-platform-node');
const fb = new FB(FB_PAGE_TOKEN, FB_APP_SECRET, logger);
This method sends a message specified by the options
object to the user with the PSID id
. Returns a promise that throws an error if the sending of the message fails.
This method executes a fbMessage(id, options);
after a given delay specified by the DELAY
constant. Returns a promise.
This method is used to send multiple messages to a single user. Each message is separated from the one before it with a constant delay (DELAY
). The messages sent are specified inside the array [options]
that contains multiple options
objects. It is implemented using a fbMessage(id, options)
for each separate message. Returns a promise.
{
text, // String
quickreplies, // Array
attachment, // Object
templateId, // String
tag // String
}
This method uses the comment_id Graph API edge to send a one-time private response to the commenter. The message
variable can only be a string. Returns a promise.
Shows the user with the PSID id
that the bot is "typing". Returns a promise.
Stops the typing indicator to the user with the PSID id
. Returns a promise.
Marks the last message on the thread with the user with the PSID id
as "seen". Returns a promise.
Gets the user data provided by the Messenger Platform API for the user with the PSID id
. Returns a promise that returns the following object:
{
first_name,
last_name,
profile_pic,
locale,
timezone,
gender
}
This method should be edited to inlude the LAST_AD_REFERRAL field
Handovers the user with the PSID id
to the Page Inbox app. Returns a promise.
Takes thread control of the user with the PSID id
. Returns a promise.
urlBtn (title, url, webview_height_ratio = "full");
callBtn (title, number);
shareBtn (generic = null);
postbackBtn (title, payload);
image (url);
buttonMessage (text, [buttons]);
cardMessage ([elements]);
cardElement ({title = null, subtitle = null, image_url = null, buttons = []});
listMessage ({[elements], buttons, large = false});
listElement ({title, subtitle, image_url, action = null, buttons = []});
webhook (messenger, FB_PAGE_ID);
messengerWebhook ({attachmentHandler, textHandler, menuHandler, getContext, isCustomerService});