messaging-api-messenger
Advanced tools
Comparing version 1.0.0-beta.0 to 1.0.0-beta.1
@@ -7,5 +7,4 @@ "use strict"; | ||
const form_data_1 = __importDefault(require("form-data")); | ||
const camelcase_keys_1 = __importDefault(require("camelcase-keys")); | ||
const omit_1 = __importDefault(require("lodash/omit")); | ||
const snakecase_keys_1 = __importDefault(require("snakecase-keys")); | ||
const messaging_api_common_1 = require("messaging-api-common"); | ||
function createMessage(payload, options = {}) { | ||
@@ -18,3 +17,3 @@ const message = Object.assign({}, payload); | ||
} | ||
return camelcase_keys_1.default(message, { deep: true }); | ||
return messaging_api_common_1.camelcaseKeysDeep(message); | ||
} | ||
@@ -32,3 +31,3 @@ function createText(text, options) { | ||
const formdata = new form_data_1.default(); | ||
formdata.append('message', JSON.stringify(snakecase_keys_1.default(message, { deep: true }))); | ||
formdata.append('message', JSON.stringify(messaging_api_common_1.snakecaseKeysDeep(message))); | ||
formdata.append('filedata', filedata, | ||
@@ -35,0 +34,0 @@ // FIXME: use pick for formdata options |
import FormData from 'form-data'; | ||
import { AxiosInstance } from 'axios'; | ||
import { OnRequestFunction } from 'messaging-api-common'; | ||
import { AccessTokenOptions, AirlineBoardingPassAttributes, AirlineCheckinAttributes, AirlineItineraryAttributes, AirlineUpdateAttributes, Attachment, BatchItem, FileData, GreetingConfig, IceBreaker, InsightMetric, InsightOptions, MediaAttachmentPayload, MediaElement, MenuItem, Message, MessageTagResponse, MessagingFeatureReview, MessengerNLPConfig, MessengerProfile, MessengerSubscription, MutationSuccessResponse, PageInfo, PersistentMenu, Persona, ReceiptAttributes, Recipient, SendMessageSuccessResponse, SendOption, SendSenderActionResponse, SenderAction, TemplateAttachmentPayload, TemplateButton, TemplateElement, TokenInfo, UploadOption, User, UserID } from './MessengerTypes'; | ||
@@ -10,3 +11,3 @@ declare type ClientConfig = { | ||
origin?: string; | ||
onRequest?: Function; | ||
onRequest?: OnRequestFunction; | ||
skipAppSecretProof?: boolean; | ||
@@ -16,3 +17,3 @@ }; | ||
static connect(accessTokenOrConfig: string | ClientConfig, version?: string): MessengerClient; | ||
_onRequest: Function; | ||
_onRequest: OnRequestFunction | undefined; | ||
_axios: AxiosInstance; | ||
@@ -19,0 +20,0 @@ _accessToken: string; |
@@ -34,3 +34,2 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
const camelcase_keys_1 = __importDefault(require("camelcase-keys")); | ||
const get_1 = __importDefault(require("lodash/get")); | ||
@@ -40,4 +39,2 @@ const invariant_1 = __importDefault(require("invariant")); | ||
const omit_1 = __importDefault(require("lodash/omit")); | ||
const snakecase_keys_1 = __importDefault(require("snakecase-keys")); | ||
const url_join_1 = __importDefault(require("url-join")); | ||
const warning_1 = __importDefault(require("warning")); | ||
@@ -71,3 +68,3 @@ const messaging_api_common_1 = require("messaging-api-common"); | ||
this._version = extractVersion(config.version || '4.0'); | ||
this._onRequest = config.onRequest || messaging_api_common_1.onRequest; | ||
this._onRequest = config.onRequest; | ||
origin = config.origin; | ||
@@ -85,3 +82,2 @@ if (typeof config.skipAppSecretProof === 'boolean') { | ||
this._version = extractVersion(version); | ||
this._onRequest = messaging_api_common_1.onRequest; | ||
skipAppSecretProof = true; | ||
@@ -119,19 +115,3 @@ } | ||
} | ||
this._axios.interceptors.request.use(config => { | ||
this._onRequest({ | ||
method: config.method, | ||
url: url_join_1.default(config.baseURL || '', config.url || '/'), | ||
headers: Object.assign(Object.assign(Object.assign({}, config.headers.common), (config.method ? config.headers[config.method] : {})), omit_1.default(config.headers, [ | ||
'common', | ||
'get', | ||
'post', | ||
'put', | ||
'patch', | ||
'delete', | ||
'head', | ||
])), | ||
body: config.data, | ||
}); | ||
return config; | ||
}); | ||
this._axios.interceptors.request.use(messaging_api_common_1.createRequestInterceptor({ onRequest: this._onRequest })); | ||
} | ||
@@ -518,3 +498,3 @@ static connect(accessTokenOrConfig, version = '4.0') { | ||
formdata.append('messaging_type', messagingType); | ||
formdata.append('recipient', JSON.stringify(snakecase_keys_1.default(recipientObject, { deep: true }))); | ||
formdata.append('recipient', JSON.stringify(messaging_api_common_1.snakecaseKeysDeep(recipientObject))); | ||
return this._axios | ||
@@ -647,3 +627,3 @@ .post(`/me/messages?access_token=${options.accessToken || this._accessToken}`, formdata, { | ||
if (item.body) { | ||
const body = snakecase_keys_1.default(item.body, { deep: true }); | ||
const body = messaging_api_common_1.snakecaseKeysDeep(item.body); | ||
return Object.assign(Object.assign({}, item), { body: Object.keys(body) | ||
@@ -665,5 +645,5 @@ .map(key => { | ||
const responseAccessPath = responseAccessPaths[index]; | ||
const datum = camelcase_keys_1.default(item, { deep: true }); | ||
const datum = messaging_api_common_1.camelcaseKeysDeep(item); | ||
if (responseAccessPath && datum.body) { | ||
return Object.assign(Object.assign({}, datum), { body: JSON.stringify(get_1.default(camelcase_keys_1.default(JSON.parse(datum.body), { deep: true }), responseAccessPath)) }); | ||
return Object.assign(Object.assign({}, datum), { body: JSON.stringify(get_1.default(messaging_api_common_1.camelcaseKeysDeep(JSON.parse(datum.body)), responseAccessPath)) }); | ||
} | ||
@@ -907,3 +887,3 @@ return datum; | ||
this._accessToken}`) | ||
.then(res => res.data.data[0].thread_owner, handleError); | ||
.then(res => res.data.data[0].threadOwner, handleError); | ||
} | ||
@@ -910,0 +890,0 @@ /** |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "1.0.0-beta.0", | ||
"version": "1.0.0-beta.1", | ||
"main": "dist/index.js", | ||
@@ -17,9 +17,7 @@ "browser": "lib/browser.js", | ||
"axios": "^0.19.0", | ||
"axios-error": "^1.0.0-alpha.2", | ||
"form-data": "^2.5.0", | ||
"axios-error": "^1.0.0-beta.1", | ||
"form-data": "^3.0.0", | ||
"invariant": "^2.2.4", | ||
"is-plain-object": "^3.0.0", | ||
"lodash": "^4.17.15", | ||
"messaging-api-common": "^1.0.0-beta.0", | ||
"url-join": "^4.0.1", | ||
"messaging-api-common": "^1.0.0-beta.1", | ||
"warning": "^4.0.3" | ||
@@ -39,3 +37,3 @@ }, | ||
}, | ||
"gitHead": "96eaeb0fc0b1bf8799d17dd93aa4c59f1eeeb0f3" | ||
"gitHead": "c92c8cdb79d62893a7c07f5208a5234f7bfc00cb" | ||
} |
@@ -145,54 +145,2 @@ import MockAdapter from 'axios-mock-adapter'; | ||
const templateElements = [ | ||
{ | ||
title: "Welcome to Peter's Hats", | ||
image_url: 'https://petersfancybrownhats.com/company_image.png', | ||
subtitle: "We've got the right hat for everyone.", | ||
default_action: { | ||
type: 'web_url', | ||
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103', | ||
messenger_extensions: true, | ||
webview_height_ratio: 'tall', | ||
fallback_url: 'https://peterssendreceiveapp.ngrok.io/', | ||
}, | ||
buttons: [ | ||
{ | ||
type: 'postback', | ||
title: 'Start Chatting', | ||
payload: 'DEVELOPER_DEFINED_PAYLOAD', | ||
}, | ||
], | ||
}, | ||
]; | ||
const templateMessage = { | ||
attachment: { | ||
type: 'template', | ||
payload: { | ||
template_type: 'generic', | ||
elements: [ | ||
{ | ||
title: "Welcome to Peter's Hats", | ||
image_url: 'https://petersfancybrownhats.com/company_image.png', | ||
subtitle: "We've got the right hat for everyone.", | ||
default_action: { | ||
type: 'web_url', | ||
url: 'https://peterssendreceiveapp.ngrok.io/view?item=103', | ||
messenger_extensions: true, | ||
webview_height_ratio: 'tall', | ||
fallback_url: 'https://peterssendreceiveapp.ngrok.io/', | ||
}, | ||
buttons: [ | ||
{ | ||
type: 'postback', | ||
title: 'Start Chatting', | ||
payload: 'DEVELOPER_DEFINED_PAYLOAD', | ||
}, | ||
], | ||
}, | ||
], | ||
image_aspect_ratio: 'horizontal', | ||
}, | ||
}, | ||
}; | ||
describe('#sendGenericTemplate', () => { | ||
@@ -199,0 +147,0 @@ it('should call messages api with generic template', async () => { |
import FormData from 'form-data'; | ||
import camelcaseKeys from 'camelcase-keys'; | ||
import omit from 'lodash/omit'; | ||
import snakecaseKeys from 'snakecase-keys'; | ||
import { camelcaseKeysDeep, snakecaseKeysDeep } from 'messaging-api-common'; | ||
@@ -40,3 +39,3 @@ import { | ||
return camelcaseKeys(message, { deep: true }); | ||
return camelcaseKeysDeep(message); | ||
} | ||
@@ -69,7 +68,4 @@ | ||
formdata.append('message', JSON.stringify(snakecaseKeysDeep(message))); | ||
formdata.append( | ||
'message', | ||
JSON.stringify(snakecaseKeys(message, { deep: true })) | ||
); | ||
formdata.append( | ||
'filedata', | ||
@@ -76,0 +72,0 @@ filedata, |
@@ -10,3 +10,2 @@ import crypto from 'crypto'; | ||
import axios, { AxiosInstance } from 'axios'; | ||
import camelcaseKeys from 'camelcase-keys'; | ||
import get from 'lodash/get'; | ||
@@ -16,8 +15,7 @@ import invariant from 'invariant'; | ||
import omit from 'lodash/omit'; | ||
import snakecaseKeys from 'snakecase-keys'; | ||
import urlJoin from 'url-join'; | ||
import warning from 'warning'; | ||
import { | ||
OnRequestFunction, | ||
camelcaseKeysDeep, | ||
onRequest, | ||
createRequestInterceptor, | ||
snakecaseKeysDeep, | ||
@@ -74,3 +72,3 @@ } from 'messaging-api-common'; | ||
origin?: string; | ||
onRequest?: Function; | ||
onRequest?: OnRequestFunction; | ||
skipAppSecretProof?: boolean; | ||
@@ -103,3 +101,3 @@ }; | ||
_onRequest: Function; | ||
_onRequest: OnRequestFunction | undefined; | ||
@@ -131,3 +129,3 @@ _axios: AxiosInstance; | ||
this._version = extractVersion(config.version || '4.0'); | ||
this._onRequest = config.onRequest || onRequest; | ||
this._onRequest = config.onRequest; | ||
origin = config.origin; | ||
@@ -148,3 +146,2 @@ | ||
this._version = extractVersion(version); | ||
this._onRequest = onRequest; | ||
@@ -201,25 +198,5 @@ skipAppSecretProof = true; | ||
this._axios.interceptors.request.use(config => { | ||
this._onRequest({ | ||
method: config.method, | ||
url: urlJoin(config.baseURL || '', config.url || '/'), | ||
headers: { | ||
...config.headers.common, | ||
...(config.method ? config.headers[config.method] : {}), | ||
...omit(config.headers, [ | ||
'common', | ||
'get', | ||
'post', | ||
'put', | ||
'patch', | ||
'delete', | ||
'head', | ||
]), | ||
}, | ||
body: config.data, | ||
}); | ||
return config; | ||
}); | ||
this._axios.interceptors.request.use( | ||
createRequestInterceptor({ onRequest: this._onRequest }) | ||
); | ||
} | ||
@@ -913,3 +890,3 @@ | ||
'recipient', | ||
JSON.stringify(snakecaseKeys(recipientObject, { deep: true })) | ||
JSON.stringify(snakecaseKeysDeep(recipientObject)) | ||
); | ||
@@ -1201,6 +1178,3 @@ | ||
if (item.body) { | ||
const body = snakecaseKeys(item.body, { deep: true }) as Record< | ||
string, | ||
any | ||
>; | ||
const body = snakecaseKeysDeep(item.body) as Record<string, any>; | ||
return { | ||
@@ -1231,6 +1205,3 @@ ...item, | ||
const responseAccessPath = responseAccessPaths[index]; | ||
const datum = camelcaseKeys(item, { deep: true }) as Record< | ||
string, | ||
any | ||
>; | ||
const datum = camelcaseKeysDeep(item) as Record<string, any>; | ||
if (responseAccessPath && datum.body) { | ||
@@ -1241,3 +1212,3 @@ return { | ||
get( | ||
camelcaseKeys(JSON.parse(datum.body), { deep: true }), | ||
camelcaseKeysDeep(JSON.parse(datum.body)), | ||
responseAccessPath | ||
@@ -1604,3 +1575,3 @@ ) | ||
) | ||
.then(res => res.data.data[0].thread_owner, handleError); | ||
.then(res => res.data.data[0].threadOwner, handleError); | ||
} | ||
@@ -1607,0 +1578,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8
680520
12391
+ Addedform-data@3.0.2(transitive)
- Removedis-plain-object@^3.0.0
- Removedurl-join@^4.0.1
- Removedform-data@2.5.2(transitive)
- Removedis-plain-object@3.0.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
Updatedaxios-error@^1.0.0-beta.1
Updatedform-data@^3.0.0