messaging-api-messenger
Advanced tools
Comparing version 0.5.16 to 0.6.0
@@ -129,10 +129,2 @@ '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;}; | ||
/** | ||
@@ -234,26 +226,2 @@ * Get Page Info | ||
/** | ||
@@ -349,30 +317,4 @@ * Persistent Menu | ||
/** | ||
* Domain Whitelist | ||
* Whitelisted Domains | ||
* | ||
@@ -404,9 +346,6 @@ * https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
/** | ||
* Whitelisted Domains | ||
* Account Linking URL | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/account-linking-url | ||
*/ | ||
@@ -437,5 +376,5 @@ | ||
/** | ||
* Account Linking URL | ||
* Payment Settings | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/account-linking-url | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/payment-settings | ||
*/ | ||
@@ -465,7 +404,2 @@ | ||
/** | ||
* Payment Settings | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/payment-settings | ||
*/ | ||
@@ -499,30 +433,7 @@ | ||
/** | ||
* Target Audience | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/target-audience | ||
*/ | ||
* Target Audience | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/target-audience | ||
*/ | ||
@@ -560,6 +471,6 @@ | ||
/** | ||
* Chat Extension Home URL | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/home-url | ||
*/ | ||
* Chat Extension Home URL | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/home-url | ||
*/ | ||
@@ -598,2 +509,7 @@ | ||
/** | ||
* Message tags | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags | ||
*/ | ||
@@ -609,51 +525,7 @@ | ||
/** | ||
* Message tags | ||
* Send API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags | ||
* https://developers.facebook.com/docs/messenger-platform/reference/send-api | ||
*/ | ||
/** | ||
* Send API | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/send-api | ||
*/ | ||
// TODO: body flowtype | ||
@@ -1449,2 +1321,4 @@ | ||
/** | ||
@@ -1601,5 +1475,5 @@ * Messenger Code API | ||
* 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 = ({ 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 | ||
*/}exports.default = MessengerClient;MessengerClient.connect = (accessToken, version = '2.11') => new MessengerClient(accessToken, version);var _initialiseProps = function _initialiseProps() {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.setGetStarted = payload => this.setMessengerProfile({ get_started: { payload } });this.deleteGetStarted = (options = {}) => this.deleteMessengerProfile(['get_started'], options);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.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.setGreeting = (greeting, options = {}) => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] }, options);}return this.setMessengerProfile({ greeting }, options);};this.deleteGreeting = (options = {}) => this.deleteMessengerProfile(['greeting'], options);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.setHomeURL = (url, { webview_share_button, in_test }, options = {}) => this.setMessengerProfile({ home_url: { url, webview_height_ratio: 'tall', in_test, webview_share_button } }, options);this.deleteHomeURL = (options = {}) => this.deleteMessengerProfile(['home_url'], options);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 | ||
@@ -1611,3 +1485,3 @@ }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, 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 }) => | ||
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 = [];const isReusable = options.is_reusable || false;if (typeof attachment === 'string') {args.push({ message: { attachment: { type, payload: { url: attachment, is_reusable: isReusable } } } });} else {const form = new _formData2.default();form.append('message', JSON.stringify({ attachment: { type, payload: { is_reusable: isReusable } } }));form.append('filedata', attachment, (0, _lodash2.default)(options, ['is_reusable']));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 }) => | ||
@@ -1614,0 +1488,0 @@ |
{ | ||
"name": "messaging-api-messenger", | ||
"description": "Messaging API client for Messenger", | ||
"version": "0.5.16", | ||
"version": "0.6.0", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": ">=6" |
@@ -129,10 +129,2 @@ /* @flow */ | ||
getHTTPClient: () => Axios = () => { | ||
warning( | ||
false, | ||
'`.getHTTPClient` method is deprecated. use `.axios` getter instead.' | ||
); | ||
return this._axios; | ||
}; | ||
/** | ||
@@ -222,10 +214,2 @@ * Get Page Info | ||
getGetStartedButton = (): Promise<MessengerProfileResponse | null> => { | ||
warning( | ||
false, | ||
'`getGetStartedButton` is deprecated, use `getGetStarted` instead' | ||
); | ||
return this.getGetStarted(); | ||
}; | ||
setGetStarted = (payload: string): Promise<MutationSuccessResponse> => | ||
@@ -238,10 +222,2 @@ this.setMessengerProfile({ | ||
setGetStartedButton = (payload: string): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`setGetStartedButton` is deprecated, use `setGetStarted` instead' | ||
); | ||
return this.setGetStarted(payload); | ||
}; | ||
deleteGetStarted = ( | ||
@@ -252,10 +228,2 @@ options?: Object = {} | ||
deleteGetStartedButton = (): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`deleteGetStartedButton` is deprecated, use `deleteGetStarted` instead' | ||
); | ||
return this.deleteGetStarted(); | ||
}; | ||
/** | ||
@@ -322,10 +290,2 @@ * Persistent Menu | ||
getGreetingText = (): Promise<MessengerProfileResponse | null> => { | ||
warning( | ||
false, | ||
'`getGreetingText` is deprecated, use `getGreeting` instead' | ||
); | ||
return this.getGreeting(); | ||
}; | ||
setGreeting = ( | ||
@@ -357,55 +317,6 @@ greeting: string | Array<GreetingConfig>, | ||
setGreetingText = ( | ||
greeting: string | Array<GreetingConfig> | ||
): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`setGreetingText` is deprecated, use `setGreeting` instead' | ||
); | ||
return this.setGreeting(greeting); | ||
}; | ||
deleteGreeting = (options?: Object = {}): Promise<MutationSuccessResponse> => | ||
this.deleteMessengerProfile(['greeting'], options); | ||
deleteGreetingText = (): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`deleteGreetingText` is deprecated, use `deleteGreeting` instead' | ||
); | ||
return this.deleteGreeting(); | ||
}; | ||
/** | ||
* Domain Whitelist | ||
* | ||
* https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting | ||
*/ | ||
getDomainWhitelist = (): Promise<MessengerProfileResponse | null> => { | ||
warning( | ||
false, | ||
'`getDomainWhitelist` is deprecated. use `getWhitelistedDomains` instead.' | ||
); | ||
return this.getWhitelistedDomains(); | ||
}; | ||
setDomainWhitelist = ( | ||
domains: Array<string> | ||
): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`setDomainWhitelist` is deprecated. use `setWhitelistedDomains` instead.' | ||
); | ||
return this.setWhitelistedDomains(domains); | ||
}; | ||
deleteDomainWhitelist = (): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`deleteDomainWhitelist` is deprecated. use `deleteWhitelistedDomains` instead.' | ||
); | ||
return this.deleteWhitelistedDomains(); | ||
}; | ||
/** | ||
* Whitelisted Domains | ||
@@ -570,10 +481,2 @@ * | ||
getChatExtensionHomeURL = (): Promise<MessengerProfileResponse | null> => { | ||
warning( | ||
false, | ||
'`getChatExtensionHomeURL` is deprecated. use `getHomeURL` instead.' | ||
); | ||
return this.getHomeURL(); | ||
}; | ||
setHomeURL = ( | ||
@@ -602,36 +505,5 @@ url: string, | ||
setChatExtensionHomeURL = ( | ||
url: string, | ||
{ | ||
webview_height_ratio, | ||
webview_share_button, | ||
in_test, | ||
}: { | ||
webview_height_ratio: string, | ||
webview_share_button?: 'hide' | 'show', | ||
in_test: boolean, | ||
} | ||
): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`setChatExtensionHomeURL` is deprecated. use `setHomeURL` instead.' | ||
); | ||
return this.setHomeURL(url, { | ||
webview_height_ratio, | ||
webview_share_button, | ||
in_test, | ||
}); | ||
}; | ||
deleteHomeURL = (options?: Object = {}): Promise<MutationSuccessResponse> => | ||
this.deleteMessengerProfile(['home_url'], options); | ||
deleteChatExtensionHomeURL = (): Promise<MutationSuccessResponse> => { | ||
warning( | ||
false, | ||
'`deleteChatExtensionHomeURL` is deprecated. use `deleteHomeURL` instead.' | ||
); | ||
return this.deleteHomeURL(); | ||
}; | ||
/** | ||
@@ -1395,2 +1267,4 @@ * Message tags | ||
const isReusable = options.is_reusable || false; | ||
if (typeof attachment === 'string') { | ||
@@ -1403,3 +1277,3 @@ args.push({ | ||
url: attachment, | ||
is_reusable: true, | ||
is_reusable: isReusable, | ||
}, | ||
@@ -1418,3 +1292,3 @@ }, | ||
payload: { | ||
is_reusable: true, | ||
is_reusable: isReusable, | ||
}, | ||
@@ -1425,3 +1299,3 @@ }, | ||
form.append('filedata', attachment, options); | ||
form.append('filedata', attachment, omit(options, ['is_reusable'])); | ||
@@ -1428,0 +1302,0 @@ args.push(form, { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2771
329551
7113