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
3
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.5.13 to 0.5.14

228

lib/MessengerClient.js

@@ -144,2 +144,4 @@ '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;};

/**

@@ -156,2 +158,5 @@ * Get User Profile

/**

@@ -190,2 +195,14 @@ * Messenger Profile

/**

@@ -235,2 +252,6 @@ * Get Started Button

/**

@@ -272,2 +293,15 @@ * Persistent Menu

/**

@@ -331,2 +365,11 @@ * Greeting Text

/**

@@ -383,2 +426,10 @@ * Domain Whitelist

/**

@@ -402,2 +453,12 @@ * Account Linking URL

/**

@@ -441,2 +502,20 @@ * Payment Settings

/**

@@ -470,2 +549,10 @@ * Target Audience

/**

@@ -542,2 +629,8 @@ * Chat Extension Home URL

/**

@@ -553,2 +646,7 @@ * Message tags

/**

@@ -637,2 +735,13 @@ * Send API

/**

@@ -997,2 +1106,7 @@ * Content Types

/**

@@ -1036,2 +1150,3 @@ * Send Batch Request

/**

@@ -1055,2 +1170,9 @@ * Broadcast API

/**

@@ -1069,2 +1191,6 @@ * Send Broadcast Message

/**

@@ -1102,2 +1228,9 @@ * Send Sponsored Message

/**

@@ -1115,2 +1248,10 @@ * Associating a Label to a PSID

/**

@@ -1128,2 +1269,10 @@ * Removing a Label From a PSID

/**

@@ -1139,2 +1288,8 @@ * Retrieving Labels Associated with a PSID

/**

@@ -1152,2 +1307,5 @@ * Retrieving Label Details

/**

@@ -1167,2 +1325,3 @@ * Retrieving a List of All Labels

/**

@@ -1178,2 +1337,7 @@ * Deleting a Label

/**

@@ -1191,2 +1355,9 @@ * Starting a Reach Estimation

/**

@@ -1202,2 +1373,8 @@ * Retrieving a Reach Estimate

/**

@@ -1217,2 +1394,5 @@ * Broadcast Metrics

/**

@@ -1281,2 +1461,3 @@ * Upload API

/**

@@ -1295,2 +1476,6 @@ * Messenger Code API

/**

@@ -1323,2 +1508,10 @@ * Handover Protocol API

/**

@@ -1337,2 +1530,10 @@ * Take Thread Control

/**

@@ -1351,2 +1552,4 @@ * Secondary Receivers List

/**

@@ -1406,2 +1609,7 @@ * Page Messaging Insights API

/**

@@ -1411,16 +1619,21 @@ * Logging Custom Events

* https://developers.facebook.com/docs/app-events/bots-for-messenger#logging-custom-events
*/}exports.default = MessengerClient;MessengerClient.connect = (accessToken, version = '2.11') => new MessengerClient(accessToken, version);var _initialiseProps = function _initialiseProps() {this.getHTTPClient = () => {(0, _warning2.default)(false, '`.getHTTPClient` method is deprecated. use `.axios` getter instead.');return this._axios;};this.getPageInfo = () => this._axios.get(`/me?access_token=${this._accessToken}`).then(res => res.data, handleError);this.getUserProfile = userId => this._axios.get(`/${userId}?access_token=${this._accessToken}`).then(res => res.data, handleError);this.getMessengerProfile = fields => this._axios.get(`/me/messenger_profile?fields=${fields.join(',')}&access_token=${this._accessToken}`).then(res => res.data.data, handleError);this.setMessengerProfile = profile => this._axios.post(`/me/messenger_profile?access_token=${this._accessToken}`, profile).then(res => res.data, handleError);this.deleteMessengerProfile = fields => this._axios.delete(`/me/messenger_profile?access_token=${this._accessToken}`, { data: { fields } }).then(res => res.data, handleError);this.getGetStarted = () => this.getMessengerProfile(['get_started']).then(res => res[0] ? res[0].get_started : null);this.getGetStartedButton = () => {(0, _warning2.default)(false, '`getGetStartedButton` is deprecated, use `getGetStarted` instead');return this.getGetStarted();};this.setGetStarted = payload => this.setMessengerProfile({ get_started: { payload } });this.setGetStartedButton = payload => {(0, _warning2.default)(false, '`setGetStartedButton` is deprecated, use `setGetStarted` instead');return this.setGetStarted(payload);};this.deleteGetStarted = () => this.deleteMessengerProfile(['get_started']);this.deleteGetStartedButton = () => {(0, _warning2.default)(false, '`deleteGetStartedButton` is deprecated, use `deleteGetStarted` instead');return this.deleteGetStarted();};this.getPersistentMenu = () => this.getMessengerProfile(['persistent_menu']).then(res => res[0] ? res[0].persistent_menu : null);this.setPersistentMenu = (menuItems, { composerInputDisabled = false } = {}) => {// menuItems is in type PersistentMenu
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.getGreeting = () => this.getMessengerProfile(['greeting']).then(res => res[0] ? res[0].greeting : null);this.getGreetingText = () => {(0, _warning2.default)(false, '`getGreetingText` is deprecated, use `getGreeting` instead');return this.getGreeting();};this.setGreeting = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.setGreetingText = greeting => {(0, _warning2.default)(false, '`setGreetingText` is deprecated, use `setGreeting` instead');return this.setGreeting(greeting);};this.deleteGreeting = () => this.deleteMessengerProfile(['greeting']);this.deleteGreetingText = () => {(0, _warning2.default)(false, '`deleteGreetingText` is deprecated, use `deleteGreeting` instead');return this.deleteGreeting();};this.getDomainWhitelist = () => {(0, _warning2.default)(false, '`getDomainWhitelist` is deprecated. use `getWhitelistedDomains` instead.');return this.getWhitelistedDomains();};this.setDomainWhitelist = domains => {(0, _warning2.default)(false, '`setDomainWhitelist` is deprecated. use `setWhitelistedDomains` instead.');return this.setWhitelistedDomains(domains);};this.deleteDomainWhitelist = () => {(0, _warning2.default)(false, '`deleteDomainWhitelist` is deprecated. use `deleteWhitelistedDomains` instead.');return this.deleteWhitelistedDomains();};this.getWhitelistedDomains = () => this.getMessengerProfile(['whitelisted_domains']).then(res => res[0] ? res[0].whitelisted_domains : null);this.setWhitelistedDomains = domains => this.setMessengerProfile({ whitelisted_domains: domains });this.deleteWhitelistedDomains = () => this.deleteMessengerProfile(['whitelisted_domains']);this.getAccountLinkingURL = () => this.getMessengerProfile(['account_linking_url']).then(res => res[0] ? res[0] : null);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] ? res[0] : null);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] ? res[0] : null);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0] ? res[0] : null);this.getChatExtensionHomeURL = () => {(0, _warning2.default)(false, '`getChatExtensionHomeURL` is deprecated. use `getHomeURL` instead.');return this.getHomeURL();};this.setHomeURL = (url, { webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio: 'tall', in_test, webview_share_button } });this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => {(0, _warning2.default)(false, '`setChatExtensionHomeURL` is deprecated. use `setHomeURL` instead.');return this.setHomeURL(url, { webview_height_ratio, webview_share_button, in_test });};this.deleteHomeURL = () => this.deleteMessengerProfile(['home_url']);this.deleteChatExtensionHomeURL = () => {(0, _warning2.default)(false, '`deleteChatExtensionHomeURL` is deprecated. use `deleteHomeURL` instead.');return this.deleteHomeURL();};this.getMessageTags = () => this._axios.get(`/page_message_tags?access_token=${this._accessToken}`).then(res => res.data.data, handleError);this.sendRawBody = body => this._axios.post(`/me/messages?access_token=${this._accessToken}`, body).then(res => res.data, handleError);this.sendMessage = (idOrRecipient, message, options = {}) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;let messageType = 'UPDATE';if (options.messaging_type) {messageType = options.messaging_type;} else if (options.tag) {messageType = 'MESSAGE_TAG';}const quickReplies = options.quick_replies,otherOptions = _objectWithoutProperties(options, ['quick_replies']);if (quickReplies) {validateQuickReplies(quickReplies);message.quick_replies = quickReplies; // eslint-disable-line no-param-reassign
*/}exports.default = MessengerClient;MessengerClient.connect = (accessToken, version = '2.11') => new MessengerClient(accessToken, version);var _initialiseProps = function _initialiseProps() {this.getHTTPClient = () => {(0, _warning2.default)(false, '`.getHTTPClient` method is deprecated. use `.axios` getter instead.');return this._axios;};this.getPageInfo = ({ access_token: customAccessToken } = {}) => this._axios.get(`/me?access_token=${customAccessToken || this._accessToken}`).then(res => res.data, handleError);this.getUserProfile = (userId, { access_token: customAccessToken } = {}) => this._axios.get(`/${userId}?access_token=${customAccessToken || this._accessToken}`).then(res => res.data, handleError);this.getMessengerProfile = (fields, { access_token: customAccessToken } = {}) => this._axios.get(`/me/messenger_profile?fields=${fields.join(',')}&access_token=${customAccessToken || this._accessToken}`).then(res => res.data.data, handleError);this.setMessengerProfile = (profile, { access_token: customAccessToken } = {}) => this._axios.post(`/me/messenger_profile?access_token=${customAccessToken || this._accessToken}`, profile).then(res => res.data, handleError);this.deleteMessengerProfile = (fields, { access_token: customAccessToken } = {}) => this._axios.delete(`/me/messenger_profile?access_token=${customAccessToken || this._accessToken}`, { data: { fields } }).then(res => res.data, handleError);this.getGetStarted = (options = {}) => this.getMessengerProfile(['get_started'], options).then(res => res[0] ? res[0].get_started : null);this.getGetStartedButton = () => {(0, _warning2.default)(false, '`getGetStartedButton` is deprecated, use `getGetStarted` instead');return this.getGetStarted();};this.setGetStarted = payload => this.setMessengerProfile({ get_started: { payload } });this.setGetStartedButton = payload => {(0, _warning2.default)(false, '`setGetStartedButton` is deprecated, use `setGetStarted` instead');return this.setGetStarted(payload);};this.deleteGetStarted = (options = {}) => this.deleteMessengerProfile(['get_started'], options);this.deleteGetStartedButton = () => {(0, _warning2.default)(false, '`deleteGetStartedButton` is deprecated, use `deleteGetStarted` instead');return this.deleteGetStarted();};this.getPersistentMenu = (options = {}) => this.getMessengerProfile(['persistent_menu'], options).then(res => res[0] ? res[0].persistent_menu : null);this.setPersistentMenu = (menuItems, _ref = {}) => {var _ref$composer_input_d = _ref.composer_input_disabled;let composerInputDisabled = _ref$composer_input_d === undefined ? false : _ref$composer_input_d,options = _objectWithoutProperties(_ref, ['composer_input_disabled']); // menuItems is in type PersistentMenu
if (menuItems.some(item => item.locale === 'default')) {return this.setMessengerProfile({ persistent_menu: menuItems }, options);} // menuItems is in type Array<MenuItem>
return this.setMessengerProfile({ persistent_menu: [{ locale: 'default', composer_input_disabled: composerInputDisabled, call_to_actions: menuItems }] }, options);};this.deletePersistentMenu = (options = {}) => this.deleteMessengerProfile(['persistent_menu'], options);this.getGreeting = (options = {}) => this.getMessengerProfile(['greeting'], options).then(res => res[0] ? res[0].greeting : null);this.getGreetingText = () => {(0, _warning2.default)(false, '`getGreetingText` is deprecated, use `getGreeting` instead');return this.getGreeting();};this.setGreeting = (greeting, options = {}) => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] }, options);}return this.setMessengerProfile({ greeting }, options);};this.setGreetingText = greeting => {(0, _warning2.default)(false, '`setGreetingText` is deprecated, use `setGreeting` instead');return this.setGreeting(greeting);};this.deleteGreeting = (options = {}) => this.deleteMessengerProfile(['greeting'], options);this.deleteGreetingText = () => {(0, _warning2.default)(false, '`deleteGreetingText` is deprecated, use `deleteGreeting` instead');return this.deleteGreeting();};this.getDomainWhitelist = () => {(0, _warning2.default)(false, '`getDomainWhitelist` is deprecated. use `getWhitelistedDomains` instead.');return this.getWhitelistedDomains();};this.setDomainWhitelist = domains => {(0, _warning2.default)(false, '`setDomainWhitelist` is deprecated. use `setWhitelistedDomains` instead.');return this.setWhitelistedDomains(domains);};this.deleteDomainWhitelist = () => {(0, _warning2.default)(false, '`deleteDomainWhitelist` is deprecated. use `deleteWhitelistedDomains` instead.');return this.deleteWhitelistedDomains();};this.getWhitelistedDomains = (options = {}) => this.getMessengerProfile(['whitelisted_domains'], options).then(res => res[0] ? res[0].whitelisted_domains : null);this.setWhitelistedDomains = (domains, options = {}) => this.setMessengerProfile({ whitelisted_domains: domains }, options);this.deleteWhitelistedDomains = (options = {}) => this.deleteMessengerProfile(['whitelisted_domains'], options);this.getAccountLinkingURL = (options = {}) => this.getMessengerProfile(['account_linking_url'], options).then(res => res[0] ? res[0] : null);this.setAccountLinkingURL = (url, options = {}) => this.setMessengerProfile({ account_linking_url: url }, options);this.deleteAccountLinkingURL = (options = {}) => this.deleteMessengerProfile(['account_linking_url'], options);this.getPaymentSettings = (options = {}) => this.getMessengerProfile(['payment_settings'], options).then(res => res[0] ? res[0] : null);this.setPaymentPrivacyPolicyURL = (url, options = {}) => this.setMessengerProfile({ payment_settings: { privacy_url: url } }, options);this.setPaymentPublicKey = (key, options = {}) => this.setMessengerProfile({ payment_settings: { public_key: key } }, options);this.setPaymentTestUsers = (users, options = {}) => this.setMessengerProfile({ payment_settings: { test_users: users } }, options);this.deletePaymentSettings = (options = {}) => this.deleteMessengerProfile(['payment_settings'], options);this.getTargetAudience = (options = {}) => this.getMessengerProfile(['target_audience'], options).then(res => res[0] ? res[0] : null);this.setTargetAudience = (type, whitelist = [], blacklist = [], options = {}) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } }, options);this.deleteTargetAudience = (options = {}) => this.deleteMessengerProfile(['target_audience'], options);this.getHomeURL = (options = {}) => this.getMessengerProfile(['home_url'], options).then(res => res[0] ? res[0] : null);this.getChatExtensionHomeURL = () => {(0, _warning2.default)(false, '`getChatExtensionHomeURL` is deprecated. use `getHomeURL` instead.');return this.getHomeURL();};this.setHomeURL = (url, { webview_share_button, in_test }, options = {}) => this.setMessengerProfile({ home_url: { url, webview_height_ratio: 'tall', in_test, webview_share_button } }, options);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => {(0, _warning2.default)(false, '`setChatExtensionHomeURL` is deprecated. use `setHomeURL` instead.');return this.setHomeURL(url, { webview_height_ratio, webview_share_button, in_test });};this.deleteHomeURL = (options = {}) => this.deleteMessengerProfile(['home_url'], options);this.deleteChatExtensionHomeURL = () => {(0, _warning2.default)(false, '`deleteChatExtensionHomeURL` is deprecated. use `deleteHomeURL` instead.');return this.deleteHomeURL();};this.getMessageTags = ({ access_token: customAccessToken } = {}) => this._axios.get(`/page_message_tags?access_token=${customAccessToken || this._accessToken}`).then(res => res.data.data, handleError);this.sendRawBody = body => {const customAccessToken = body.access_token;return this._axios.post(`/me/messages?access_token=${customAccessToken || this._accessToken}`, body).then(res => res.data, handleError);};this.sendMessage = (idOrRecipient, message, options = {}) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;let messageType = 'UPDATE';if (options.messaging_type) {messageType = options.messaging_type;} else if (options.tag) {messageType = 'MESSAGE_TAG';}const quickReplies = options.quick_replies,otherOptions = _objectWithoutProperties(options, ['quick_replies']);if (quickReplies) {validateQuickReplies(quickReplies);message.quick_replies = quickReplies; // eslint-disable-line no-param-reassign
}return this.sendRawBody(_extends({ messaging_type: messageType, recipient, message }, otherOptions));};this.sendMessageFormData = (recipient, message, filedata, options = {}) => {const form = new _formData2.default();const recipientObject = typeof recipient === 'string' ? { id: recipient } : recipient;let messageType = 'UPDATE';if (options.messaging_type) {messageType = options.messaging_type;} else if (options.tag) {messageType = 'MESSAGE_TAG';}if (options.quick_replies) {validateQuickReplies(options.quick_replies);message.quick_replies = options.quick_replies; // eslint-disable-line no-param-reassign
}form.append('messaging_type', messageType);form.append('recipient', JSON.stringify(recipientObject));form.append('message', JSON.stringify(message));form.append('filedata', filedata);return this._axios.post(`/me/messages?access_token=${this._accessToken}`, form, { headers: form.getHeaders() }).then(res => res.data, handleError);};this.sendAttachment = (recipient, attachment, options) => this.sendMessage(recipient, { attachment }, options);this.sendAttachmentFormData = (recipient, attachment, filedata, option) => this.sendMessageFormData(recipient, { attachment }, filedata, option);this.sendText = (recipient, text, options) => this.sendMessage(recipient, { text }, options);this.sendAudio = (recipient, audio, options) => {const attachment = { type: 'audio', payload: {} };if (typeof audio === 'string') {attachment.payload.url = audio;return this.sendAttachment(recipient, attachment, options);} else if (audio && (0, _isPlainObject2.default)(audio)) {attachment.payload = audio;return this.sendAttachment(recipient, attachment, options);} // $FlowFixMe
}form.append('messaging_type', messageType);form.append('recipient', JSON.stringify(recipientObject));form.append('message', JSON.stringify(message));form.append('filedata', filedata);return this._axios.post(`/me/messages?access_token=${options.access_token || this._accessToken}`, form, { headers: form.getHeaders() }).then(res => res.data, handleError);};this.sendAttachment = (recipient, attachment, options) => this.sendMessage(recipient, { attachment }, options);this.sendAttachmentFormData = (recipient, attachment, filedata, option) => this.sendMessageFormData(recipient, { attachment }, filedata, option);this.sendText = (recipient, text, options) => this.sendMessage(recipient, { text }, options);this.sendAudio = (recipient, audio, options) => {const attachment = { type: 'audio', payload: {} };if (typeof audio === 'string') {attachment.payload.url = audio;return this.sendAttachment(recipient, attachment, options);} else if (audio && (0, _isPlainObject2.default)(audio)) {attachment.payload = audio;return this.sendAttachment(recipient, attachment, options);} // $FlowFixMe
return this.sendAttachmentFormData(recipient, attachment, audio, options);};this.sendImage = (recipient, image, options) => {const attachment = { type: 'image', payload: {} };if (typeof image === 'string') {attachment.payload.url = image;return this.sendAttachment(recipient, attachment, options);} else if (image && (0, _isPlainObject2.default)(image)) {attachment.payload = image;return this.sendAttachment(recipient, attachment, options);} // $FlowFixMe
return this.sendAttachmentFormData(recipient, attachment, image, options);};this.sendVideo = (recipient, video, options) => {const attachment = { type: 'video', payload: {} };if (typeof video === 'string') {attachment.payload.url = video;return this.sendAttachment(recipient, attachment, options);} else if (video && (0, _isPlainObject2.default)(video)) {attachment.payload = video;return this.sendAttachment(recipient, attachment, options);} // $FlowFixMe
return this.sendAttachmentFormData(recipient, attachment, video, options);};this.sendFile = (recipient, file, options) => {const attachment = { type: 'file', payload: {} };if (typeof file === 'string') {attachment.payload.url = file;return this.sendAttachment(recipient, attachment, options);} else if (file && (0, _isPlainObject2.default)(file)) {attachment.payload = file;return this.sendAttachment(recipient, attachment, options);} // $FlowFixMe
return this.sendAttachmentFormData(recipient, attachment, file, options);};this.sendTemplate = (recipient, payload, options) => this.sendAttachment(recipient, { type: 'template', payload }, options);this.sendButtonTemplate = (recipient, text, buttons, options) => this.sendTemplate(recipient, { template_type: 'button', text, buttons }, options);this.sendGenericTemplate = (recipient, elements, options = {}) => this.sendTemplate(recipient, { template_type: 'generic', elements, image_aspect_ratio: options.image_aspect_ratio || 'horizontal' }, (0, _lodash2.default)(options, ['image_aspect_ratio']));this.sendListTemplate = (recipient, elements, buttons, options = {}) => this.sendTemplate(recipient, { template_type: 'list', elements, buttons, top_element_style: options.top_element_style || 'large' }, (0, _lodash2.default)(options, ['top_element_style']));this.sendOpenGraphTemplate = (recipient, elements, options) => this.sendTemplate(recipient, { template_type: 'open_graph', elements }, options);this.sendReceiptTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'receipt' }, attrs), options);this.sendMediaTemplate = (recipient, elements, options) => this.sendTemplate(recipient, { template_type: 'media', elements }, options);this.sendAirlineBoardingPassTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_boardingpass' }, attrs), options);this.sendAirlineCheckinTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_checkin' }, attrs), options);this.sendAirlineItineraryTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_itinerary' }, attrs), options);this.sendAirlineFlightUpdateTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_update' }, attrs), options);this.sendQuickReplies = (recipient, textOrAttachment, quickReplies, options) => {(0, _warning2.default)(false, '`sendQuickReplies` is deprecated. Use send message methods with `options.quick_replies` instead.');validateQuickReplies(quickReplies);return this.sendMessage(recipient, _extends({}, textOrAttachment, { quick_replies: quickReplies }), options);};this.sendSenderAction = (idOrRecipient, action) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;return this.sendRawBody({ recipient, sender_action: action });};this.markSeen = recipient => this.sendSenderAction(recipient, 'mark_seen');this.typingOn = recipient => this.sendSenderAction(recipient, 'typing_on');this.typingOff = recipient => this.sendSenderAction(recipient, 'typing_off');this.sendBatch = batch => {(0, _invariant2.default)(batch.length <= 50, 'limit the number of requests which can be in a batch to 50');const bodyEncodedbatch = batch.map(item => {if (item.body) {return _extends({}, item, { body: Object.keys(item.body).map(key => {// $FlowFixMe item.body should not possible as undefined.
const val = item.body[key];return `${encodeURIComponent(key)}=${encodeURIComponent(typeof val === 'object' ? JSON.stringify(val) : val)}`;}).join('&') });}return item;});return _axios2.default.post('https://graph.facebook.com/', { access_token: this._accessToken, batch: bodyEncodedbatch }).then(res => res.data);};this.createMessageCreative = (messages = []) => this._axios.post(`/me/message_creatives?access_token=${this._accessToken}`, { messages }).then(res => res.data, handleError);this.sendBroadcastMessage = (messageCreativeId, options = {}) => this._axios.post(`/me/broadcast_messages?access_token=${this._accessToken}`, _extends({ message_creative_id: messageCreativeId }, options)).then(res => res.data, handleError);this.sendSponsoredMessage = (adAccountId, message) => this._axios.post(`/act_${adAccountId}/sponsored_message_ads?access_token=${this._accessToken}`, message).then(res => res.data, handleError);this.createLabel = name => this._axios.post(`/me/custom_labels?access_token=${this._accessToken}`, { name }).then(res => res.data, handleError);this.associateLabel = (userId, labelId) => this._axios.post(`/${labelId}/label?access_token=${this._accessToken}`, { user: userId }).then(res => res.data, handleError);this.dissociateLabel = (userId, labelId) => this._axios.delete(`/${labelId}/label?access_token=${this._accessToken}`, { data: { user: userId } }).then(res => res.data, handleError);this.getAssociatedLabels = userId => this._axios.get(`/${userId}/custom_labels?access_token=${this._accessToken}`).then(res => res.data, handleError);this.getLabelDetails = (labelId, options = {}) => {const fields = options.fields ? options.fields.join(',') : 'name';return this._axios.get(`/${labelId}?fields=${fields}&access_token=${this._accessToken}`).then(res => res.data, handleError);};this.getLabelList = (options = {}) => {const fields = options.fields ? options.fields.join(',') : 'name';return this._axios.get(`/me/custom_labels?fields=${fields}&access_token=${this._accessToken}`).then(res => res.data, handleError);};this.deleteLabel = labelId => this._axios.delete(`/${labelId}?access_token=${this._accessToken}`).then(res => res.data, handleError);this.startReachEstimation = customLabelId => this._axios.post(`/broadcast_reach_estimations?access_token=${this._accessToken}`, { custom_label_id: customLabelId }).then(res => res.data, handleError);this.getReachEstimate = reachEstimationId => this._axios.post(`/${reachEstimationId}?access_token=${this._accessToken}`).then(res => res.data, handleError);this.getBroadcastMessagesSent = broadcastId => this._axios.post(`/${broadcastId}/insights/messages_sent?access_token=${this._accessToken}`).then(res => res.data.data, handleError);this.uploadAttachment = (type, attachment, options) => {const args = [];if (typeof attachment === 'string') {args.push({ message: { attachment: { type, payload: { url: attachment, is_reusable: true } } } });} else {const form = new _formData2.default();form.append('message', JSON.stringify({ attachment: { type, payload: { is_reusable: true } } }));form.append('filedata', attachment, options);args.push(form, { headers: form.getHeaders() });}return this._axios.post(`/me/message_attachments?access_token=${this._accessToken}`, ...args).then(res => res.data, handleError);};this.uploadAudio = (attachment, options) => this.uploadAttachment('audio', attachment, options);this.uploadImage = (attachment, options) => this.uploadAttachment('image', attachment, options);this.uploadVideo = (attachment, options) => this.uploadAttachment('video', attachment, options);this.uploadFile = (attachment, options) => this.uploadAttachment('file', attachment, options);this.generateMessengerCode = (options = {}) => this._axios.post(`/me/messenger_codes?access_token=${this._accessToken}`, _extends({ type: 'standard' }, options)).then(res => res.data, handleError);this.passThreadControl = (recipientId, targetAppId, metadata) => this._axios.post(`/me/pass_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, target_app_id: targetAppId, metadata }).then(res => res.data, handleError);this.passThreadControlToPageInbox = (recipientId, metadata) => this.passThreadControl(recipientId, 263902037430900, metadata);this.takeThreadControl = (recipientId, metadata) => this._axios.post(`/me/take_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, metadata }).then(res => res.data, handleError);this.getSecondaryReceivers = () => this._axios.get(`/me/secondary_receivers?fields=id,name&access_token=${this._accessToken}`).then(res => res.data.data, handleError);this.getInsights = (metrics, options = {}) => this._axios.get(`/me/insights/?${_querystring2.default.stringify(_extends({ metric: metrics.join(','), access_token: this._accessToken }, options))}`).then(res => res.data.data, handleError);this.getDailyUniqueActiveThreadCounts = () => this.getInsights(['page_messages_active_threads_unique']);this.getBlockedConversations = () => this.getInsights(['page_messages_blocked_conversations_unique']);this.getReportedConversations = () => this.getInsights(['page_messages_reported_conversations_unique']);this.getReportedConversationsByReportType = () => this.getInsights(['page_messages_blocked_conversations_unique']);this.getDailyUniqueConversationCounts = () => {(0, _warning2.default)(false, 'page_messages_feedback_by_action_unique is deprecated as of November 7, 2017.\nThis metric will be removed in Graph API v2.12.');return this.getInsights(['page_messages_feedback_by_action_unique']);};this.setNLPConfigs = (config = {}) => this._axios.post(`/me/nlp_configs?${_querystring2.default.stringify(config)}`, { access_token: this._accessToken }).then(res => res.data, handleError);this.enableNLP = () => this.setNLPConfigs({ nlp_enabled: true });this.disableNLP = () => this.setNLPConfigs({ nlp_enabled: false });this.logCustomEvents = ({ appId, pageId, userId, events }) =>
return this.sendAttachmentFormData(recipient, attachment, file, options);};this.sendTemplate = (recipient, payload, options) => this.sendAttachment(recipient, { type: 'template', payload }, options);this.sendButtonTemplate = (recipient, text, buttons, options) => this.sendTemplate(recipient, { template_type: 'button', text, buttons }, options);this.sendGenericTemplate = (recipient, elements, options = {}) => this.sendTemplate(recipient, { template_type: 'generic', elements, image_aspect_ratio: options.image_aspect_ratio || 'horizontal' }, (0, _lodash2.default)(options, ['image_aspect_ratio']));this.sendListTemplate = (recipient, elements, buttons, options = {}) => this.sendTemplate(recipient, { template_type: 'list', elements, buttons, top_element_style: options.top_element_style || 'large' }, (0, _lodash2.default)(options, ['top_element_style']));this.sendOpenGraphTemplate = (recipient, elements, options) => this.sendTemplate(recipient, { template_type: 'open_graph', elements }, options);this.sendReceiptTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'receipt' }, attrs), options);this.sendMediaTemplate = (recipient, elements, options) => this.sendTemplate(recipient, { template_type: 'media', elements }, options);this.sendAirlineBoardingPassTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_boardingpass' }, attrs), options);this.sendAirlineCheckinTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_checkin' }, attrs), options);this.sendAirlineItineraryTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_itinerary' }, attrs), options);this.sendAirlineFlightUpdateTemplate = (recipient, attrs, options) => this.sendTemplate(recipient, _extends({ template_type: 'airline_update' }, attrs), options);this.sendQuickReplies = (recipient, textOrAttachment, quickReplies, options) => {(0, _warning2.default)(false, '`sendQuickReplies` is deprecated. Use send message methods with `options.quick_replies` instead.');validateQuickReplies(quickReplies);return this.sendMessage(recipient, _extends({}, textOrAttachment, { quick_replies: quickReplies }), options);};this.sendSenderAction = (idOrRecipient, action, { access_token: customAccessToken } = {}) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;return this.sendRawBody({ recipient, sender_action: action, access_token: customAccessToken });};this.markSeen = (recipient, options = {}) => this.sendSenderAction(recipient, 'mark_seen', options);this.typingOn = (recipient, options = {}) => this.sendSenderAction(recipient, 'typing_on', options);this.typingOff = (recipient, options = {}) => this.sendSenderAction(recipient, 'typing_off', options);this.sendBatch = (batch, { access_token: customAccessToken } = {}) => {(0, _invariant2.default)(batch.length <= 50, 'limit the number of requests which can be in a batch to 50');const bodyEncodedbatch = batch.map(item => {if (item.body) {return _extends({}, item, { body: Object.keys(item.body).map(key => {// $FlowFixMe item.body should not possible as undefined.
const val = item.body[key];return `${encodeURIComponent(key)}=${encodeURIComponent(typeof val === 'object' ? JSON.stringify(val) : val)}`;}).join('&') });}return item;});return _axios2.default.post('https://graph.facebook.com/', { access_token: customAccessToken || this._accessToken, batch: bodyEncodedbatch }).then(res => res.data);};this.createMessageCreative = (messages = [], { access_token: customAccessToken } = {}) => this._axios.post(`/me/message_creatives?access_token=${customAccessToken || this._accessToken}`, { messages }).then(res => res.data, handleError);this.sendBroadcastMessage = (messageCreativeId, options = {}) => this._axios.post(`/me/broadcast_messages?access_token=${options.access_token || this._accessToken}`, _extends({ message_creative_id: messageCreativeId }, options)).then(res => res.data, handleError);this.sendSponsoredMessage = (adAccountId, message) => this._axios.post(`/act_${adAccountId}/sponsored_message_ads?access_token=${this._accessToken}`, message).then(res => res.data, handleError);this.createLabel = (name, { access_token: customAccessToken } = {}) => this._axios.post(`/me/custom_labels?access_token=${customAccessToken || this._accessToken}`, { name }).then(res => res.data, handleError);this.associateLabel = (userId, labelId, { access_token: customAccessToken } = {}) => this._axios.post(`/${labelId}/label?access_token=${customAccessToken || this._accessToken}`, { user: userId }).then(res => res.data, handleError);this.dissociateLabel = (userId, labelId, { access_token: customAccessToken } = {}) => this._axios.delete(`/${labelId}/label?access_token=${customAccessToken || this._accessToken}`, { data: { user: userId } }).then(res => res.data, handleError);this.getAssociatedLabels = (userId, { access_token: customAccessToken } = {}) => this._axios.get(`/${userId}/custom_labels?access_token=${customAccessToken || this._accessToken}`).then(res => res.data, handleError);this.getLabelDetails = (labelId, options = {}) => {const fields = options.fields ? options.fields.join(',') : 'name';return this._axios.get(`/${labelId}?fields=${fields}&access_token=${options.access_token || this._accessToken}`).then(res => res.data, handleError);};this.getLabelList = (options = {}) => {const fields = options.fields ? options.fields.join(',') : 'name';return this._axios.get(`/me/custom_labels?fields=${fields}&access_token=${options.access_token || this._accessToken}`).then(res => res.data, handleError);};this.deleteLabel = (labelId, { access_token: customAccessToken } = {}) => this._axios.delete(`/${labelId}?access_token=${customAccessToken || this._accessToken}`).then(res => res.data, handleError);this.startReachEstimation = (customLabelId, { access_token: customAccessToken } = {}) => this._axios.post(`/broadcast_reach_estimations?access_token=${customAccessToken || this._accessToken}`, { custom_label_id: customLabelId }).then(res => res.data, handleError);this.getReachEstimate = (reachEstimationId, { access_token: customAccessToken } = {}) => this._axios.post(`/${reachEstimationId}?access_token=${customAccessToken || this._accessToken}`).then(res => res.data, handleError);this.getBroadcastMessagesSent = (broadcastId, { access_token: customAccessToken } = {}) => this._axios.post(`/${broadcastId}/insights/messages_sent?access_token=${customAccessToken || this._accessToken}`).then(res => res.data.data, handleError);this.uploadAttachment = (type, attachment, options = {}) => {const args = [];if (typeof attachment === 'string') {args.push({ message: { attachment: { type, payload: { url: attachment, is_reusable: true } } } });} else {const form = new _formData2.default();form.append('message', JSON.stringify({ attachment: { type, payload: { is_reusable: true } } }));form.append('filedata', attachment, options);args.push(form, { headers: form.getHeaders() });}return this._axios.post(`/me/message_attachments?access_token=${options.access_token || this._accessToken}`, ...args).then(res => res.data, handleError);};this.uploadAudio = (attachment, options) => this.uploadAttachment('audio', attachment, options);this.uploadImage = (attachment, options) => this.uploadAttachment('image', attachment, options);this.uploadVideo = (attachment, options) => this.uploadAttachment('video', attachment, options);this.uploadFile = (attachment, options) => this.uploadAttachment('file', attachment, options);this.generateMessengerCode = (options = {}) => this._axios.post(`/me/messenger_codes?access_token=${options.access_token || this._accessToken}`, _extends({ type: 'standard' }, options)).then(res => res.data, handleError);this.passThreadControl = (recipientId, targetAppId, metadata, { access_token: customAccessToken } = {}) => this._axios.post(`/me/pass_thread_control?access_token=${customAccessToken || this._accessToken}`, { recipient: { id: recipientId }, target_app_id: targetAppId, metadata }).then(res => res.data, handleError);this.passThreadControlToPageInbox = (recipientId, metadata, options = {}) => this.passThreadControl(recipientId, 263902037430900, metadata, options);this.takeThreadControl = (recipientId, metadata, { access_token: customAccessToken } = {}) => this._axios.post(`/me/take_thread_control?access_token=${customAccessToken || this._accessToken}`, { recipient: { id: recipientId }, metadata }).then(res => res.data, handleError);this.getSecondaryReceivers = ({ access_token: customAccessToken } = {}) => this._axios.get(`/me/secondary_receivers?fields=id,name&access_token=${customAccessToken || this._accessToken}`).then(res => res.data.data, handleError);this.getInsights = (metrics, options = {}) => this._axios.get(`/me/insights/?${_querystring2.default.stringify(_extends({ metric: metrics.join(','), access_token: options.access_token || this._accessToken }, options))}`).then(res => res.data.data, handleError);this.getDailyUniqueActiveThreadCounts = (options = {}) => this.getInsights(['page_messages_active_threads_unique'], options);this.getBlockedConversations = (options = {}) => this.getInsights(['page_messages_blocked_conversations_unique'], options);this.getReportedConversations = (options = {}) => this.getInsights(['page_messages_reported_conversations_unique'], options);this.getReportedConversationsByReportType = (options = {}) => this.getInsights(['page_messages_blocked_conversations_unique'], options);this.getDailyUniqueConversationCounts = () => {(0, _warning2.default)(false, 'page_messages_feedback_by_action_unique is deprecated as of November 7, 2017.\nThis metric will be removed in Graph API v2.12.');return this.getInsights(['page_messages_feedback_by_action_unique']);};this.setNLPConfigs = (config = {}, { access_token: customAccessToken } = {}) => this._axios.post(`/me/nlp_configs?${_querystring2.default.stringify(config)}`, { access_token: customAccessToken || this._accessToken }).then(res => res.data, handleError);this.enableNLP = (options = {}) => this.setNLPConfigs({ nlp_enabled: true }, options);this.disableNLP = (options = {}) => this.setNLPConfigs({ nlp_enabled: false }, options);this.logCustomEvents = ({ appId, pageId, userId, events, access_token: customAccessToken }) =>
this._axios.
post(`/${appId}/activities?access_token=${this._accessToken}`, {
post(
`/${appId}/activities?access_token=${customAccessToken ||
this._accessToken}`,
{
event: 'CUSTOM_APP_EVENTS',

@@ -1434,2 +1647,3 @@ custom_events: JSON.stringify(events),

then(res => res.data, handleError);};

2

package.json
{
"name": "messaging-api-messenger",
"description": "Messaging API client for Messenger",
"version": "0.5.13",
"version": "0.5.14",
"engines": {

@@ -6,0 +6,0 @@ "node": ">=6"

@@ -139,5 +139,7 @@ /* @flow */

*/
getPageInfo = (): Promise<PageInfo> =>
getPageInfo = (
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<PageInfo> =>
this._axios
.get(`/me?access_token=${this._accessToken}`)
.get(`/me?access_token=${customAccessToken || this._accessToken}`)
.then(res => res.data, handleError);

@@ -151,5 +153,8 @@

*/
getUserProfile = (userId: string): Promise<User> =>
getUserProfile = (
userId: string,
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<User> =>
this._axios
.get(`/${userId}?access_token=${this._accessToken}`)
.get(`/${userId}?access_token=${customAccessToken || this._accessToken}`)
.then(res => res.data, handleError);

@@ -163,8 +168,10 @@

getMessengerProfile = (
fields: Array<string>
fields: Array<string>,
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<MessengerProfileResponse> =>
this._axios
.get(
`/me/messenger_profile?fields=${fields.join(',')}&access_token=${this
._accessToken}`
`/me/messenger_profile?fields=${fields.join(
','
)}&access_token=${customAccessToken || this._accessToken}`
)

@@ -174,17 +181,27 @@ .then(res => res.data.data, handleError);

setMessengerProfile = (
profile: MessengerProfile
profile: MessengerProfile,
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<MutationSuccessResponse> =>
this._axios
.post(`/me/messenger_profile?access_token=${this._accessToken}`, profile)
.post(
`/me/messenger_profile?access_token=${customAccessToken ||
this._accessToken}`,
profile
)
.then(res => res.data, handleError);
deleteMessengerProfile = (
fields: Array<string>
fields: Array<string>,
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<MutationSuccessResponse> =>
this._axios
.delete(`/me/messenger_profile?access_token=${this._accessToken}`, {
data: {
fields,
},
})
.delete(
`/me/messenger_profile?access_token=${customAccessToken ||
this._accessToken}`,
{
data: {
fields,
},
}
)
.then(res => res.data, handleError);

@@ -197,4 +214,6 @@

*/
getGetStarted = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['get_started']).then(
getGetStarted = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['get_started'], options).then(
res => (res[0] ? res[0].get_started : null)

@@ -226,4 +245,6 @@ );

deleteGetStarted = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['get_started']);
deleteGetStarted = (
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['get_started'], options);

@@ -243,4 +264,6 @@ deleteGetStartedButton = (): Promise<MutationSuccessResponse> => {

*/
getPersistentMenu = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['persistent_menu']).then(
getPersistentMenu = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['persistent_menu'], options).then(
res => (res[0] ? res[0].persistent_menu : null)

@@ -251,25 +274,36 @@ );

menuItems: Array<MenuItem> | PersistentMenu,
{ composerInputDisabled = false }: { composerInputDisabled: boolean } = {}
{
composer_input_disabled: composerInputDisabled = false,
...options
}: { composer_input_disabled: boolean } = {}
): Promise<MutationSuccessResponse> => {
// menuItems is in type PersistentMenu
if (menuItems.some((item: Object) => item.locale === 'default')) {
return this.setMessengerProfile({
persistent_menu: ((menuItems: any): PersistentMenu),
});
return this.setMessengerProfile(
{
persistent_menu: ((menuItems: any): PersistentMenu),
},
options
);
}
// menuItems is in type Array<MenuItem>
return this.setMessengerProfile({
persistent_menu: [
{
locale: 'default',
composer_input_disabled: composerInputDisabled,
call_to_actions: ((menuItems: any): Array<MenuItem>),
},
],
});
return this.setMessengerProfile(
{
persistent_menu: [
{
locale: 'default',
composer_input_disabled: composerInputDisabled,
call_to_actions: ((menuItems: any): Array<MenuItem>),
},
],
},
options
);
};
deletePersistentMenu = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['persistent_menu']);
deletePersistentMenu = (
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['persistent_menu'], options);

@@ -281,4 +315,6 @@ /**

*/
getGreeting = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['greeting']).then(
getGreeting = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['greeting'], options).then(
res => (res[0] ? res[0].greeting : null)

@@ -296,18 +332,25 @@ );

setGreeting = (
greeting: string | Array<GreetingConfig>
greeting: string | Array<GreetingConfig>,
options?: Object = {}
): Promise<MutationSuccessResponse> => {
if (typeof greeting === 'string') {
return this.setMessengerProfile({
greeting: [
{
locale: 'default',
text: greeting,
},
],
});
return this.setMessengerProfile(
{
greeting: [
{
locale: 'default',
text: greeting,
},
],
},
options
);
}
return this.setMessengerProfile({
greeting,
});
return this.setMessengerProfile(
{
greeting,
},
options
);
};

@@ -325,4 +368,4 @@

deleteGreeting = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['greeting']);
deleteGreeting = (options?: Object = {}): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['greeting'], options);

@@ -373,4 +416,6 @@ deleteGreetingText = (): Promise<MutationSuccessResponse> => {

*/
getWhitelistedDomains = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['whitelisted_domains']).then(
getWhitelistedDomains = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['whitelisted_domains'], options).then(
res => (res[0] ? res[0].whitelisted_domains : null)

@@ -380,10 +425,16 @@ );

setWhitelistedDomains = (
domains: Array<string>
domains: Array<string>,
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
whitelisted_domains: domains,
});
this.setMessengerProfile(
{
whitelisted_domains: domains,
},
options
);
deleteWhitelistedDomains = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['whitelisted_domains']);
deleteWhitelistedDomains = (
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['whitelisted_domains'], options);

@@ -395,14 +446,24 @@ /**

*/
getAccountLinkingURL = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['account_linking_url']).then(
getAccountLinkingURL = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['account_linking_url'], options).then(
res => (res[0] ? res[0] : null)
);
setAccountLinkingURL = (url: string): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
account_linking_url: url,
});
setAccountLinkingURL = (
url: string,
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile(
{
account_linking_url: url,
},
options
);
deleteAccountLinkingURL = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['account_linking_url']);
deleteAccountLinkingURL = (
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['account_linking_url'], options);

