New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

messaging-api-messenger

Package Overview
Dependencies
Maintainers
2
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messaging-api-messenger - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

yarn.lock

83

lib/MessengerClient.js
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _querystring = require('querystring');var _querystring2 = _interopRequireDefault(_querystring);
var _axios = require('axios');var _axios2 = _interopRequireDefault(_axios);
var _formData = require('form-data');var _formData2 = _interopRequireDefault(_formData);
var _invariant = require('invariant');var _invariant2 = _interopRequireDefault(_invariant);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}

@@ -43,2 +44,5 @@

class MessengerClient {

@@ -355,2 +359,29 @@

/**

@@ -381,3 +412,2 @@ * Content Types

// TODO: support formdata fileupload?

@@ -394,3 +424,2 @@

// TODO: support formdata fileupload?

@@ -407,3 +436,2 @@

// TODO: support formdata fileupload?

@@ -420,3 +448,2 @@

// TODO: support formdata fileupload?

@@ -433,7 +460,38 @@

/**
* Templates
*
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/templates
*/
* Templates
*
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/templates
*/

@@ -697,2 +755,5 @@

/**

@@ -813,7 +874,7 @@ * Upload API

if (menuItems.some(item => item.locale === 'default')) {return this.setMessengerProfile({ persistent_menu: menuItems });} // menuItems is in type Array<MenuItem>
return this.setMessengerProfile({ persistent_menu: [{ locale: 'default', composer_input_disabled: composerInputDisabled, call_to_actions: menuItems }] });};this.deletePersistentMenu = () => this.deleteMessengerProfile(['persistent_menu']);this.getGreetingText = () => this.getMessengerProfile(['greeting']).then(res => res[0].greeting);this.setGreetingText = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.deleteGreetingText = () => this.deleteMessengerProfile(['greeting']);this.getDomainWhitelist = () => this.getMessengerProfile(['whitelisted_domains']).then(res => res[0].whitelisted_domains);this.setDomainWhitelist = domains => this.setMessengerProfile({ whitelisted_domains: domains });this.deleteDomainWhitelist = () => this.deleteMessengerProfile(['whitelisted_domains']);this.getAccountLinkingURL = () => this.getMessengerProfile(['account_linking_url']).then(res => res[0]);this.setAccountLinkingURL = url => this.setMessengerProfile({ account_linking_url: url });this.deleteAccountLinkingURL = () => this.deleteMessengerProfile(['account_linking_url']);this.getPaymentSettings = () => this.getMessengerProfile(['payment_settings']).then(res => res[0]);this.setPaymentPrivacyPolicyURL = url => this.setMessengerProfile({ payment_settings: { privacy_url: url } });this.setPaymentPublicKey = key => this.setMessengerProfile({ payment_settings: { public_key: key } });this.setPaymentTestUsers = users => this.setMessengerProfile({ payment_settings: { test_users: users } });this.deletePaymentSettings = () => this.deleteMessengerProfile(['payment_settings']);this.getTargetAudience = () => this.getMessengerProfile(['target_audience']).then(res => res[0]);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getChatExtensionHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0]);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, in_test, webview_share_button } });this.deleteChatExtensionHomeURL = () => this.deleteMessengerProfile(['home_url']);this.getMessageTags = () => this._http.get(`/page_message_tags?access_token=${this._accessToken}`).then(res => res.data.data);this.sendRawBody = body => this._http.post(`/me/messages?access_token=${this._accessToken}`, body).then(res => res.data);this.send = (recipientId, message, options) => this.sendRawBody(_extends({ recipient: { id: recipientId }, message }, options));this.sendAttachment = (recipientId, attachment, options) => this.send(recipientId, { attachment }, options);this.sendText = (recipientId, text, options) => this.send(recipientId, { text }, options);this.sendIssueResolutionText = (recipientId, text) => this.sendText(recipientId, text, { tag: 'ISSUE_RESOLUTION' });this.sendAudio = (recipientId, url) => this.sendAttachment(recipientId, { type: 'audio', payload: { url } });this.sendImage = (recipientId, url) => this.sendAttachment(recipientId, { type: 'image', payload: { url } });this.sendVideo = (recipientId, url) => this.sendAttachment(recipientId, { type: 'video', payload: { url } });this.sendFile = (recipientId, url) => this.sendAttachment(recipientId, { type: 'file', payload: { url } });this.sendTemplate = (recipientId, payload, options) => this.sendAttachment(recipientId, { type: 'template', payload }, options);this.sendButtonTemplate = (recipientId, text, buttons) => this.sendTemplate(recipientId, { template_type: 'button', text, buttons });this.sendGenericTemplate = (recipientId, elements, ratio = 'horizontal', options) => this.sendTemplate(recipientId, { template_type: 'generic', elements, image_aspect_ratio: ratio // FIXME rename to image_aspect_ratio?
}, options);this.sendTaggedTemplate = (recipientId, elements, tag, ratio = 'horizontal') => this.sendGenericTemplate(recipientId, elements, ratio, { tag });this.sendShippingUpdateTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'SHIPPING_UPDATE', ratio);this.sendReservationUpdateTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'RESERVATION_UPDATE', ratio);this.sendIssueResolutionTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'ISSUE_RESOLUTION', ratio);this.sendAppointmentUpdateTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'APPOINTMENT_UPDATE', ratio);this.sendGameEventTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'GAME_EVENT', ratio);this.sendTransportationUpdateTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'TRANSPORTATION_UPDATE', ratio);this.sendFeatureFunctionalityUpdateTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'FEATURE_FUNCTIONALITY_UPDATE', ratio);this.sendTicketUpdateTemplate = (recipientId, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipientId, elements, 'TICKET_UPDATE', ratio);this.sendListTemplate = (recipientId, elements, buttons, topElementStyle = 'large') => this.sendTemplate(recipientId, { template_type: 'list', elements, buttons, top_element_style: topElementStyle });this.sendOpenGraphTemplate = (recipientId, elements) => this.sendTemplate(recipientId, { template_type: 'open_graph', elements });this.sendReceiptTemplate = (recipientId, attrs) => this.sendTemplate(recipientId, _extends({ template_type: 'receipt' }, attrs));this.sendAirlineBoardingPassTemplate = (recipientId, attrs) => this.sendTemplate(recipientId, _extends({ template_type: 'airline_boardingpass' }, attrs));this.sendAirlineCheckinTemplate = (recipientId, attrs) => this.sendTemplate(recipientId, _extends({ template_type: 'airline_checkin' }, attrs));this.sendAirlineItineraryTemplate = (recipientId, attrs) => this.sendTemplate(recipientId, _extends({ template_type: 'airline_itinerary' }, attrs));this.sendAirlineFlightUpdateTemplate = (recipientId, attrs) => this.sendTemplate(recipientId, _extends({ template_type: 'airline_update' }, attrs));this.sendQuickReplies = (recipientId, textOrAttachment, quickReplies) => {// quick_replies is limited to 11
return this.setMessengerProfile({ persistent_menu: [{ locale: 'default', composer_input_disabled: composerInputDisabled, call_to_actions: menuItems }] });};this.deletePersistentMenu = () => this.deleteMessengerProfile(['persistent_menu']);this.getGreetingText = () => this.getMessengerProfile(['greeting']).then(res => res[0].greeting);this.setGreetingText = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.deleteGreetingText = () => this.deleteMessengerProfile(['greeting']);this.getDomainWhitelist = () => this.getMessengerProfile(['whitelisted_domains']).then(res => res[0].whitelisted_domains);this.setDomainWhitelist = domains => this.setMessengerProfile({ whitelisted_domains: domains });this.deleteDomainWhitelist = () => this.deleteMessengerProfile(['whitelisted_domains']);this.getAccountLinkingURL = () => this.getMessengerProfile(['account_linking_url']).then(res => res[0]);this.setAccountLinkingURL = url => this.setMessengerProfile({ account_linking_url: url });this.deleteAccountLinkingURL = () => this.deleteMessengerProfile(['account_linking_url']);this.getPaymentSettings = () => this.getMessengerProfile(['payment_settings']).then(res => res[0]);this.setPaymentPrivacyPolicyURL = url => this.setMessengerProfile({ payment_settings: { privacy_url: url } });this.setPaymentPublicKey = key => this.setMessengerProfile({ payment_settings: { public_key: key } });this.setPaymentTestUsers = users => this.setMessengerProfile({ payment_settings: { test_users: users } });this.deletePaymentSettings = () => this.deleteMessengerProfile(['payment_settings']);this.getTargetAudience = () => this.getMessengerProfile(['target_audience']).then(res => res[0]);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getChatExtensionHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0]);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, in_test, webview_share_button } });this.deleteChatExtensionHomeURL = () => this.deleteMessengerProfile(['home_url']);this.getMessageTags = () => this._http.get(`/page_message_tags?access_token=${this._accessToken}`).then(res => res.data.data);this.sendRawBody = body => this._http.post(`/me/messages?access_token=${this._accessToken}`, body).then(res => res.data);this.send = (idOrRecipient, message, options) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;return this.sendRawBody(_extends({ recipient, message }, options));};this.sendFormData = (recipient, message, filedata) => {const form = new _formData2.default();const recipientObject = typeof recipient === 'string' ? { id: recipient } : recipient;form.append('recipient', JSON.stringify(recipientObject));form.append('message', JSON.stringify(message));form.append('filedata', filedata);return this._http.post(`/me/messages?access_token=${this._accessToken}`, form, { headers: form.getHeaders() }).then(res => res.data);};this.sendAttachment = (recipient, attachment, options) => this.send(recipient, { attachment }, options);this.sendAttachmentFormData = (recipient, attachment, filedata) => this.sendFormData(recipient, { attachment }, filedata);this.sendText = (recipient, text, options) => this.send(recipient, { text }, options);this.sendIssueResolutionText = (recipient, text) => this.sendText(recipient, text, { tag: 'ISSUE_RESOLUTION' });this.sendAudio = (recipient, audio) => {const attachment = { type: 'audio', payload: {} };if (typeof audio === 'string') {attachment.payload.url = audio;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, audio);};this.sendImage = (recipient, image) => {const attachment = { type: 'image', payload: {} };if (typeof image === 'string') {attachment.payload.url = image;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, image);};this.sendVideo = (recipient, video) => {const attachment = { type: 'video', payload: {} };if (typeof video === 'string') {attachment.payload.url = video;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, video);};this.sendFile = (recipient, file) => {const attachment = { type: 'file', payload: {} };if (typeof file === 'string') {attachment.payload.url = file;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, file);};this.sendTemplate = (recipient, payload, options) => this.sendAttachment(recipient, { type: 'template', payload }, options);this.sendButtonTemplate = (recipient, text, buttons) => this.sendTemplate(recipient, { template_type: 'button', text, buttons });this.sendGenericTemplate = (recipient, elements, ratio = 'horizontal', options) => this.sendTemplate(recipient, { template_type: 'generic', elements, image_aspect_ratio: ratio // FIXME rename to image_aspect_ratio?
}, options);this.sendTaggedTemplate = (recipient, elements, tag, ratio = 'horizontal') => this.sendGenericTemplate(recipient, elements, ratio, { tag });this.sendShippingUpdateTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'SHIPPING_UPDATE', ratio);this.sendReservationUpdateTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'RESERVATION_UPDATE', ratio);this.sendIssueResolutionTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'ISSUE_RESOLUTION', ratio);this.sendAppointmentUpdateTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'APPOINTMENT_UPDATE', ratio);this.sendGameEventTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'GAME_EVENT', ratio);this.sendTransportationUpdateTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'TRANSPORTATION_UPDATE', ratio);this.sendFeatureFunctionalityUpdateTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'FEATURE_FUNCTIONALITY_UPDATE', ratio);this.sendTicketUpdateTemplate = (recipient, elements, ratio = 'horizontal') => this.sendTaggedTemplate(recipient, elements, 'TICKET_UPDATE', ratio);this.sendListTemplate = (recipient, elements, buttons, topElementStyle = 'large') => this.sendTemplate(recipient, { template_type: 'list', elements, buttons, top_element_style: topElementStyle });this.sendOpenGraphTemplate = (recipient, elements) => this.sendTemplate(recipient, { template_type: 'open_graph', elements });this.sendReceiptTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'receipt' }, attrs));this.sendAirlineBoardingPassTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_boardingpass' }, attrs));this.sendAirlineCheckinTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_checkin' }, attrs));this.sendAirlineItineraryTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_itinerary' }, attrs));this.sendAirlineFlightUpdateTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_update' }, attrs));this.sendQuickReplies = (recipient, textOrAttachment, quickReplies) => {// quick_replies is limited to 11
(0, _invariant2.default)(Array.isArray(quickReplies) && quickReplies.length <= 11, 'quickReplies is an array and limited to 11');quickReplies.forEach(quickReply => {if (quickReply.content_type === 'text') {// title has a 20 character limit, after that it gets truncated
(0, _invariant2.default)(quickReply.title.trim().length <= 20, 'title of quickReply has a 20 character limit, after that it gets truncated'); // payload has a 1000 character limit
(0, _invariant2.default)(quickReply.payload.length <= 1000, 'payload of quickReply has a 1000 character limit');}});return this.send(recipientId, _extends({}, textOrAttachment, { quick_replies: quickReplies }));};this.sendSenderAction = (recipientId, action) => this._http.post(`/me/messages?access_token=${this._accessToken}`, { recipient: { id: recipientId }, sender_action: action }).then(res => res.data);this.turnTypingIndicatorsOn = recipientId => this.sendSenderAction(recipientId, 'typing_on');this.turnTypingIndicatorsOff = recipientId => this.sendSenderAction(recipientId, 'typing_off');this.uploadAttachment = (type, url) => this._http.post(`/me/message_attachments?access_token=${this._accessToken}`, { message: { attachment: { type, payload: { url, is_reusable: true } } } }).then(res => res.data);this.uploadAudio = url => this.uploadAttachment('audio', url);this.uploadImage = url => this.uploadAttachment('image', url);this.uploadVideo = url => this.uploadAttachment('video', url);this.uploadFile = url => this.uploadAttachment('file', url);this.generateMessengerCode = (options = {}) => this._http.post(`/me/messenger_codes?access_token=${this._accessToken}`, _extends({ type: 'standard' }, options)).then(res => res.data);this.passThreadControl = (recipientId, targetAppId, metadata) => this._http.post(`/me/pass_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, target_app_id: targetAppId, metadata }).then(res => res.data);this.takeThreadControl = (recipientId, metadata) => this._http.post(`/me/take_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, metadata }).then(res => res.data);this.getSecondaryReceivers = () => this._http.get(`/me/secondary_receivers?fields=id,name&access_token=${this._accessToken}`).then(res => res.data.data);this.getDailyUniqueActiveThreadCounts = () => this._http.get(`/me/insights/page_messages_active_threads_unique&access_token=${this._accessToken}`).then(res => res.data.data);this.getDailyUniqueConversationCounts = () => this._http.get(`/me/insights/page_messages_feedback_by_action_unique&access_token=${this._accessToken}`).then(res => res.data.data);this.setNLPConfigs = (config = {}) => {const query = { nlp_enabled: config.nlp_enabled ? 'true' : 'false' };if (config.custom_token) {query.custom_token = config.custom_token;
(0, _invariant2.default)(quickReply.payload.length <= 1000, 'payload of quickReply has a 1000 character limit');}});return this.send(recipient, _extends({}, textOrAttachment, { quick_replies: quickReplies }));};this.sendSenderAction = (idOrRecipient, action) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;return this.sendRawBody({ recipient, sender_action: action });};this.turnTypingIndicatorsOn = recipient => this.sendSenderAction(recipient, 'typing_on');this.turnTypingIndicatorsOff = recipient => this.sendSenderAction(recipient, 'typing_off');this.uploadAttachment = (type, url) => this._http.post(`/me/message_attachments?access_token=${this._accessToken}`, { message: { attachment: { type, payload: { url, is_reusable: true } } } }).then(res => res.data);this.uploadAudio = url => this.uploadAttachment('audio', url);this.uploadImage = url => this.uploadAttachment('image', url);this.uploadVideo = url => this.uploadAttachment('video', url);this.uploadFile = url => this.uploadAttachment('file', url);this.generateMessengerCode = (options = {}) => this._http.post(`/me/messenger_codes?access_token=${this._accessToken}`, _extends({ type: 'standard' }, options)).then(res => res.data);this.passThreadControl = (recipientId, targetAppId, metadata) => this._http.post(`/me/pass_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, target_app_id: targetAppId, metadata }).then(res => res.data);this.takeThreadControl = (recipientId, metadata) => this._http.post(`/me/take_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, metadata }).then(res => res.data);this.getSecondaryReceivers = () => this._http.get(`/me/secondary_receivers?fields=id,name&access_token=${this._accessToken}`).then(res => res.data.data);this.getDailyUniqueActiveThreadCounts = () => this._http.get(`/me/insights/page_messages_active_threads_unique&access_token=${this._accessToken}`).then(res => res.data.data);this.getDailyUniqueConversationCounts = () => this._http.get(`/me/insights/page_messages_feedback_by_action_unique&access_token=${this._accessToken}`).then(res => res.data.data);this.setNLPConfigs = (config = {}) => {const query = { nlp_enabled: config.nlp_enabled ? 'true' : 'false' };if (config.custom_token) {query.custom_token = config.custom_token;
}

@@ -820,0 +881,0 @@

3

lib/MessengerTypes.js

@@ -1,1 +0,2 @@

'use strict';
'use strict';
var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
{
"name": "messaging-api-messenger",
"description": "Messaging API client for Messenger",
"version": "0.2.5",
"version": "0.2.6",
"engines": {

@@ -22,4 +22,5 @@ "node": ">=6"

"axios": "^0.16.1",
"form-data": "^2.2.0",
"invariant": "^2.2.2"
}
}

@@ -92,5 +92,5 @@ # messaging-api-messenger

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -115,5 +115,5 @@ ###### message

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -136,5 +136,5 @@ ###### text

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -153,5 +153,5 @@ ###### text

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -171,3 +171,3 @@ ###### attachment

#### sendAudio(userId, url)
#### sendAudio(userId, audio)

@@ -178,10 +178,12 @@ <img src="https://scontent-tpe1-1.xx.fbcdn.net/v/t39.2365-6/13503473_1584526905179825_88080075_n.png?oh=085ef554f12d061090677b89f3275d64&oe=59EB29D3" alt="sendAudio" width="250" />

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.
###### url
###### audio
Type: `String`
Type: `String | Buffer | ReadStream`
Send audio using url string:
```js

@@ -191,4 +193,12 @@ client.sendAudio(USER_ID, 'https://example.com/audio.mp3');

#### sendImage(userId, url)
or using `ReadStream` created from local file:
```js
const fs = require('fs');
client.sendAudio(USER_ID, fs.createReadStream('audio.mp3'));
```
#### sendImage(userId, image)
<img src="https://scontent-tpe1-1.xx.fbcdn.net/v/t39.2365-6/13466577_1753800631570799_2129488873_n.png?oh=5904aadb6aa82cd2287d777359bd3cd2&oe=59F32D6A" alt="sendImage" width="250" />

@@ -198,10 +208,12 @@

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.
###### url
###### image
Type: `String`
Type: `String | Buffer | ReadStream`
Send image using url string:
```js

@@ -211,4 +223,12 @@ client.sendImage(USER_ID, 'https://example.com/vr.jpg');

#### sendVideo(userId, url)
or using `ReadStream` created from local file:
```js
const fs = require('fs');
client.sendImage(USER_ID, fs.createReadStream('vr.jpg'));
```
#### sendVideo(userId, video)
<img src="https://scontent-tpe1-1.xx.fbcdn.net/v/t39.2365-6/13509239_1608341092811398_289173120_n.png?oh=160ea165834203bae79c24c8e07137de&oe=5A350DB4" alt="sendVideo" width="250" />

@@ -218,10 +238,12 @@

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.
###### url
###### video
Type: `String`
Type: `String | Buffer | ReadStream`
Send video using url string:
```js

@@ -231,4 +253,12 @@ client.sendVideo(USER_ID, 'https://example.com/video.mp4');

#### sendFile(userId, url)
or using `ReadStream` created from local file:
```js
const fs = require('fs');
client.sendVideo(USER_ID, fs.createReadStream('video.mp4'));
```
#### sendFile(userId, file)
<img src="https://scontent-tpe1-1.xx.fbcdn.net/v/t39.2365-6/13480153_1115020735225077_1305291896_n.png?oh=a972010ea3edd1ea967885b06317efab&oe=59F63578" alt="sendVideo" width="250" />

@@ -238,10 +268,12 @@

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.
###### url
###### file
Type: `String`
Type: `String | Buffer | ReadStream`
Send file using url string:
```js

@@ -251,2 +283,10 @@ client.sendFile(USER_ID, 'https://example.com/receipt.pdf');

or using `ReadStream` created from local file:
```js
const fs = require('fs');
client.sendFile(USER_ID, fs.createReadStream('receipt.pdf'));
```
<a id="templates" />

@@ -260,5 +300,5 @@

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -289,5 +329,5 @@ ###### template

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -323,5 +363,5 @@ ###### title

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -360,5 +400,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -405,5 +445,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -442,5 +482,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -479,5 +519,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -516,5 +556,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -553,5 +593,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -590,5 +630,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -627,5 +667,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -664,5 +704,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -703,5 +743,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -762,5 +802,5 @@ ###### items

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -792,5 +832,5 @@ ###### elements

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -860,5 +900,5 @@ ###### receipt

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -994,5 +1034,5 @@ ###### attributes

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -1040,5 +1080,5 @@ ###### attributes

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -1180,5 +1220,5 @@ ###### attributes

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -1228,5 +1268,5 @@ ###### attributes

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -1261,5 +1301,5 @@ ###### message

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -1280,5 +1320,5 @@ ###### action

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -1293,5 +1333,5 @@ ```js

Type: `String`
Type: `String | Object`
Page-scoped user ID of the recipient.
Page-scoped user ID of the recipient or [recipient](https://developers.facebook.com/docs/messenger-platform/send-api-reference#recipient) object.

@@ -2019,3 +2059,3 @@ ```js

// ]
})
});
```

@@ -2059,3 +2099,3 @@

// ],
})
});
```

@@ -2062,0 +2102,0 @@

import querystring from 'querystring';
import axios from 'axios';
import FormData from 'form-data';
import invariant from 'invariant';
import type {
UserID,
Recipient,
AttachmentPayload,

@@ -33,2 +36,3 @@ Attachment,

MessageTagResponse,
FileData,
} from './MessengerTypes';

@@ -343,14 +347,41 @@

send = (
recipientId: string,
idOrRecipient: UserID | Recipient,
message: Message,
options?: SendOption
): Promise<SendMessageSucessResponse> =>
this.sendRawBody({
recipient: {
id: recipientId,
},
): Promise<SendMessageSucessResponse> => {
const recipient =
typeof idOrRecipient === 'string'
? {
id: idOrRecipient,
}
: idOrRecipient;
return this.sendRawBody({
recipient,
message,
...options,
});
};
sendFormData = (
recipient: UserID | Recipient,
message: Message,
filedata: FileData
) => {
const form = new FormData();
const recipientObject =
typeof recipient === 'string'
? {
id: recipient,
}
: recipient;
form.append('recipient', JSON.stringify(recipientObject));
form.append('message', JSON.stringify(message));
form.append('filedata', filedata);
return this._http
.post(`/me/messages?access_token=${this._accessToken}`, form, {
headers: form.getHeaders(),
})
.then(res => res.data);
};
/**

@@ -362,69 +393,96 @@ * Content Types

sendAttachment = (
recipientId: string,
recipient: UserID | Recipient,
attachment: Attachment,
options?: SendOption
): Promise<SendMessageSucessResponse> =>
this.send(recipientId, { attachment }, options);
this.send(recipient, { attachment }, options);
sendAttachmentFormData = (
recipient: UserID | Recipient,
attachment: Attachment,
filedata: FileData
): Promise<SendMessageSucessResponse> =>
this.sendFormData(recipient, { attachment }, filedata);
sendText = (
recipientId: string,
recipient: UserID | Recipient,
text: string,
options?: SendOption
): Promise<SendMessageSucessResponse> =>
this.send(recipientId, { text }, options);
this.send(recipient, { text }, options);
sendIssueResolutionText = (
recipientId: string,
recipient: UserID | Recipient,
text: string
): Promise<SendMessageSucessResponse> =>
this.sendText(recipientId, text, { tag: 'ISSUE_RESOLUTION' });
this.sendText(recipient, text, { tag: 'ISSUE_RESOLUTION' });
// TODO: support formdata fileupload?
sendAudio = (
recipientId: string,
url: string
): Promise<SendMessageSucessResponse> =>
this.sendAttachment(recipientId, {
recipient: UserID | Recipient,
audio: string | FileData
): Promise<SendMessageSucessResponse> => {
const attachment = {
type: 'audio',
payload: {
url,
},
});
payload: {},
};
// TODO: support formdata fileupload?
if (typeof audio === 'string') {
attachment.payload.url = audio;
return this.sendAttachment(recipient, attachment);
}
return this.sendAttachmentFormData(recipient, attachment, audio);
};
sendImage = (
recipientId: string,
url: string
): Promise<SendMessageSucessResponse> =>
this.sendAttachment(recipientId, {
recipient: UserID | Recipient,
image: string | FileData
): Promise<SendMessageSucessResponse> => {
const attachment = {
type: 'image',
payload: {
url,
},
});
payload: {},
};
// TODO: support formdata fileupload?
if (typeof image === 'string') {
attachment.payload.url = image;
return this.sendAttachment(recipient, attachment);
}
return this.sendAttachmentFormData(recipient, attachment, image);
};
sendVideo = (
recipientId: string,
url: string
): Promise<SendMessageSucessResponse> =>
this.sendAttachment(recipientId, {
recipient: UserID | Recipient,
video: string | FileData
): Promise<SendMessageSucessResponse> => {
const attachment = {
type: 'video',
payload: {
url,
},
});
payload: {},
};
// TODO: support formdata fileupload?
if (typeof video === 'string') {
attachment.payload.url = video;
return this.sendAttachment(recipient, attachment);
}
return this.sendAttachmentFormData(recipient, attachment, video);
};
sendFile = (
recipientId: string,
url: string
): Promise<SendMessageSucessResponse> =>
this.sendAttachment(recipientId, {
recipient: UserID | Recipient,
file: string | FileData
): Promise<SendMessageSucessResponse> => {
const attachment = {
type: 'file',
payload: {
url,
},
});
payload: {},
};
if (typeof file === 'string') {
attachment.payload.url = file;
return this.sendAttachment(recipient, attachment);
}
return this.sendAttachmentFormData(recipient, attachment, file);
};
/**

@@ -436,3 +494,3 @@ * Templates

sendTemplate = (
recipientId: string,
recipient: UserID | Recipient,
payload: AttachmentPayload,

@@ -442,3 +500,3 @@ options?: SendOption

this.sendAttachment(
recipientId,
recipient,
{

@@ -453,7 +511,7 @@ type: 'template',

sendButtonTemplate = (
recipientId: string,
recipient: UserID | Recipient,
text: string,
buttons: Array<TemplateButton>
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'button',

@@ -466,3 +524,3 @@ text,

sendGenericTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,

@@ -473,3 +531,3 @@ ratio: string = 'horizontal',

this.sendTemplate(
recipientId,
recipient,
{

@@ -485,3 +543,3 @@ template_type: 'generic',

sendTaggedTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,

@@ -491,41 +549,41 @@ tag: MessageTag,

): Promise<SendMessageSucessResponse> =>
this.sendGenericTemplate(recipientId, elements, ratio, { tag });
this.sendGenericTemplate(recipient, elements, ratio, { tag });
sendShippingUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal'
): Promise<SendMessageSucessResponse> =>
this.sendTaggedTemplate(recipientId, elements, 'SHIPPING_UPDATE', ratio);
this.sendTaggedTemplate(recipient, elements, 'SHIPPING_UPDATE', ratio);
sendReservationUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal'
): Promise<SendMessageSucessResponse> =>
this.sendTaggedTemplate(recipientId, elements, 'RESERVATION_UPDATE', ratio);
this.sendTaggedTemplate(recipient, elements, 'RESERVATION_UPDATE', ratio);
sendIssueResolutionTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal'
): Promise<SendMessageSucessResponse> =>
this.sendTaggedTemplate(recipientId, elements, 'ISSUE_RESOLUTION', ratio);
this.sendTaggedTemplate(recipient, elements, 'ISSUE_RESOLUTION', ratio);
sendAppointmentUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal'
): Promise<SendMessageSucessResponse> =>
this.sendTaggedTemplate(recipientId, elements, 'APPOINTMENT_UPDATE', ratio);
this.sendTaggedTemplate(recipient, elements, 'APPOINTMENT_UPDATE', ratio);
sendGameEventTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal'
): Promise<SendMessageSucessResponse> =>
this.sendTaggedTemplate(recipientId, elements, 'GAME_EVENT', ratio);
this.sendTaggedTemplate(recipient, elements, 'GAME_EVENT', ratio);
sendTransportationUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,

@@ -535,3 +593,3 @@ ratio: string = 'horizontal'

this.sendTaggedTemplate(
recipientId,
recipient,
elements,

@@ -543,3 +601,3 @@ 'TRANSPORTATION_UPDATE',

sendFeatureFunctionalityUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,

@@ -549,3 +607,3 @@ ratio: string = 'horizontal'

this.sendTaggedTemplate(
recipientId,
recipient,
elements,

@@ -557,11 +615,11 @@ 'FEATURE_FUNCTIONALITY_UPDATE',

sendTicketUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,
ratio: string = 'horizontal'
): Promise<SendMessageSucessResponse> =>
this.sendTaggedTemplate(recipientId, elements, 'TICKET_UPDATE', ratio);
this.sendTaggedTemplate(recipient, elements, 'TICKET_UPDATE', ratio);
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/list-template
sendListTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<TemplateElement>,

@@ -571,3 +629,3 @@ buttons: Array<TemplateButton>,

): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'list',

@@ -581,6 +639,6 @@ elements,

sendOpenGraphTemplate = (
recipientId: string,
recipient: UserID | Recipient,
elements: Array<OpenGraphElement>
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'open_graph',

@@ -592,6 +650,6 @@ elements,

sendReceiptTemplate = (
recipientId: string,
recipient: UserID | Recipient,
attrs: ReceiptAttributes
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'receipt',

@@ -603,6 +661,6 @@ ...attrs,

sendAirlineBoardingPassTemplate = (
recipientId: string,
recipient: UserID | Recipient,
attrs: AirlineBoardingPassAttributes
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'airline_boardingpass',

@@ -614,6 +672,6 @@ ...attrs,

sendAirlineCheckinTemplate = (
recipientId: string,
recipient: UserID | Recipient,
attrs: AirlineCheckinAttributes
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'airline_checkin',

@@ -625,6 +683,6 @@ ...attrs,

sendAirlineItineraryTemplate = (
recipientId: string,
recipient: UserID | Recipient,
attrs: AirlineItineraryAttributes
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'airline_itinerary',

@@ -636,6 +694,6 @@ ...attrs,

sendAirlineFlightUpdateTemplate = (
recipientId: string,
recipient: UserID | Recipient,
attrs: AirlineFlightUpdateAttributes
): Promise<SendMessageSucessResponse> =>
this.sendTemplate(recipientId, {
this.sendTemplate(recipient, {
template_type: 'airline_update',

@@ -651,3 +709,3 @@ ...attrs,

sendQuickReplies = (
recipientId: string,
recipient: UserID | Recipient,
textOrAttachment: TextOrAttachment,

@@ -678,3 +736,3 @@ quickReplies: Array<QuickReply>

return this.send(recipientId, {
return this.send(recipient, {
...textOrAttachment,

@@ -691,23 +749,26 @@ quick_replies: quickReplies,

sendSenderAction = (
recipientId: string,
idOrRecipient: UserID | Recipient,
action: SenderAction
): Promise<SendSenderActionResponse> =>
this._http
.post(`/me/messages?access_token=${this._accessToken}`, {
recipient: {
id: recipientId,
},
sender_action: action,
})
.then(res => res.data);
): Promise<SendSenderActionResponse> => {
const recipient =
typeof idOrRecipient === 'string'
? {
id: idOrRecipient,
}
: idOrRecipient;
return this.sendRawBody({
recipient,
sender_action: action,
});
};
turnTypingIndicatorsOn = (
recipientId: string
recipient: UserID | Recipient
): Promise<SendSenderActionResponse> =>
this.sendSenderAction(recipientId, 'typing_on');
this.sendSenderAction(recipient, 'typing_on');
turnTypingIndicatorsOff = (
recipientId: string
recipient: UserID | Recipient
): Promise<SendSenderActionResponse> =>
this.sendSenderAction(recipientId, 'typing_off');
this.sendSenderAction(recipient, 'typing_off');

@@ -714,0 +775,0 @@ /**

/* @flow */
import fs from 'fs';
export type UserID = string;
export type RecipientWithID = {
id: UserID,
};
export type RecipientWithPhoneNumber = {
phone_number: string,
name?: Object,
};
export type Recipient = RecipientWithID | RecipientWithPhoneNumber;
export type AttachmentPayload = {

@@ -266,1 +280,3 @@ url?: string,

}>;
export type FileData = Buffer | fs.ReadStream;

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc