messaging-api-messenger
Messaging API client for Messenger
Installation
npm i --save messaging-api-messenger
or
yarn add messaging-api-messenger
Usage
Initialize
import { MessengerClient } from 'messaging-api-line';
const client = MessengerClient.connect(accessToken);
Call API
async function() {
await client.sendText(recipientId, text, options);
}
or
client.sendText(recipientId, text, options).then(() => {
});
API Reference
All methods return a Promise.
User
client.getUserProfile('1')
.then(user => {
console.log(user);
});
Send API
Official docs
Content types
client.sendRawBody({
recipient: {
id: '1',
},
message: {
text: 'Hello!',
},
});
client.send('1', {
text: 'Hello!',
});
sendText(userId, text [, options])
client.sendText('1', 'Hello!');
sendIssueResolutionText(userId, text)
client.sendIssueResolutionText('1', 'Hello!');
sendAttachment(userId, attachment)
client.sendAttachment('1', {
type: 'image',
payload: {
url: 'https://example.com/pic.png',
},
});
client.sendAudio('1', 'https://example.com/audio.mp3');
client.sendImage('1', 'https://example.com/pic.png');
client.sendVideo('1', 'https://example.com/video.mp4');
client.sendFile('1', 'https://example.com/word.docx');
sendTemplate(userId, template)
client.sendTemplate('1', {
template_type: 'button',
text: 'title',
buttons: [
{
type: 'postback',
title: 'Start Chatting',
payload: 'USER_DEFINED_PAYLOAD',
},
],
});
Official docs
sendButtonTemplate(userId, title, buttons)
client.sendButtonTemplate('1', 'my_title', [
{
type: 'postback',
title: 'Start Chatting',
payload: 'USER_DEFINED_PAYLOAD',
},
]
Official docs
sendGenericTemplate(userId, elements)
client.sendGenericTemplate('1', [
{
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',
},
],
},
]);
Official docs
sendShippingUpdateTemplate(userId, elements)
client.sendShippingUpdateTemplate('1', [
{
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)
client.sendReservationUpdateTemplate('1', [
{
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)
client.sendIssueResolutionTemplate('1', [
{
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, topElementStyle)
client.sendListTemplate('1', [
{
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'
);
Official docs
Official docs
sendAirlineBoardingPassTemplate
Official docs
sendAirlineCheckinTemplate
Official docs
sendAirlineItineraryTemplate
Official docs
sendAirlineFlightUpdateTemplate
Official docs
sendQuickReplies(userId, message, items)
client.sendQuickReplies('1', { text: 'Pick a color:' }, [
{
content_type: 'text',
title: 'Red',
payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED',
},
]
);
Official docs
client.sendSenderAction('1', 'typing_on');
Official docs
turnTypingIndicatorsOn(userId)
client.turnTypingIndicatorsOn('1');
turnTypingIndicatorsOff(userId)
client.turnTypingIndicatorsOff('1');
Upload API
Official docs
uploadAttachment
uploadAudio
uploadImage
uploadVideo
uploadFile
Messenger Platform
Messenger Profile
Official docs
getMessengerProfile
setMessengerProfile
deleteMessengerProfile
Get Started Button
Official docs
getGetStartedButton
setGetStartedButton
deleteGetStartedButton
Official docs
getPersistentMenu
setPersistentMenu
deletePersistentMenu
Greeting Text
Officail docs
getGreetingText
setGreetingText
deleteGreetingText
Domain Whitelist
Official docs
getDomainWhitelist
setDomainWhitelist
deleteDomainWhitelist
Account Linking URL
Official docs
getAccountLinkingURL
setAccountLinkingURL
deleteAccountLinkingURL
Payment Settings
Official docs
getPaymentSettings
setPaymentPrivacyPolicyURL
setPaymentPublicKey
setPaymentTestUsers
deletePaymentSettings
Target Audience
Official docs
getTargetAudience
setTargetAudience
deleteTargetAudience