@@ -414,4 +475,6 @@ /**

*/
getPaymentSettings = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['payment_settings']).then(
getPaymentSettings = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['payment_settings'], options).then(
res => (res[0] ? res[0] : null)

@@ -421,28 +484,44 @@ );

setPaymentPrivacyPolicyURL = (
url: string
url: string,
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
payment_settings: {
privacy_url: url,
this.setMessengerProfile(
{
payment_settings: {
privacy_url: url,
},
},
});
options
);
setPaymentPublicKey = (key: string): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
payment_settings: {
public_key: key,
setPaymentPublicKey = (
key: string,
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile(
{
payment_settings: {
public_key: key,
},
},
});
options
);
setPaymentTestUsers = (
users: Array<string>
users: Array<string>,
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
payment_settings: {
test_users: users,
this.setMessengerProfile(
{
payment_settings: {
test_users: users,
},
},
});
options
);
deletePaymentSettings = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['payment_settings']);
deletePaymentSettings = (
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['payment_settings'], options);

@@ -454,4 +533,6 @@ /**

*/
getTargetAudience = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['target_audience']).then(
getTargetAudience = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['target_audience'], options).then(
res => (res[0] ? res[0] : null)

@@ -463,16 +544,22 @@ );

whitelist: ?Array<string> = [],
blacklist: ?Array<string> = []
blacklist: ?Array<string> = [],
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
target_audience: {
audience_type: type,
countries: {
whitelist,
blacklist,
this.setMessengerProfile(
{
target_audience: {
audience_type: type,
countries: {
whitelist,
blacklist,
},
},
},
});
options
);
deleteTargetAudience = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['target_audience']);
deleteTargetAudience = (
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['target_audience'], options);

