
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
messenger-client
Advanced tools
Javascript library for sending a message through Facebook Messenger send API.
This package depends on axios library, so you need to install it too.
$ npm install axios messenger-client
Here's a basic usage on sending a text reply to the user identifed by and id of 123.
import MessengerClient from 'messenger-client';
const client = new MessengerClient({ pageAccessToken: 'YOUR_PAGE_ACCESS_TOKEN' });
client.sendText({ recipientId: 123, text: 'Hello World 🌎' })
.then(data => console.log(data))
.catch(e => console.error(e.message));
const client = new MessengerClient({ pageAccessToken, [apiVersion] });
pageAccessToken (String): The access token for the page where the Messenger bot will be used. To get your page access token, heads up to Facebook apps page and select the app that you use for your Messenger bot. Within your app page, select the Messenger >> Settings menu on the left. On this Messenger settings console, you'll find Token Generation section to generate the access token.apiVersion (String): The Facebook Messenger API version to use. Optional parameter, default to 2.11.As of the release of Messenger Platform v2.2, the Send API requires you to provide the messaging_type property. You can check all possible values for messaging_type in the documentation. You can pass the messagingType property to all send methods and if you not set it, it will be default to RESPONSE.
This package also provides static properties that you can use to represent the messaging type value:
MessengerClient.MESSAGING_TYPE_RESPONSE; // RESPONSE
MessengerClient.MESSAGING_TYPE_UPDATE; // UPDATE
MessengerClient.MESSAGING_TYPE_MESSAGE_TAG; // MESSAGE_TAG
MessengerClient.MESSAGING_TYPE_NON_PROMOTIONAL_SUBSCRIPTION; // NON_PROMOTIONAL_SUBSCRIPTION
This is the most basic API to allow you interact directly with Facebook Messenger send API.
client.send(data);
data (Object): An object of payload that you need to provide to Facebook Messenger Send API.Check out the Send API documentation to see all possible payload properties.
Sending a text message using a basic send method:
client.send({
messaging_type: Messenger.MESSAGING_TYPE_RESPONSE,
recipient: {
id: 123
},
message: {
text: 'May the force be with you ✨'
}
});
client.sendText({ recipientId, text, [messagingType] });
recipientId (Integer): The recipient ID.text (String): The text that you want to send to the user.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.client.sendText({
recipientId: 123,
text: 'Do or do not. There is no try.'
});
client.sendImage({ recipientId, url, [messagingType] });
client.sendAudio({ recipientId, url, [messagingType] });
client.sendVideo({ recipientId, url, [messagingType] });
client.sendFile({ recipientId, url, [messagingType] });
recipientId (Integer): The recipient ID.url (String): The URL of the file that you want to send.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.client.sendImage({
recipientId: 123,
url: 'https://media.giphy.com/media/ArrVyXcjSzzxe/giphy-downsized.gif'
});
client.sendReadReceipt({ recipientId, [messagingType] });
client.sendTypingOn({ recipientId, [messagingType] });
client.sendTypingOff({ recipientId, [messagingType] });
recipientId (Integer): The recipient ID.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.client.sendTypingOn({ recipientId: 123 })
.then(data => {
setTimeout(() => {
client.sendTypingOff({ recipientId: 123 })
}, 5000);
});
client.sendQuickReplies({ recipientId, text, replies, [messagingType] });
recipientId (Integer): The recipient ID.text (String): The main text to send along with the quick replies.replies (Array): An array of quick reply options.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the quick replies documentation to see all possible properties for replies parameter.
client.sendQuickReplies({
recipientId: 123,
text: 'Choose your favorite spacecraft:',
replies: [
{
content_type: 'text',
title: 'Millennium Falcon',
payload: 'MILLENNIUM_FALCON_IS_SELECTED'
},
{
content_type: 'text',
title: 'Star Destroyer',
payload: 'STAR_DESTROYER_IS_SELECTED'
}
]
});
client.sendButtons({ recipientId, text, buttons, [messagingType] });
recipientId (Integer): The recipient ID.text (String): The main text to send along with the buttons.buttons (Array): An array that consist of 1-3 button objects.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the buttons documentaion to see all possible button types and how to construct them.
client.sendButtons({
recipientId: 123,
text: 'Check out for more detail',
buttons: [
{
type: 'web_url',
url: 'http://www.starwars.com',
title: 'Star Wars Homepage'
},
{
type: 'web_url',
url: 'https://en.wikipedia.org/wiki/Star_Wars',
title: 'Star Wars Wikipedia'
}
]
});
client.sendGeneric({ recipientId, elements, [messagingType] });
recipientId (Integer): The recipient ID.elements (Array): An array of structured template elements that you want to send, maximum up to 10 items.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the generic template documentaion to see all possible element properties that you can provide.
client.sendGeneric({
recipientId: 123,
elements: [{
title: 'Do or do not. There is no try.',
image_url: 'https://media.giphy.com/media/ArrVyXcjSzzxe/giphy-downsized.gif',
buttons: [
{
type: 'postback',
title: 'Do',
payload: 'DO_IS_CLICKED',
},
{
type: 'postback',
title: 'Try',
payload: 'TRY_IS_CLICKED',
}
]
}]
});
client.sendList({ recipientId, elements, [topElementStyle, button, messagingType] });
recipientId (Integer): The recipient ID.elements (Array): Array of objects that describe items in the list. Minimum of 2 elements must be provided, and up to 4 elements is supported.topElementStyle (String): Optional parameter to set the format of the first item, it can be: compact or large.button (Object): Optional button object to display at the bottom of the list.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the list template documentaion to see all possible element properties that you can provide.
client.sendList({
recipientId: 123,
topElementStyle: 'compact',
elements: [
{
title: 'Millennium Falcon',
subtitle: 'The modified YT-1300F Corellian Light Freighter',
image_url: 'https://media.giphy.com/media/4MFxMNhSioR3i/giphy-tumblr.gif',
default_action: {
type: 'web_url',
url: 'https://en.wikipedia.org/wiki/Millennium_Falcon'
}
},
{
title: 'Star Destroyer',
subtitle: 'The vessel of the Imperial fleet',
image_url: 'https://media.giphy.com/media/unK3ncdrEao2k/giphy-downsized.gif',
default_action: {
type: 'web_url',
url: 'https://en.wikipedia.org/wiki/Star_Destroyer'
}
}
]
});
client.sendMedia({ recipientId, type, url, attachmentId, button, [messagingType] });
recipientId (Integer): The recipient ID.type (String): The type of the media, it can be image or video.url (String): The Facebook URL of the media, leave it empty if you want to set the attachmentId instead. Note that it must be a Facebook URL, check the documentation for more info.attachmentId (String): The attachment ID, it will be ignored if you set the url parameter.button (Object): An object of button.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the media template documentaion for more information.
client.sendMedia({
recipientId: 123,
type: 'video',
url: 'https://business.facebook.com/StarWars.Nordics/videos/1921975247818517',
button: {
type: 'web_url',
url: 'https://en.wikipedia.org/wiki/Star_Wars:_The_Last_Jedi',
title: 'Read More'
}
});
client.sendOpenGraph({ recipientId, url, buttons, [messagingType] });
recipientId (Integer): The recipient ID.url (String): The Open Graph URL that you want to send. Currently, only sharing songs is supported.buttons (Array): An array of button objects to append to.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the Open Graph template documentaion for more information.
client.sendOpenGraph({
recipientId: 123,
url: 'https://open.spotify.com/track/7a3iXf8eqbwciDHZUbfQSQ',
buttons: [
{
type: 'web_url',
url: 'https://en.wikipedia.org/wiki/The_Imperial_March',
title: 'Read More'
}
]
});
client.sendReceipt({
recipientId, recipientName, orderNumber, paymentMethod, summary,
[currency, sharable, merchantName, timestamp, elements, address, adjustments, messagingType]
});
recipientId (Integer): The recipient ID.recipientName (String): The recipient's name.orderNumber (String): The order number, it must be unique.paymentMethod (String): The payment method used. It's recomended to provide enough information for the customer on which payment method and account they used. It can be a custom string like Visa 1234.summary (Object): The payment summary object, the only required property is the total_cost. Check the summary section for further information.currency (String): The currency of the payment, default to USD.sharable (Boolean): Enable or disable native share button, default to false.merchantName (String): The merchant's name.timestamp (String): Timestamp of the order in seconds.elements (Array): Array of object that describe items within the order. Check the element section for more information.address (Object): The shipping address of the order. Check the address section for more information.adjustments (Array): An array of object that describe the payment adjustments, such as discount. Check the adjustments section for more information.messagingType (String): The messaging type. Optional parameter, default to RESPONSE.Check the receipt template documentaion for more information.
client.sendReceipt({
recipientId: 123,
recipientName: 'Darth Vader',
orderNumber: '123456',
paymentMethod: 'Visa 1234',
summary: {
total_cost: 12500
},
elements: [
{
title: 'Death Star',
image_url: 'https://upload.wikimedia.org/wikipedia/en/f/f9/Death_star1.png',
quantity: 1,
price: 10000
},
{
title: 'TIE Fighter',
image_url: 'https://free3d.com/imgd/l15332-tie-fighter-94029.jpg',
quantity: 5,
price: 500
}
]
});
MIT © Risan Bagja Pradana
This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Facebook or any of its affiliates or subsidiaries. This is an independent and unofficial API.
FAQs
A library for sending a message through Facebook Messenger send API
The npm package messenger-client receives a total of 3 weekly downloads. As such, messenger-client popularity was classified as not popular.
We found that messenger-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.