messaging-api-messenger
Advanced tools
Comparing version 0.4.7 to 0.5.0-0
@@ -6,2 +6,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;}; | ||
var _axios = require('axios');var _axios2 = _interopRequireDefault(_axios); | ||
var _axiosError = require('axios-error');var _axiosError2 = _interopRequireDefault(_axiosError); | ||
var _formData = require('form-data');var _formData2 = _interopRequireDefault(_formData); | ||
@@ -54,2 +55,15 @@ var _invariant = require('invariant');var _invariant2 = _interopRequireDefault(_invariant); | ||
function extractVersion(version) { | ||
if (version.startsWith('v')) { | ||
return version.slice(1); | ||
} | ||
return version; | ||
} | ||
function handleError(err) {const | ||
error = err.response.data.error; | ||
const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`; | ||
throw new _axiosError2.default(msg, err); | ||
} | ||
class MessengerClient { | ||
@@ -65,7 +79,8 @@ | ||
constructor(accessToken, version = 'v2.10') {_initialiseProps.call(this); | ||
constructor(accessToken, version = '2.10') {_initialiseProps.call(this); | ||
this._accessToken = accessToken; | ||
this._version = version; | ||
this._http = _axios2.default.create({ | ||
baseURL: `https://graph.facebook.com/${version}/`, | ||
(0, _invariant2.default)(typeof version === 'string', 'Type of `version` must be string.'); | ||
this._version = extractVersion(version); | ||
this._axios = _axios2.default.create({ | ||
baseURL: `https://graph.facebook.com/v${this._version}/`, | ||
headers: { 'Content-Type': 'application/json' } }); | ||
@@ -79,4 +94,14 @@ | ||
get axios() { | ||
return this._axios; | ||
} | ||
/** | ||
@@ -891,5 +916,5 @@ * Get User Profile | ||
* 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 = () => this._http;this.getUserProfile = userId => this._http.get(`/${userId}?access_token=${this._accessToken}`).then(res => res.data);this.getMessengerProfile = fields => this._http.get(`/me/messenger_profile?fields=${fields.join(',')}&access_token=${this._accessToken}`).then(res => res.data.data);this.setMessengerProfile = profile => this._http.post(`/me/messenger_profile?access_token=${this._accessToken}`, profile).then(res => res.data);this.deleteMessengerProfile = fields => this._http.delete(`/me/messenger_profile?access_token=${this._accessToken}`, { data: { fields } }).then(res => res.data);this.getGetStartedButton = () => this.getMessengerProfile(['get_started']).then(res => res[0].get_started);this.setGetStartedButton = payload => this.setMessengerProfile({ get_started: { payload } });this.deleteGetStartedButton = () => this.deleteMessengerProfile(['get_started']);this.getPersistentMenu = () => this.getMessengerProfile(['persistent_menu']).then(res => res[0].persistent_menu);this.setPersistentMenu = (menuItems, { composerInputDisabled = false } = {}) => {// menuItems is in type PersistentMenu | ||
*/}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.getGetStartedButton = () => this.getMessengerProfile(['get_started']).then(res => res[0].get_started);this.setGetStartedButton = payload => this.setMessengerProfile({ get_started: { payload } });this.deleteGetStartedButton = () => this.deleteMessengerProfile(['get_started']);this.getPersistentMenu = () => this.getMessengerProfile(['persistent_menu']).then(res => res[0].persistent_menu);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.getGreetingText = () => this.getMessengerProfile(['greeting']).then(res => res[0].greeting);this.setGreetingText = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.deleteGreetingText = () => this.deleteMessengerProfile(['greeting']);this.getDomainWhitelist = () => {(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].whitelisted_domains);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]);this.setAccountLinkingURL = url => this.setMessengerProfile({ account_linking_url: url });this.deleteAccountLinkingURL = () => this.deleteMessengerProfile(['account_linking_url']);this.getPaymentSettings = () => this.getMessengerProfile(['payment_settings']).then(res => res[0]);this.setPaymentPrivacyPolicyURL = url => this.setMessengerProfile({ payment_settings: { privacy_url: url } });this.setPaymentPublicKey = key => this.setMessengerProfile({ payment_settings: { public_key: key } });this.setPaymentTestUsers = users => this.setMessengerProfile({ payment_settings: { test_users: users } });this.deletePaymentSettings = () => this.deleteMessengerProfile(['payment_settings']);this.getTargetAudience = () => this.getMessengerProfile(['target_audience']).then(res => res[0]);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getChatExtensionHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0]);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, in_test, webview_share_button } });this.deleteChatExtensionHomeURL = () => this.deleteMessengerProfile(['home_url']);this.getMessageTags = () => this._http.get(`/page_message_tags?access_token=${this._accessToken}`).then(res => res.data.data);this.sendRawBody = body => this._http.post(`/me/messages?access_token=${this._accessToken}`, body).then(res => res.data);this.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._http.post(`/me/messages?access_token=${this._accessToken}`, form, { headers: form.getHeaders() }).then(res => res.data);};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.setMessengerProfile({ persistent_menu: [{ locale: 'default', composer_input_disabled: composerInputDisabled, call_to_actions: menuItems }] });};this.deletePersistentMenu = () => this.deleteMessengerProfile(['persistent_menu']);this.getGreetingText = () => this.getMessengerProfile(['greeting']).then(res => res[0].greeting);this.setGreetingText = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.deleteGreetingText = () => this.deleteMessengerProfile(['greeting']);this.getDomainWhitelist = () => {(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].whitelisted_domains);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]);this.setAccountLinkingURL = url => this.setMessengerProfile({ account_linking_url: url });this.deleteAccountLinkingURL = () => this.deleteMessengerProfile(['account_linking_url']);this.getPaymentSettings = () => this.getMessengerProfile(['payment_settings']).then(res => res[0]);this.setPaymentPrivacyPolicyURL = url => this.setMessengerProfile({ payment_settings: { privacy_url: url } });this.setPaymentPublicKey = key => this.setMessengerProfile({ payment_settings: { public_key: key } });this.setPaymentTestUsers = users => this.setMessengerProfile({ payment_settings: { test_users: users } });this.deletePaymentSettings = () => this.deleteMessengerProfile(['payment_settings']);this.getTargetAudience = () => this.getMessengerProfile(['target_audience']).then(res => res[0]);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getChatExtensionHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0]);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, in_test, webview_share_button } });this.deleteChatExtensionHomeURL = () => this.deleteMessengerProfile(['home_url']);this.getMessageTags = () => this._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 | ||
@@ -902,6 +927,6 @@ 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 | ||
(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._http.post(`/me/message_attachments?access_token=${this._accessToken}`, { message: { attachment: { type, payload: { url, is_reusable: true } } } }).then(res => res.data);this.uploadAudio = url => this.uploadAttachment('audio', url);this.uploadImage = url => this.uploadAttachment('image', url);this.uploadVideo = url => this.uploadAttachment('video', url);this.uploadFile = url => this.uploadAttachment('file', url);this.generateMessengerCode = (options = {}) => this._http.post(`/me/messenger_codes?access_token=${this._accessToken}`, _extends({ type: 'standard' }, options)).then(res => res.data);this.passThreadControl = (recipientId, targetAppId, metadata) => this._http.post(`/me/pass_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, target_app_id: targetAppId, metadata }).then(res => res.data);this.takeThreadControl = (recipientId, metadata) => this._http.post(`/me/take_thread_control?access_token=${this._accessToken}`, { recipient: { id: recipientId }, metadata }).then(res => res.data);this.getSecondaryReceivers = () => this._http.get(`/me/secondary_receivers?fields=id,name&access_token=${this._accessToken}`).then(res => res.data.data);this.getDailyUniqueActiveThreadCounts = () => this._http.get(`/me/insights/page_messages_active_threads_unique&access_token=${this._accessToken}`).then(res => res.data.data);this.getDailyUniqueConversationCounts = () => this._http.get(`/me/insights/page_messages_feedback_by_action_unique&access_token=${this._accessToken}`).then(res => res.data.data);this.setNLPConfigs = (config = {}) => {const query = { nlp_enabled: config.nlp_enabled ? 'true' : 'false' };if (config.custom_token) {query.custom_token = config.custom_token;}return this._http.post(`/me/nlp_configs?${_querystring2.default.stringify(query)}`, { | ||
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.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 }). | ||
then(res => res.data); | ||
then(res => res.data, handleError); | ||
};this. | ||
@@ -908,0 +933,0 @@ |
{ | ||
"name": "messaging-api-messenger", | ||
"description": "Messaging API client for Messenger", | ||
"version": "0.4.7", | ||
"version": "0.5.0-0", | ||
"engines": { | ||
@@ -22,2 +22,3 @@ "node": ">=6" | ||
"axios": "^0.16.2", | ||
"axios-error": "^0.5.0-0", | ||
"form-data": "^2.3.1", | ||
@@ -24,0 +25,0 @@ "invariant": "^2.2.2", |
@@ -61,6 +61,6 @@ # messaging-api-messenger | ||
```js | ||
const client = MessengerClient.connect(accessToken, 'v2.9'); | ||
const client = MessengerClient.connect(accessToken, '2.9'); | ||
``` | ||
If it is not specified, version `v2.10` will be used as default. | ||
If it is not specified, version `2.10` will be used as default. | ||
@@ -67,0 +67,0 @@ <br /> |
@@ -6,2 +6,3 @@ /* @flow */ | ||
import axios from 'axios'; | ||
import AxiosError from 'axios-error'; | ||
import FormData from 'form-data'; | ||
@@ -54,2 +55,15 @@ import invariant from 'invariant'; | ||
function extractVersion(version) { | ||
if (version.startsWith('v')) { | ||
return version.slice(1); | ||
} | ||
return version; | ||
} | ||
function handleError(err) { | ||
const { error } = err.response.data; | ||
const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`; | ||
throw new AxiosError(msg, err); | ||
} | ||
export default class MessengerClient { | ||
@@ -63,9 +77,10 @@ static connect = ( | ||
_version: string; | ||
_http: Axios; | ||
_axios: Axios; | ||
constructor(accessToken: string, version?: string = 'v2.10') { | ||
constructor(accessToken: string, version?: string = '2.10') { | ||
this._accessToken = accessToken; | ||
this._version = version; | ||
this._http = axios.create({ | ||
baseURL: `https://graph.facebook.com/${version}/`, | ||
invariant(typeof version === 'string', 'Type of `version` must be string.'); | ||
this._version = extractVersion(version); | ||
this._axios = axios.create({ | ||
baseURL: `https://graph.facebook.com/v${this._version}/`, | ||
headers: { 'Content-Type': 'application/json' }, | ||
@@ -79,4 +94,14 @@ }); | ||
getHTTPClient: () => Axios = () => this._http; | ||
get axios(): Axios { | ||
return this._axios; | ||
} | ||
getHTTPClient: () => Axios = () => { | ||
warning( | ||
false, | ||
'`.getHTTPClient` method is deprecated. use `.axios` getter instead.' | ||
); | ||
return this._axios; | ||
}; | ||
/** | ||
@@ -89,5 +114,5 @@ * Get User Profile | ||
getUserProfile = (userId: string): Promise<User> => | ||
this._http | ||
this._axios | ||
.get(`/${userId}?access_token=${this._accessToken}`) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -102,3 +127,3 @@ /** | ||
): Promise<MessengerProfileResponse> => | ||
this._http | ||
this._axios | ||
.get( | ||
@@ -108,3 +133,3 @@ `/me/messenger_profile?fields=${fields.join(',')}&access_token=${this | ||
) | ||
.then(res => res.data.data); | ||
.then(res => res.data.data, handleError); | ||
@@ -114,5 +139,5 @@ setMessengerProfile = ( | ||
): Promise<MutationSuccessResponse> => | ||
this._http | ||
this._axios | ||
.post(`/me/messenger_profile?access_token=${this._accessToken}`, profile) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -122,3 +147,3 @@ deleteMessengerProfile = ( | ||
): Promise<MutationSuccessResponse> => | ||
this._http | ||
this._axios | ||
.delete(`/me/messenger_profile?access_token=${this._accessToken}`, { | ||
@@ -129,3 +154,3 @@ data: { | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -383,5 +408,5 @@ /** | ||
getMessageTags = (): Promise<MessageTagResponse> => | ||
this._http | ||
this._axios | ||
.get(`/page_message_tags?access_token=${this._accessToken}`) | ||
.then(res => res.data.data); | ||
.then(res => res.data.data, handleError); | ||
@@ -395,5 +420,5 @@ /** | ||
sendRawBody = (body: Object): Promise<SendMessageSucessResponse> => | ||
this._http | ||
this._axios | ||
.post(`/me/messages?access_token=${this._accessToken}`, body) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -433,7 +458,7 @@ sendMessage = ( | ||
form.append('filedata', filedata); | ||
return this._http | ||
return this._axios | ||
.post(`/me/messages?access_token=${this._accessToken}`, form, { | ||
headers: form.getHeaders(), | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
}; | ||
@@ -793,3 +818,3 @@ | ||
uploadAttachment = (type: string, url: string) => | ||
this._http | ||
this._axios | ||
.post(`/me/message_attachments?access_token=${this._accessToken}`, { | ||
@@ -806,3 +831,3 @@ message: { | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -820,3 +845,3 @@ uploadAudio = (url: string) => this.uploadAttachment('audio', url); | ||
generateMessengerCode = (options: Object = {}) => | ||
this._http | ||
this._axios | ||
.post(`/me/messenger_codes?access_token=${this._accessToken}`, { | ||
@@ -826,3 +851,3 @@ type: 'standard', | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -845,3 +870,3 @@ /** | ||
) => | ||
this._http | ||
this._axios | ||
.post(`/me/pass_thread_control?access_token=${this._accessToken}`, { | ||
@@ -852,3 +877,3 @@ recipient: { id: recipientId }, | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -861,3 +886,3 @@ /** | ||
takeThreadControl = (recipientId: string, metadata?: string) => | ||
this._http | ||
this._axios | ||
.post(`/me/take_thread_control?access_token=${this._accessToken}`, { | ||
@@ -867,3 +892,3 @@ recipient: { id: recipientId }, | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
@@ -876,3 +901,3 @@ /** | ||
getSecondaryReceivers = () => | ||
this._http | ||
this._axios | ||
.get( | ||
@@ -882,3 +907,3 @@ `/me/secondary_receivers?fields=id,name&access_token=${this | ||
) | ||
.then(res => res.data.data); | ||
.then(res => res.data.data, handleError); | ||
@@ -891,3 +916,3 @@ /** | ||
getDailyUniqueActiveThreadCounts = () => | ||
this._http | ||
this._axios | ||
.get( | ||
@@ -897,6 +922,6 @@ `/me/insights/page_messages_active_threads_unique&access_token=${this | ||
) | ||
.then(res => res.data.data); | ||
.then(res => res.data.data, handleError); | ||
getDailyUniqueConversationCounts = () => | ||
this._http | ||
this._axios | ||
.get( | ||
@@ -906,3 +931,3 @@ `/me/insights/page_messages_feedback_by_action_unique&access_token=${this | ||
) | ||
.then(res => res.data.data); | ||
.then(res => res.data.data, handleError); | ||
@@ -922,7 +947,7 @@ /** | ||
return this._http | ||
return this._axios | ||
.post(`/me/nlp_configs?${querystring.stringify(query)}`, { | ||
access_token: this._accessToken, | ||
}) | ||
.then(res => res.data); | ||
.then(res => res.data, handleError); | ||
}; | ||
@@ -929,0 +954,0 @@ |
Sorry, the diff of this file is too big to display
234879
5067
7
+ Addedaxios-error@^0.5.0-0
+ Addedaxios-error@0.5.4(transitive)