@@ -484,4 +571,6 @@ /**

*/
getHomeURL = (): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['home_url']).then(
getHomeURL = (
options?: Object = {}
): Promise<MessengerProfileResponse | null> =>
this.getMessengerProfile(['home_url'], options).then(
res => (res[0] ? res[0] : null)

@@ -506,12 +595,16 @@ );

in_test: boolean,
}
},
options?: Object = {}
): Promise<MutationSuccessResponse> =>
this.setMessengerProfile({
home_url: {
url,
webview_height_ratio: 'tall',
in_test,
webview_share_button,
this.setMessengerProfile(
{
home_url: {
url,
webview_height_ratio: 'tall',
in_test,
webview_share_button,
},
},
});
options
);

@@ -541,4 +634,4 @@ setChatExtensionHomeURL = (

deleteHomeURL = (): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['home_url']);
deleteHomeURL = (options?: Object = {}): Promise<MutationSuccessResponse> =>
this.deleteMessengerProfile(['home_url'], options);

@@ -558,5 +651,10 @@ deleteChatExtensionHomeURL = (): Promise<MutationSuccessResponse> => {

*/
getMessageTags = (): Promise<MessageTagResponse> =>
getMessageTags = (
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<MessageTagResponse> =>
this._axios
.get(`/page_message_tags?access_token=${this._accessToken}`)
.get(
`/page_message_tags?access_token=${customAccessToken ||
this._accessToken}`
)
.then(res => res.data.data, handleError);

@@ -570,6 +668,12 @@

// TODO: body flowtype
sendRawBody = (body: Object): Promise<SendMessageSucessResponse> =>
this._axios
.post(`/me/messages?access_token=${this._accessToken}`, body)
sendRawBody = (body: Object): Promise<SendMessageSucessResponse> => {
const { access_token: customAccessToken } = body;
return this._axios
.post(
`/me/messages?access_token=${customAccessToken || this._accessToken}`,
body
)
.then(res => res.data, handleError);
};

@@ -642,5 +746,10 @@ sendMessage = (

return this._axios
.post(`/me/messages?access_token=${this._accessToken}`, form, {
headers: form.getHeaders(),
})
.post(
`/me/messages?access_token=${options.access_token ||
this._accessToken}`,
form,
{
headers: form.getHeaders(),
}
)
.then(res => res.data, handleError);

@@ -979,3 +1088,4 @@ };

idOrRecipient: UserID | Recipient,
action: SenderAction
action: SenderAction,
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<SendSenderActionResponse> => {

@@ -991,2 +1101,3 @@ const recipient =

sender_action: action,
access_token: customAccessToken,
});

@@ -996,15 +1107,18 @@ };

markSeen = (
recipient: UserID | Recipient
recipient: UserID | Recipient,
options?: Object = {}
): Promise<SendSenderActionResponse> =>
this.sendSenderAction(recipient, 'mark_seen');
this.sendSenderAction(recipient, 'mark_seen', options);
typingOn = (
recipient: UserID | Recipient
recipient: UserID | Recipient,
options?: Object = {}
): Promise<SendSenderActionResponse> =>
this.sendSenderAction(recipient, 'typing_on');
this.sendSenderAction(recipient, 'typing_on', options);
typingOff = (
recipient: UserID | Recipient
recipient: UserID | Recipient,
options?: Object = {}
): Promise<SendSenderActionResponse> =>
this.sendSenderAction(recipient, 'typing_off');
this.sendSenderAction(recipient, 'typing_off', options);

@@ -1017,3 +1131,4 @@ /**

sendBatch = (
batch: Array<BatchItem>
batch: Array<BatchItem>,
{ access_token: customAccessToken }: { access_token?: string } = {}
): Promise<Array<SendMessageSucessResponse>> => {

@@ -1044,3 +1159,3 @@ invariant(

.post('https://graph.facebook.com/', {
access_token: this._accessToken,
access_token: customAccessToken || this._accessToken,
batch: bodyEncodedbatch,

@@ -1062,7 +1177,14 @@ })

*/
createMessageCreative = (messages: Array<Object> = []) =>
createMessageCreative = (
messages: Array<Object> = [],
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(`/me/message_creatives?access_token=${this._accessToken}`, {
messages,
})
.post(
`/me/message_creatives?access_token=${customAccessToken ||
this._accessToken}`,
{
messages,
}
)
.then(res => res.data, handleError);

@@ -1077,6 +1199,10 @@

this._axios
.post(`/me/broadcast_messages?access_token=${this._accessToken}`, {
message_creative_id: messageCreativeId,
...options,
})
.post(
`/me/broadcast_messages?access_token=${options.access_token ||
this._accessToken}`,
{
message_creative_id: messageCreativeId,
...options,
}
)
.then(res => res.data, handleError);

@@ -1109,7 +1235,14 @@

*/
createLabel = (name: string) =>
createLabel = (
name: string,
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(`/me/custom_labels?access_token=${this._accessToken}`, {
name,
})
.post(
`/me/custom_labels?access_token=${customAccessToken ||
this._accessToken}`,
{
name,
}
)
.then(res => res.data, handleError);

@@ -1122,7 +1255,15 @@

*/
associateLabel = (userId: UserID, labelId: number) =>
associateLabel = (
userId: UserID,
labelId: number,
{ access_token: customAccessToken }: { access_token: ?string } = {}
) =>
this._axios
.post(`/${labelId}/label?access_token=${this._accessToken}`, {
user: userId,
})
.post(
`/${labelId}/label?access_token=${customAccessToken ||
this._accessToken}`,
{
user: userId,
}
)
.then(res => res.data, handleError);

@@ -1135,7 +1276,15 @@

*/
dissociateLabel = (userId: UserID, labelId: number) =>
dissociateLabel = (
userId: UserID,
labelId: number,
{ access_token: customAccessToken }: { access_token: ?string } = {}
) =>
this._axios
.delete(`/${labelId}/label?access_token=${this._accessToken}`, {
data: { user: userId },
})
.delete(
`/${labelId}/label?access_token=${customAccessToken ||
this._accessToken}`,
{
data: { user: userId },
}
)
.then(res => res.data, handleError);

@@ -1148,5 +1297,11 @@

*/
getAssociatedLabels = (userId: UserID) =>
getAssociatedLabels = (
userId: UserID,
{ access_token: customAccessToken }: { access_token: ?string } = {}
) =>
this._axios
.get(`/${userId}/custom_labels?access_token=${this._accessToken}`)
.get(
`/${userId}/custom_labels?access_token=${customAccessToken ||
this._accessToken}`
)
.then(res => res.data, handleError);

@@ -1162,3 +1317,6 @@

return this._axios
.get(`/${labelId}?fields=${fields}&access_token=${this._accessToken}`)
.get(
`/${labelId}?fields=${fields}&access_token=${options.access_token ||
this._accessToken}`
)
.then(res => res.data, handleError);

@@ -1176,3 +1334,4 @@ };

.get(
`/me/custom_labels?fields=${fields}&access_token=${this._accessToken}`
`/me/custom_labels?fields=${fields}&access_token=${options.access_token ||
this._accessToken}`
)

@@ -1187,5 +1346,10 @@ .then(res => res.data, handleError);

*/
deleteLabel = (labelId: number) =>
deleteLabel = (
labelId: number,
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.delete(`/${labelId}?access_token=${this._accessToken}`)
.delete(
`/${labelId}?access_token=${customAccessToken || this._accessToken}`
)
.then(res => res.data, handleError);

@@ -1198,7 +1362,14 @@

*/
startReachEstimation = (customLabelId: number) =>
startReachEstimation = (
customLabelId: number,
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(`/broadcast_reach_estimations?access_token=${this._accessToken}`, {
custom_label_id: customLabelId,
})
.post(
`/broadcast_reach_estimations?access_token=${customAccessToken ||
this._accessToken}`,
{
custom_label_id: customLabelId,
}
)
.then(res => res.data, handleError);

@@ -1211,5 +1382,11 @@

*/
getReachEstimate = (reachEstimationId: number) =>
getReachEstimate = (
reachEstimationId: number,
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(`/${reachEstimationId}?access_token=${this._accessToken}`)
.post(
`/${reachEstimationId}?access_token=${customAccessToken ||
this._accessToken}`
)
.then(res => res.data, handleError);

@@ -1223,7 +1400,10 @@

*/
getBroadcastMessagesSent = (broadcastId: number) =>
getBroadcastMessagesSent = (
broadcastId: number,
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(
`/${broadcastId}/insights/messages_sent?access_token=${this
._accessToken}`
`/${broadcastId}/insights/messages_sent?access_token=${customAccessToken ||
this._accessToken}`
)

@@ -1240,3 +1420,3 @@ .then(res => res.data.data, handleError);

attachment: string | FileData,
options?: UploadOption
options?: UploadOption = {}
) => {

@@ -1281,3 +1461,4 @@ const args = [];

.post(
`/me/message_attachments?access_token=${this._accessToken}`,
`/me/message_attachments?access_token=${options.access_token ||
this._accessToken}`,
...args

@@ -1304,6 +1485,10 @@ )

this._axios
.post(`/me/messenger_codes?access_token=${this._accessToken}`, {
type: 'standard',
...options,
})
.post(
`/me/messenger_codes?access_token=${options.access_token ||
this._accessToken}`,
{
type: 'standard',
...options,
}
)
.then(res => res.data, handleError);

@@ -1325,14 +1510,22 @@

targetAppId: number,
metadata?: string
metadata?: string,
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(`/me/pass_thread_control?access_token=${this._accessToken}`, {
recipient: { id: recipientId },
target_app_id: targetAppId,
metadata,
})
.post(
`/me/pass_thread_control?access_token=${customAccessToken ||
this._accessToken}`,
{
recipient: { id: recipientId },
target_app_id: targetAppId,
metadata,
}
)
.then(res => res.data, handleError);
passThreadControlToPageInbox = (recipientId: string, metadata?: string) =>
this.passThreadControl(recipientId, 263902037430900, metadata);
passThreadControlToPageInbox = (
recipientId: string,
metadata?: string,
options?: Object = {}
) => this.passThreadControl(recipientId, 263902037430900, metadata, options);

@@ -1344,8 +1537,16 @@ /**

*/
takeThreadControl = (recipientId: string, metadata?: string) =>
takeThreadControl = (
recipientId: string,
metadata?: string,
{ access_token: customAccessToken }: { access_token: ?string } = {}
) =>
this._axios
.post(`/me/take_thread_control?access_token=${this._accessToken}`, {
recipient: { id: recipientId },
metadata,
})
.post(
`/me/take_thread_control?access_token=${customAccessToken ||
this._accessToken}`,
{
recipient: { id: recipientId },
metadata,
}
)
.then(res => res.data, handleError);

@@ -1358,7 +1559,9 @@

*/
getSecondaryReceivers = () =>
getSecondaryReceivers = (
{ access_token: customAccessToken }: { access_token: ?string } = {}
) =>
this._axios
.get(
`/me/secondary_receivers?fields=id,name&access_token=${this
._accessToken}`
`/me/secondary_receivers?fields=id,name&access_token=${customAccessToken ||
this._accessToken}`
)

@@ -1380,3 +1583,3 @@ .then(res => res.data.data, handleError);

metric: metrics.join(','),
access_token: this._accessToken,
access_token: options.access_token || this._accessToken,
...options,

@@ -1387,13 +1590,13 @@ })}`

getDailyUniqueActiveThreadCounts = () =>
this.getInsights(['page_messages_active_threads_unique']);
getDailyUniqueActiveThreadCounts = (options?: Object = {}) =>
this.getInsights(['page_messages_active_threads_unique'], options);
getBlockedConversations = () =>
this.getInsights(['page_messages_blocked_conversations_unique']);
getBlockedConversations = (options?: Object = {}) =>
this.getInsights(['page_messages_blocked_conversations_unique'], options);
getReportedConversations = () =>
this.getInsights(['page_messages_reported_conversations_unique']);
getReportedConversations = (options?: Object = {}) =>
this.getInsights(['page_messages_reported_conversations_unique'], options);
getReportedConversationsByReportType = () =>
this.getInsights(['page_messages_blocked_conversations_unique']);
getReportedConversationsByReportType = (options?: Object = {}) =>
this.getInsights(['page_messages_blocked_conversations_unique'], options);

@@ -1413,11 +1616,16 @@ getDailyUniqueConversationCounts = () => {

*/
setNLPConfigs = (config: MessengerNLPConfig = {}) =>
setNLPConfigs = (
config: MessengerNLPConfig = {},
{ access_token: customAccessToken }: { access_token?: string } = {}
) =>
this._axios
.post(`/me/nlp_configs?${querystring.stringify(config)}`, {
access_token: this._accessToken,
access_token: customAccessToken || this._accessToken,
})
.then(res => res.data, handleError);
enableNLP = () => this.setNLPConfigs({ nlp_enabled: true });
disableNLP = () => this.setNLPConfigs({ nlp_enabled: false });
enableNLP = (options?: Object = {}) =>
this.setNLPConfigs({ nlp_enabled: true }, options);
disableNLP = (options?: Object = {}) =>
this.setNLPConfigs({ nlp_enabled: false }, options);

@@ -1434,2 +1642,3 @@ /**

events,
access_token: customAccessToken,
}: {

@@ -1440,14 +1649,19 @@ appId: number,

events: Array<Object>,
access_token?: string,
}) =>
this._axios
.post(`/${appId}/activities?access_token=${this._accessToken}`, {
event: 'CUSTOM_APP_EVENTS',
custom_events: JSON.stringify(events),
advertiser_tracking_enabled: 0,
application_tracking_enabled: 0,
extinfo: JSON.stringify(['mb1']),
page_id: pageId,
page_scoped_user_id: userId,
})
.post(
`/${appId}/activities?access_token=${customAccessToken ||
this._accessToken}`,
{
event: 'CUSTOM_APP_EVENTS',
custom_events: JSON.stringify(events),
advertiser_tracking_enabled: 0,
application_tracking_enabled: 0,
extinfo: JSON.stringify(['mb1']),
page_id: pageId,
page_scoped_user_id: userId,
}
)
.then(res => res.data, handleError);
}

@@ -87,2 +87,3 @@ /* @flow */

quick_replies?: Array<QuickReply>,
access_token?: string,
};

@@ -92,2 +93,3 @@

filename?: string,
access_token?: string,
};

@@ -94,0 +96,0 @@

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