messaging-api-messenger
Advanced tools
Comparing version 0.5.5 to 0.5.7
@@ -22,3 +22,3 @@ '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;}; | ||
message, | ||
options) | ||
options = {}) | ||
{ | ||
@@ -31,3 +31,10 @@ const recipient = | ||
idOrRecipient; | ||
let messageType = 'UPDATE'; | ||
if (options.messaging_type) { | ||
messageType = options.messaging_type; | ||
} else if (options.tag) { | ||
messageType = 'MESSAGE_TAG'; | ||
} | ||
return createRequest(_extends({ | ||
messaging_type: messageType, | ||
recipient, | ||
@@ -34,0 +41,0 @@ message }, |
@@ -54,2 +54,5 @@ '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;}; | ||
function extractVersion(version) { | ||
@@ -78,3 +81,3 @@ if (version.startsWith('v')) { | ||
constructor(accessToken, version = '2.10') {_initialiseProps.call(this); | ||
constructor(accessToken, version = '2.11') {_initialiseProps.call(this); | ||
this._accessToken = accessToken; | ||
@@ -119,3 +122,3 @@ (0, _invariant2.default)(typeof version === 'string', 'Type of `version` must be string.'); | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api | ||
*/ | ||
@@ -153,3 +156,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/get-started-button | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/get-started-button | ||
*/ | ||
@@ -198,3 +201,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/persistent-menu | ||
*/ | ||
@@ -235,3 +238,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/greeting-text | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/greeting | ||
*/ | ||
@@ -294,3 +297,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/domain-whitelisting | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
*/ | ||
@@ -326,3 +329,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/domain-whitelisting | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
*/ | ||
@@ -347,3 +350,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/account-linking-url | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/account-linking-url | ||
*/ | ||
@@ -366,3 +369,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/payment-settings | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/payment-settings | ||
*/ | ||
@@ -405,3 +408,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/target-audience | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/target-audience | ||
*/ | ||
@@ -434,3 +437,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/home-url | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/home-url | ||
*/ | ||
@@ -508,3 +511,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/tags/ | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags | ||
*/ | ||
@@ -519,3 +522,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference | ||
* https://developers.facebook.com/docs/messenger-platform/reference/send-api | ||
*/ | ||
@@ -568,6 +571,21 @@ // TODO: body flowtype | ||
/** | ||
* Content Types | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/contenttypes | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages#content_types | ||
*/ | ||
@@ -679,6 +697,11 @@ | ||
/** | ||
* Templates | ||
* Message Templates | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/templates | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/templates | ||
*/ | ||
@@ -699,3 +722,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/button-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/button | ||
@@ -712,3 +735,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic | ||
@@ -732,3 +755,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/list-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/list | ||
@@ -747,3 +770,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/open-graph-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/open-graph | ||
@@ -758,3 +781,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/receipt-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/receipt | ||
@@ -769,3 +792,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-boardingpass-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/media | ||
@@ -780,3 +803,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-checkin-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#boarding_pass | ||
@@ -791,3 +814,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-itinerary-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#check_in | ||
@@ -802,3 +825,3 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-update-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#itinerary | ||
@@ -813,6 +836,16 @@ | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#update | ||
/** | ||
* Quick Replies | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies | ||
*/ | ||
@@ -855,3 +888,3 @@ | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/sender-actions | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions | ||
*/ | ||
@@ -928,7 +961,12 @@ | ||
/** | ||
* Upload API | ||
* Broadcast API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/attachment-upload | ||
* https://developers.facebook.com/docs/messenger-platform/reference/broadcast-api | ||
*/ | ||
/** | ||
* Create Message Creative | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/sponsored-messages#creative | ||
*/ | ||
@@ -941,2 +979,7 @@ | ||
/** | ||
* Send Broadcast Message | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages#sending | ||
*/ | ||
@@ -950,2 +993,7 @@ | ||
/** | ||
* Send Sponsored Message | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/sponsored-messages#message | ||
*/ | ||
@@ -955,8 +1003,18 @@ | ||
/** | ||
* Messenger Code API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-code | ||
*/ | ||
* Label API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts | ||
*/ | ||
/** | ||
* Create Label | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#create_label | ||
*/ | ||
@@ -970,12 +1028,18 @@ | ||
/** | ||
* Handover Protocol API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/handover-protocol | ||
*/ | ||
* Associating a Label to a PSID | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#associate_label | ||
*/ | ||
/** | ||
* Pass Thread Control | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/pass-thread-control | ||
*/ | ||
* Removing a Label From a PSID | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#associate_label | ||
*/ | ||
@@ -988,2 +1052,7 @@ | ||
/** | ||
* Retrieving Labels Associated with a PSID | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#get_all_labels | ||
*/ | ||
@@ -994,2 +1063,7 @@ | ||
/** | ||
* Retrieving Label Details | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#get_label_details | ||
*/ | ||
@@ -999,7 +1073,10 @@ | ||
/** | ||
* Take Thread Control | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/take-thread-control | ||
*/ | ||
* Retrieving a List of All Labels | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#get_all_labels | ||
*/ | ||
@@ -1013,7 +1090,8 @@ | ||
/** | ||
* Secondary Receivers List | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/secondary-receivers | ||
*/ | ||
* Deleting a Label | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#delete_label | ||
*/ | ||
@@ -1024,10 +1102,19 @@ | ||
/** | ||
* Starting a Reach Estimation | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/estimate-reach#start | ||
*/ | ||
/** | ||
* Page Messaging Insights API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/insights/page-messaging | ||
*/ | ||
* Retrieving a Reach Estimate | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/estimate-reach#get | ||
*/ | ||
@@ -1038,2 +1125,8 @@ | ||
/** | ||
* Broadcast Metrics | ||
* | ||
* Once a broadcast has been delivered, you can find out the total number of people it reached. | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/#metrics | ||
*/ | ||
@@ -1047,26 +1140,173 @@ | ||
/** | ||
* Upload API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api | ||
*/ | ||
/** | ||
* Built-in NLP API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/built-in-nlp | ||
*/}exports.default = MessengerClient;MessengerClient.connect = (accessToken, version = 'v2.10') => 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.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 | ||
* Messenger Code API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/discovery/messenger-codes | ||
*/ | ||
/** | ||
* Handover Protocol API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/handover-protocol | ||
*/ | ||
/** | ||
* Pass Thread Control | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/pass-thread-control | ||
*/ | ||
/** | ||
* Take Thread Control | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/take-thread-control | ||
*/ | ||
/** | ||
* Secondary Receivers List | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/secondary-receivers | ||
*/ | ||
/** | ||
* Page Messaging Insights API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messaging-insights-api | ||
*/ | ||
/** | ||
* Built-in NLP API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/built-in-nlp | ||
*/ | ||
/** | ||
* 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.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_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, 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;return this.sendRawBody(_extends({ recipient, message }, options));};this.sendMessageFormData = (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._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) => this.sendMessageFormData(recipient, { attachment }, filedata);this.sendText = (recipient, text, options) => this.sendMessage(recipient, { text }, options);this.sendAudio = (recipient, audio) => {const attachment = { type: 'audio', payload: {} };if (typeof audio === 'string') {attachment.payload.url = audio;return this.sendAttachment(recipient, attachment);} else if (audio && (0, _isPlainObject2.default)(audio)) {attachment.payload = audio;return this.sendAttachment(recipient, attachment);} // $FlowFixMe | ||
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);} else if (image && (0, _isPlainObject2.default)(image)) {attachment.payload = image;return this.sendAttachment(recipient, attachment);} // $FlowFixMe | ||
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);} else if (video && (0, _isPlainObject2.default)(video)) {attachment.payload = video;return this.sendAttachment(recipient, attachment);} // $FlowFixMe | ||
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);} else if (file && (0, _isPlainObject2.default)(file)) {attachment.payload = file;return this.sendAttachment(recipient, attachment);} // $FlowFixMe | ||
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, 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' });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 | ||
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_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, 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';}return this.sendRawBody(_extends({ messaging_type: messageType, recipient, message }, options));};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';}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 | ||
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) => this.sendTemplate(recipient, { template_type: 'button', text, buttons });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' });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.sendMediaTemplate = (recipient, elements) => this.sendTemplate(recipient, { template_type: 'media', elements });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.sendMessage(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.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.uploadAttachment = (type, url) => this._axios.post(`/me/message_attachments?access_token=${this._accessToken}`, { message: { attachment: { type, payload: { url, is_reusable: true } } } }).then(res => res.data, handleError);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._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.getDailyUniqueActiveThreadCounts = () => this._axios.get(`/me/insights/page_messages_active_threads_unique&access_token=${this._accessToken}`).then(res => res.data.data, handleError);this.getDailyUniqueConversationCounts = () => this._axios.get(`/me/insights/page_messages_feedback_by_action_unique&access_token=${this._accessToken}`).then(res => res.data.data, handleError);this.setNLPConfigs = (config = {}) => {const query = { nlp_enabled: config.nlp_enabled ? 'true' : 'false' };if (config.custom_token) {query.custom_token = config.custom_token;}return this._axios.post(`/me/nlp_configs?${_querystring2.default.stringify(query)}`, { | ||
access_token: this._accessToken }). | ||
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, url) => this._axios.post(`/me/message_attachments?access_token=${this._accessToken}`, { message: { attachment: { type, payload: { url, is_reusable: true } } } }).then(res => res.data, handleError);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._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 }) => | ||
then(res => res.data, handleError); | ||
};this. | ||
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 }). | ||
enableNLP = () => this.setNLPConfigs({ nlp_enabled: true });this. | ||
disableNLP = () => this.setNLPConfigs({ nlp_enabled: false });}; | ||
then(res => res.data, handleError);}; |
{ | ||
"name": "messaging-api-messenger", | ||
"description": "Messaging API client for Messenger", | ||
"version": "0.5.5", | ||
"version": "0.5.7", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": ">=6" |
@@ -9,2 +9,3 @@ import Messenger from '../Messenger'; | ||
Messenger.createRequest({ | ||
messaging_type: 'UPDATE', | ||
message: { | ||
@@ -21,2 +22,3 @@ text: 'Hello', | ||
body: { | ||
messaging_type: 'UPDATE', | ||
message: { | ||
@@ -39,2 +41,3 @@ text: 'Hello', | ||
body: { | ||
messaging_type: 'UPDATE', | ||
message: { | ||
@@ -50,2 +53,24 @@ text: 'Hello', | ||
it('should create send text with RESPONSE type', () => { | ||
expect( | ||
Messenger.createMessage( | ||
RECIPIENT_ID, | ||
{ text: 'Hello' }, | ||
{ messaging_type: 'RESPONSE' } | ||
) | ||
).toEqual({ | ||
method: 'POST', | ||
relative_url: 'me/messages', | ||
body: { | ||
messaging_type: 'RESPONSE', | ||
message: { | ||
text: 'Hello', | ||
}, | ||
recipient: { | ||
id: RECIPIENT_ID, | ||
}, | ||
}, | ||
}); | ||
}); | ||
it('can create request with phone_number', () => { | ||
@@ -64,2 +89,3 @@ expect( | ||
body: { | ||
messaging_type: 'UPDATE', | ||
message: { | ||
@@ -83,2 +109,3 @@ text: 'Hello', | ||
body: { | ||
messaging_type: 'UPDATE', | ||
message: { | ||
@@ -85,0 +112,0 @@ text: 'Hello', |
@@ -22,3 +22,3 @@ /* @flow */ | ||
message: Message, | ||
options?: SendOption | ||
options?: SendOption = {} | ||
): BatchItem { | ||
@@ -31,3 +31,10 @@ const recipient = | ||
: idOrRecipient; | ||
let messageType = 'UPDATE'; | ||
if (options.messaging_type) { | ||
messageType = options.messaging_type; | ||
} else if (options.tag) { | ||
messageType = 'MESSAGE_TAG'; | ||
} | ||
return createRequest({ | ||
messaging_type: messageType, | ||
recipient, | ||
@@ -34,0 +41,0 @@ message, |
@@ -29,2 +29,3 @@ /* @flow */ | ||
OpenGraphElement, | ||
MediaElement, | ||
ReceiptAttributes, | ||
@@ -45,2 +46,4 @@ AirlineBoardingPassAttributes, | ||
MessengerNLPConfig, | ||
InsightMetric, | ||
InsightOptions, | ||
} from './MessengerTypes'; | ||
@@ -72,3 +75,3 @@ | ||
accessToken: string, | ||
version?: string = 'v2.10' | ||
version?: string = '2.11' | ||
): MessengerClient => new MessengerClient(accessToken, version); | ||
@@ -80,3 +83,3 @@ | ||
constructor(accessToken: string, version?: string = '2.10') { | ||
constructor(accessToken: string, version?: string = '2.11') { | ||
this._accessToken = accessToken; | ||
@@ -121,3 +124,3 @@ invariant(typeof version === 'string', 'Type of `version` must be string.'); | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api | ||
*/ | ||
@@ -155,3 +158,3 @@ getMessengerProfile = ( | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/get-started-button | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/get-started-button | ||
*/ | ||
@@ -200,3 +203,3 @@ getGetStarted = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/persistent-menu | ||
*/ | ||
@@ -237,3 +240,3 @@ getPersistentMenu = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/greeting-text | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/greeting | ||
*/ | ||
@@ -296,3 +299,3 @@ getGreeting = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/domain-whitelisting | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
*/ | ||
@@ -328,3 +331,3 @@ getDomainWhitelist = (): Promise<MessengerProfileResponse | null> => { | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/domain-whitelisting | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
*/ | ||
@@ -349,3 +352,3 @@ getWhitelistedDomains = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/account-linking-url | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/account-linking-url | ||
*/ | ||
@@ -368,3 +371,3 @@ getAccountLinkingURL = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/payment-settings | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/payment-settings | ||
*/ | ||
@@ -407,3 +410,3 @@ getPaymentSettings = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/target-audience | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/target-audience | ||
*/ | ||
@@ -436,3 +439,3 @@ getTargetAudience = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-profile/home-url | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/home-url | ||
*/ | ||
@@ -510,3 +513,3 @@ getHomeURL = (): Promise<MessengerProfileResponse | null> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/tags/ | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags | ||
*/ | ||
@@ -521,3 +524,3 @@ getMessageTags = (): Promise<MessageTagResponse> => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference | ||
* https://developers.facebook.com/docs/messenger-platform/reference/send-api | ||
*/ | ||
@@ -533,3 +536,3 @@ // TODO: body flowtype | ||
message: Message, | ||
options?: SendOption | ||
options?: SendOption = {} | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -542,3 +545,10 @@ const recipient = | ||
: idOrRecipient; | ||
let messageType = 'UPDATE'; | ||
if (options.messaging_type) { | ||
messageType = options.messaging_type; | ||
} else if (options.tag) { | ||
messageType = 'MESSAGE_TAG'; | ||
} | ||
return this.sendRawBody({ | ||
messaging_type: messageType, | ||
recipient, | ||
@@ -553,3 +563,4 @@ message, | ||
message: Message, | ||
filedata: FileData | ||
filedata: FileData, | ||
options?: SendOption = {} | ||
) => { | ||
@@ -563,2 +574,9 @@ const form = new FormData(); | ||
: recipient; | ||
let messageType = 'UPDATE'; | ||
if (options.messaging_type) { | ||
messageType = options.messaging_type; | ||
} else if (options.tag) { | ||
messageType = 'MESSAGE_TAG'; | ||
} | ||
form.append('messaging_type', messageType); | ||
form.append('recipient', JSON.stringify(recipientObject)); | ||
@@ -577,3 +595,3 @@ form.append('message', JSON.stringify(message)); | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/contenttypes | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages#content_types | ||
*/ | ||
@@ -590,5 +608,6 @@ sendAttachment = ( | ||
attachment: Attachment, | ||
filedata: FileData | ||
filedata: FileData, | ||
option?: SendOption | ||
): Promise<SendMessageSucessResponse> => | ||
this.sendMessageFormData(recipient, { attachment }, filedata); | ||
this.sendMessageFormData(recipient, { attachment }, filedata, option); | ||
@@ -604,3 +623,4 @@ sendText = ( | ||
recipient: UserID | Recipient, | ||
audio: string | FileData | AttachmentPayload | ||
audio: string | FileData | AttachmentPayload, | ||
options?: SendOption | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -614,10 +634,10 @@ const attachment = { | ||
attachment.payload.url = audio; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} else if (audio && isPlainObject(audio)) { | ||
attachment.payload = audio; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} | ||
// $FlowFixMe | ||
return this.sendAttachmentFormData(recipient, attachment, audio); | ||
return this.sendAttachmentFormData(recipient, attachment, audio, options); | ||
}; | ||
@@ -627,3 +647,4 @@ | ||
recipient: UserID | Recipient, | ||
image: string | FileData | AttachmentPayload | ||
image: string | FileData | AttachmentPayload, | ||
options?: SendOption | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -637,10 +658,10 @@ const attachment = { | ||
attachment.payload.url = image; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} else if (image && isPlainObject(image)) { | ||
attachment.payload = image; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} | ||
// $FlowFixMe | ||
return this.sendAttachmentFormData(recipient, attachment, image); | ||
return this.sendAttachmentFormData(recipient, attachment, image, options); | ||
}; | ||
@@ -650,3 +671,4 @@ | ||
recipient: UserID | Recipient, | ||
video: string | FileData | AttachmentPayload | ||
video: string | FileData | AttachmentPayload, | ||
options?: SendOption | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -660,10 +682,10 @@ const attachment = { | ||
attachment.payload.url = video; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} else if (video && isPlainObject(video)) { | ||
attachment.payload = video; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} | ||
// $FlowFixMe | ||
return this.sendAttachmentFormData(recipient, attachment, video); | ||
return this.sendAttachmentFormData(recipient, attachment, video, options); | ||
}; | ||
@@ -673,3 +695,4 @@ | ||
recipient: UserID | Recipient, | ||
file: string | FileData | AttachmentPayload | ||
file: string | FileData | AttachmentPayload, | ||
options?: SendOption | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -683,16 +706,16 @@ const attachment = { | ||
attachment.payload.url = file; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} else if (file && isPlainObject(file)) { | ||
attachment.payload = file; | ||
return this.sendAttachment(recipient, attachment); | ||
return this.sendAttachment(recipient, attachment, options); | ||
} | ||
// $FlowFixMe | ||
return this.sendAttachmentFormData(recipient, attachment, file); | ||
return this.sendAttachmentFormData(recipient, attachment, file, options); | ||
}; | ||
/** | ||
* Templates | ||
* Message Templates | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/templates | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/templates | ||
*/ | ||
@@ -713,3 +736,3 @@ sendTemplate = ( | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/button-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/button | ||
sendButtonTemplate = ( | ||
@@ -726,3 +749,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic | ||
sendGenericTemplate = ( | ||
@@ -746,3 +769,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/list-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/list | ||
sendListTemplate = ( | ||
@@ -761,3 +784,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/open-graph-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/open-graph | ||
sendOpenGraphTemplate = ( | ||
@@ -772,3 +795,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/receipt-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/receipt | ||
sendReceiptTemplate = ( | ||
@@ -783,3 +806,13 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-boardingpass-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/media | ||
sendMediaTemplate = ( | ||
recipient: UserID | Recipient, | ||
elements: Array<MediaElement> | ||
): Promise<SendMessageSucessResponse> => | ||
this.sendTemplate(recipient, { | ||
template_type: 'media', | ||
elements, | ||
}); | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#boarding_pass | ||
sendAirlineBoardingPassTemplate = ( | ||
@@ -794,3 +827,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-checkin-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#check_in | ||
sendAirlineCheckinTemplate = ( | ||
@@ -805,3 +838,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-itinerary-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#itinerary | ||
sendAirlineItineraryTemplate = ( | ||
@@ -816,3 +849,3 @@ recipient: UserID | Recipient, | ||
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/airline-update-template | ||
// https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#update | ||
sendAirlineFlightUpdateTemplate = ( | ||
@@ -830,3 +863,3 @@ recipient: UserID | Recipient, | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies | ||
*/ | ||
@@ -869,3 +902,3 @@ sendQuickReplies = ( | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/sender-actions | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions | ||
*/ | ||
@@ -942,5 +975,174 @@ sendSenderAction = ( | ||
/** | ||
* Broadcast API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/broadcast-api | ||
*/ | ||
/** | ||
* Create Message Creative | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/sponsored-messages#creative | ||
*/ | ||
createMessageCreative = (messages: Array<Object> = []) => | ||
this._axios | ||
.post(`/me/message_creatives?access_token=${this._accessToken}`, { | ||
messages, | ||
}) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Send Broadcast Message | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages#sending | ||
*/ | ||
sendBroadcastMessage = (messageCreativeId: number, options?: Object = {}) => | ||
this._axios | ||
.post(`/me/broadcast_messages?access_token=${this._accessToken}`, { | ||
message_creative_id: messageCreativeId, | ||
...options, | ||
}) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Send Sponsored Message | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/sponsored-messages#message | ||
*/ | ||
sendSponsoredMessage = (adAccountId: string, message: Object) => | ||
this._axios | ||
.post( | ||
`/act_${adAccountId}/sponsored_message_ads?access_token=${this | ||
._accessToken}`, | ||
message | ||
) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Label API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts | ||
*/ | ||
/** | ||
* Create Label | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#create_label | ||
*/ | ||
createLabel = (name: string) => | ||
this._axios | ||
.post(`/me/custom_labels?access_token=${this._accessToken}`, { | ||
name, | ||
}) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Associating a Label to a PSID | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#associate_label | ||
*/ | ||
associateLabel = (userId: UserID, labelId: number) => | ||
this._axios | ||
.post(`/${labelId}/label?access_token=${this._accessToken}`, { | ||
user: userId, | ||
}) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Removing a Label From a PSID | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#associate_label | ||
*/ | ||
dissociateLabel = (userId: UserID, labelId: number) => | ||
this._axios | ||
.delete(`/${labelId}/label?access_token=${this._accessToken}`, { | ||
data: { user: userId }, | ||
}) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Retrieving Labels Associated with a PSID | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#get_all_labels | ||
*/ | ||
getAssociatedLabels = (userId: UserID) => | ||
this._axios | ||
.get(`/${userId}/custom_labels?access_token=${this._accessToken}`) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Retrieving Label Details | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#get_label_details | ||
*/ | ||
getLabelDetails = (labelId: number, options?: Object = {}) => { | ||
const fields = options.fields ? options.fields.join(',') : 'name'; | ||
return this._axios | ||
.get(`/${labelId}?fields=${fields}&access_token=${this._accessToken}`) | ||
.then(res => res.data, handleError); | ||
}; | ||
/** | ||
* Retrieving a List of All Labels | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#get_all_labels | ||
*/ | ||
getLabelList = (options?: Object = {}) => { | ||
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); | ||
}; | ||
/** | ||
* Deleting a Label | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/target-broadcasts#delete_label | ||
*/ | ||
deleteLabel = (labelId: number) => | ||
this._axios | ||
.delete(`/${labelId}?access_token=${this._accessToken}`) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Starting a Reach Estimation | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/estimate-reach#start | ||
*/ | ||
startReachEstimation = (customLabelId: number) => | ||
this._axios | ||
.post(`/broadcast_reach_estimations?access_token=${this._accessToken}`, { | ||
custom_label_id: customLabelId, | ||
}) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Retrieving a Reach Estimate | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/estimate-reach#get | ||
*/ | ||
getReachEstimate = (reachEstimationId: number) => | ||
this._axios | ||
.post(`/${reachEstimationId}?access_token=${this._accessToken}`) | ||
.then(res => res.data, handleError); | ||
/** | ||
* Broadcast Metrics | ||
* | ||
* Once a broadcast has been delivered, you can find out the total number of people it reached. | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages/#metrics | ||
*/ | ||
getBroadcastMessagesSent = (broadcastId: number) => | ||
this._axios | ||
.post( | ||
`/${broadcastId}/insights/messages_sent?access_token=${this | ||
._accessToken}` | ||
) | ||
.then(res => res.data.data, handleError); | ||
/** | ||
* Upload API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-api-reference/attachment-upload | ||
* https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api | ||
*/ | ||
@@ -970,3 +1172,3 @@ uploadAttachment = (type: string, url: string) => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/messenger-code | ||
* https://developers.facebook.com/docs/messenger-platform/discovery/messenger-codes | ||
*/ | ||
@@ -990,3 +1192,3 @@ generateMessengerCode = (options: Object = {}) => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/pass-thread-control | ||
* https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/pass-thread-control | ||
*/ | ||
@@ -1012,3 +1214,3 @@ passThreadControl = ( | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/take-thread-control | ||
* https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/take-thread-control | ||
*/ | ||
@@ -1026,3 +1228,3 @@ takeThreadControl = (recipientId: string, metadata?: string) => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/secondary-receivers | ||
* https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/secondary-receivers | ||
*/ | ||
@@ -1040,20 +1242,38 @@ getSecondaryReceivers = () => | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/insights/page-messaging | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messaging-insights-api | ||
*/ | ||
getDailyUniqueActiveThreadCounts = () => | ||
getInsights = ( | ||
metrics: Array<InsightMetric>, | ||
options?: InsightOptions = {} | ||
) => | ||
this._axios | ||
.get( | ||
`/me/insights/page_messages_active_threads_unique&access_token=${this | ||
._accessToken}` | ||
`/me/insights/?${querystring.stringify({ | ||
metric: metrics.join(','), | ||
access_token: this._accessToken, | ||
...options, | ||
})}` | ||
) | ||
.then(res => res.data.data, handleError); | ||
getDailyUniqueConversationCounts = () => | ||
this._axios | ||
.get( | ||
`/me/insights/page_messages_feedback_by_action_unique&access_token=${this | ||
._accessToken}` | ||
) | ||
.then(res => res.data.data, handleError); | ||
getDailyUniqueActiveThreadCounts = () => | ||
this.getInsights(['page_messages_active_threads_unique']); | ||
getBlockedConversations = () => | ||
this.getInsights(['page_messages_blocked_conversations_unique']); | ||
getReportedConversations = () => | ||
this.getInsights(['page_messages_reported_conversations_unique']); | ||
getReportedConversationsByReportType = () => | ||
this.getInsights(['page_messages_blocked_conversations_unique']); | ||
getDailyUniqueConversationCounts = () => { | ||
warning( | ||
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']); | ||
}; | ||
/** | ||
@@ -1064,19 +1284,39 @@ * Built-in NLP API | ||
*/ | ||
setNLPConfigs = (config: MessengerNLPConfig = {}) => { | ||
const query: Object = { | ||
nlp_enabled: config.nlp_enabled ? 'true' : 'false', | ||
}; | ||
if (config.custom_token) { | ||
query.custom_token = config.custom_token; | ||
} | ||
return this._axios | ||
.post(`/me/nlp_configs?${querystring.stringify(query)}`, { | ||
setNLPConfigs = (config: MessengerNLPConfig = {}) => | ||
this._axios | ||
.post(`/me/nlp_configs?${querystring.stringify(config)}`, { | ||
access_token: this._accessToken, | ||
}) | ||
.then(res => res.data, handleError); | ||
}; | ||
enableNLP = () => this.setNLPConfigs({ nlp_enabled: true }); | ||
disableNLP = () => this.setNLPConfigs({ nlp_enabled: false }); | ||
/** | ||
* Logging Custom Events | ||
* | ||
* https://developers.facebook.com/docs/app-events/bots-for-messenger#logging-custom-events | ||
*/ | ||
logCustomEvents = ({ | ||
appId, | ||
pageId, | ||
userId, | ||
events, | ||
}: { | ||
appId: number, | ||
pageId: number, | ||
userId: UserID, | ||
events: Array<Object>, | ||
}) => | ||
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, | ||
}) | ||
.then(res => res.data, handleError); | ||
} |
@@ -42,6 +42,38 @@ /* @flow */ | ||
export type Tag = 'SHIPPING_UPDATE' | 'RESERVATION_UPDATE' | 'ISSUE_RESOLUTION'; | ||
export type MessagingType = | ||
| 'RESPONSE' | ||
| 'UPDATE' | ||
| 'MESSAGE_TAG' | ||
| 'NON_PROMOTIONAL_SUBSCRIPTION'; | ||
export type MessageTag = | ||
| 'PAIRING_UPDATE' | ||
| 'APPLICATION_UPDATE' | ||
| 'ACCOUNT_UPDATE' | ||
| 'PAYMENT_UPDATE' | ||
| 'PERSONAL_FINANCE_UPDATE' | ||
| 'SHIPPING_UPDATE' | ||
| 'RESERVATION_UPDATE' | ||
| 'ISSUE_RESOLUTION' | ||
| 'APPOINTMENT_UPDATE' | ||
| 'GAME_EVENT' | ||
| 'TRANSPORTATION_UPDATE' | ||
| 'FEATURE_FUNCTIONALITY_UPDATE' | ||
| 'TICKET_UPDATE'; | ||
export type InsightMetric = | ||
| 'page_messages_active_threads_unique' | ||
| 'page_messages_blocked_conversations_unique' | ||
| 'page_messages_reported_conversations_unique' | ||
| 'page_messages_reported_conversations_by_report_type_unique' | ||
| 'page_messages_feedback_by_action_unique'; | ||
export type InsightOptions = { | ||
since?: number, | ||
until?: number, | ||
}; | ||
export type SendOption = { | ||
tag: Tag, | ||
messaging_type?: MessagingType, | ||
tag?: MessageTag, | ||
}; | ||
@@ -78,2 +110,9 @@ | ||
export type MediaElement = { | ||
media_type: 'image' | 'video', | ||
attachment_id?: string, | ||
url?: string, | ||
buttons?: Array<TemplateButton>, | ||
}; | ||
export type Address = { | ||
@@ -271,12 +310,2 @@ street_1: string, | ||
export type MessageTag = | ||
| 'SHIPPING_UPDATE' | ||
| 'RESERVATION_UPDATE' | ||
| 'ISSUE_RESOLUTION' | ||
| 'APPOINTMENT_UPDATE' | ||
| 'GAME_EVENT' | ||
| 'TRANSPORTATION_UPDATE' | ||
| 'FEATURE_FUNCTIONALITY_UPDATE' | ||
| 'TICKET_UPDATE'; | ||
export type MessageTagResponse = Array<{ | ||
@@ -296,5 +325,24 @@ tag: MessageTag, | ||
export type Model = | ||
| 'zh' | ||
| 'zh-Hans' | ||
| 'zh-Hant' | ||
| 'nl' | ||
| 'en' | ||
| 'fr' | ||
| 'de' | ||
| 'it' | ||
| 'pl' | ||
| 'pt' | ||
| 'ro' | ||
| 'es' | ||
| 'vi' | ||
| 'custom'; | ||
export type MessengerNLPConfig = { | ||
nlp_enabled?: boolean, | ||
model?: Model, | ||
custom_token?: string, | ||
verbose?: boolean, | ||
n_best?: number, | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
303857
6424
2631