diff --git a/packages/bottender-facebook/src/FacebookConnector.ts b/packages/bottender-facebook/src/FacebookConnector.ts index faa8ecdcc..fa4a04886 100644 --- a/packages/bottender-facebook/src/FacebookConnector.ts +++ b/packages/bottender-facebook/src/FacebookConnector.ts @@ -166,11 +166,23 @@ export default class FacebookConnector } } + let client; + if (customAccessToken) { + client = new FacebookClient({ + accessToken: customAccessToken, + appSecret: this._appSecret, + origin: this._origin, + skipAppSecretProof: this._skipAppSecretProof, + }); + } else { + client = this._client; + } + if (params.event instanceof FacebookEvent) { return new FacebookContext({ ...params, event: params.event, - client: this._client, + client, customAccessToken, batchQueue: this._batchQueue, appId: this._appId, @@ -179,7 +191,7 @@ export default class FacebookConnector return new MessengerContext({ ...params, event: params.event, - client: this._client, + client, customAccessToken, batchQueue: this._batchQueue, appId: this._appId, diff --git a/packages/bottender-facebook/src/FacebookContext.ts b/packages/bottender-facebook/src/FacebookContext.ts index bc5db42d3..aaebbaedd 100644 --- a/packages/bottender-facebook/src/FacebookContext.ts +++ b/packages/bottender-facebook/src/FacebookContext.ts @@ -101,9 +101,10 @@ export default class FacebookContext extends Context< if (this._batchQueue) { return this._batchQueue.push( + // FIXME: this type should be fixed in MessengerBatch MessengerBatch.sendText(recipient, text, { accessToken: this._customAccessToken, - }) + } as any) ); } return this._client.sendText(recipient, text); @@ -148,9 +149,10 @@ export default class FacebookContext extends Context< if (this._batchQueue) { return this._batchQueue.push( + // FIXME: this type should be fixed in MessengerBatch MessengerBatch.sendMessage(recipient, message, { accessToken: this._customAccessToken, - }) + } as any) ); } return this._client.sendMessage(recipient, message); diff --git a/packages/bottender-luis/package.json b/packages/bottender-luis/package.json index 2b8f8e3d1..46fd0e455 100644 --- a/packages/bottender-luis/package.json +++ b/packages/bottender-luis/package.json @@ -1,5 +1,6 @@ { "name": "@bottender/luis", + "version": "1.5.1-alpha.9", "description": "LUIS integration for Bottender.", "license": "MIT", "homepage": "https://bottender.js.org/", @@ -7,14 +8,13 @@ "type": "git", "url": "https://github.com/Yoctol/bottender.git" }, - "version": "1.5.1-alpha.9", "main": "dist/index.js", "files": [ "dist" ], "types": "dist/index.d.ts", "dependencies": { - "axios": "^0.19.2", + "axios": "^0.21.4", "invariant": "^2.2.4" }, "peerDependencies": { diff --git a/packages/bottender-qna-maker/package.json b/packages/bottender-qna-maker/package.json index c802c2fee..12f72f3d8 100644 --- a/packages/bottender-qna-maker/package.json +++ b/packages/bottender-qna-maker/package.json @@ -1,5 +1,6 @@ { "name": "@bottender/qna-maker", + "version": "1.5.1-alpha.9", "description": "QnA Maker integration for Bottender.", "license": "MIT", "homepage": "https://bottender.js.org/", @@ -7,14 +8,13 @@ "type": "git", "url": "https://github.com/Yoctol/bottender.git" }, - "version": "1.5.1-alpha.9", "main": "dist/index.js", "files": [ "dist" ], "types": "dist/index.d.ts", "dependencies": { - "axios": "^0.19.2", + "axios": "^0.21.4", "invariant": "^2.2.4" }, "peerDependencies": { diff --git a/packages/bottender-rasa/package.json b/packages/bottender-rasa/package.json index 0e0136811..21ca41669 100644 --- a/packages/bottender-rasa/package.json +++ b/packages/bottender-rasa/package.json @@ -1,5 +1,6 @@ { "name": "@bottender/rasa", + "version": "1.5.1-alpha.9", "description": "Rasa NLU integration for Bottender.", "license": "MIT", "homepage": "https://bottender.js.org/", @@ -7,7 +8,6 @@ "type": "git", "url": "https://github.com/Yoctol/bottender.git" }, - "version": "1.5.1-alpha.9", "main": "dist/index.js", "files": [ "dist" @@ -15,7 +15,7 @@ "types": "dist/index.d.ts", "dependencies": { "@types/lodash": "^4.14.149", - "axios": "^0.19.2", + "axios": "^0.21.4", "lodash": "^4.17.15" }, "peerDependencies": { diff --git a/packages/bottender/package.json b/packages/bottender/package.json index e5145706e..e5ca709bc 100644 --- a/packages/bottender/package.json +++ b/packages/bottender/package.json @@ -1,5 +1,6 @@ { "name": "bottender", + "version": "1.5.1-alpha.9", "description": "A framework for building conversational user interfaces.", "license": "MIT", "homepage": "https://bottender.js.org/", @@ -7,7 +8,6 @@ "type": "git", "url": "https://github.com/Yoctol/bottender.git" }, - "version": "1.5.1-alpha.9", "main": "dist/index.js", "browser": "dist/browser.js", "bin": { @@ -43,7 +43,7 @@ "@types/update-notifier": "^4.1.0", "@types/warning": "^3.0.0", "arg": "^4.1.3", - "axios": "^0.19.2", + "axios": "^0.21.4", "axios-error": "^1.0.0-beta.27", "body-parser": "^1.19.0", "chalk": "~2.4.2", @@ -54,7 +54,7 @@ "delay": "^4.3.0", "dotenv": "^8.2.0", "express": "^4.17.1", - "facebook-batch": "1.0.0-beta.32", + "facebook-batch": "1.0.6", "figures": "^3.2.0", "file-type": "^14.1.3", "fs-extra": "^8.1.0", @@ -67,12 +67,12 @@ "jsonfile": "^6.0.0", "lodash": "^4.17.15", "lru-cache": "^5.1.1", - "messaging-api-common": "1.0.0-beta.29", - "messaging-api-line": "1.0.0-beta.33", - "messaging-api-messenger": "1.0.0-beta.33", - "messaging-api-slack": "1.0.0-beta.33", - "messaging-api-telegram": "1.0.0-beta.33", - "messaging-api-viber": "1.0.0-beta.33", + "messaging-api-common": "1.0.4", + "messaging-api-line": "1.0.6", + "messaging-api-messenger": "1.0.6", + "messaging-api-slack": "1.0.6", + "messaging-api-telegram": "1.0.6", + "messaging-api-viber": "1.0.6", "minimist": "^1.2.0", "mongodb": "^3.5.4", "ngrok": "^3.4.1", diff --git a/packages/bottender/src/messenger/FacebookBaseConnector.ts b/packages/bottender/src/messenger/FacebookBaseConnector.ts index 1f18f4d9a..ab7d26b28 100644 --- a/packages/bottender/src/messenger/FacebookBaseConnector.ts +++ b/packages/bottender/src/messenger/FacebookBaseConnector.ts @@ -41,6 +41,10 @@ export default class FacebookBaseConnector< _appSecret: string; + _origin: string | undefined = undefined; + + _skipAppSecretProof: boolean | undefined = undefined; + _mapPageToAccessToken: ((pageId: string) => Promise) | null = null; _verifyToken: string | null = null; @@ -91,6 +95,9 @@ export default class FacebookBaseConnector< this._batchConfig ); } + + this._origin = origin; + this._skipAppSecretProof = skipAppSecretProof; } this._appId = appId; diff --git a/packages/bottender/src/messenger/MessengerConnector.ts b/packages/bottender/src/messenger/MessengerConnector.ts index a9e401b0d..90a63210f 100644 --- a/packages/bottender/src/messenger/MessengerConnector.ts +++ b/packages/bottender/src/messenger/MessengerConnector.ts @@ -169,9 +169,17 @@ export default class MessengerConnector } else { let user = {}; try { - user = await this._client.getUserProfile(senderId as any, { - accessToken: customAccessToken, - }); + if (customAccessToken) { + const client = new MessengerClient({ + accessToken: customAccessToken, + appSecret: this._appSecret, + origin: this._origin, + skipAppSecretProof: this._skipAppSecretProof, + }); + user = await client.getUserProfile(senderId as any); + } else { + user = await this._client.getUserProfile(senderId as any); + } } catch (err) { warning( false, @@ -243,9 +251,22 @@ export default class MessengerConnector customAccessToken = await this._mapPageToAccessToken(pageId); } } + + let client; + if (customAccessToken) { + client = new MessengerClient({ + accessToken: customAccessToken, + appSecret: this._appSecret, + origin: this._origin, + skipAppSecretProof: this._skipAppSecretProof, + }); + } else { + client = this._client; + } + return new MessengerContext({ ...params, - client: this._client, + client, customAccessToken, batchQueue: this._batchQueue, appId: this._appId, diff --git a/packages/bottender/src/messenger/MessengerContext.ts b/packages/bottender/src/messenger/MessengerContext.ts index 57b4a7adb..c52bd7f3b 100644 --- a/packages/bottender/src/messenger/MessengerContext.ts +++ b/packages/bottender/src/messenger/MessengerContext.ts @@ -200,15 +200,10 @@ class MessengerContext extends Context { ) ); } - return this._client.getUserProfile( - this._session.user.id, - this._getMethodOptions(options) - ); + return this._client.getUserProfile(this._session.user.id, options); } - async getUserPersistentMenu( - options: MessengerTypes.SendOption = {} - ): Promise { + async getUserPersistentMenu(): Promise { if (!this._session) { warning( false, @@ -221,20 +216,19 @@ class MessengerContext extends Context { return this._batchQueue.push( MessengerBatch.getUserPersistentMenu( this._session.user.id, - this._getMethodOptions(options) + this._getMethodOptions({}) ) ); } - return this._client.getUserPersistentMenu( - this._session.user.id, - this._getMethodOptions(options) - ); + return this._client.getUserPersistentMenu(this._session.user.id); } async setUserPersistentMenu( attrs: MessengerTypes.PersistentMenu, - options: MessengerTypes.SendOption = {} + options: { + composerInputDisabled?: boolean; + } = {} ): Promise { if (!this._session) { warning( @@ -257,13 +251,13 @@ class MessengerContext extends Context { return this._client.setUserPersistentMenu( this._session.user.id, attrs, - this._getMethodOptions(options) + options ); } - async deleteUserPersistentMenu( - options: MessengerTypes.SendOption = {} - ): Promise { + async deleteUserPersistentMenu(): Promise< + MessengerTypes.MutationSuccessResponse | undefined + > { if (!this._session) { warning( false, @@ -276,15 +270,12 @@ class MessengerContext extends Context { return this._batchQueue.push( MessengerBatch.deleteUserPersistentMenu( this._session.user.id, - this._getMethodOptions(options) + this._getMethodOptions({}) ) ); } - return this._client.deleteUserPersistentMenu( - this._session.user.id, - this._getMethodOptions(options) - ); + return this._client.deleteUserPersistentMenu(this._session.user.id); } /** @@ -383,9 +374,9 @@ class MessengerContext extends Context { /** * https://github.com/Yoctol/messaging-apis/tree/master/packages/messaging-api-messenger#markseenuserid */ - async markSeen( - options: MessengerTypes.SendOption = {} - ): Promise { + async markSeen(): Promise< + MessengerTypes.SendSenderActionResponse | undefined + > { if (!this._session) { warning( false, @@ -398,14 +389,12 @@ class MessengerContext extends Context { return this._batchQueue.push( MessengerBatch.markSeen( this._session.user.id, - this._getSenderActionMethodOptions(options) + // FIXME: this type should be fixed in MessengerBatch + this._getMethodOptions({}) as any ) ); } - return this._client.markSeen( - this._session.user.id, - this._getSenderActionMethodOptions(options) - ); + return this._client.markSeen(this._session.user.id); } /** @@ -442,8 +431,7 @@ class MessengerContext extends Context { return this._client.passThreadControl( this._session.user.id, targetAppId, - metadata, - this._getMethodOptions({}) + metadata ); } @@ -472,8 +460,7 @@ class MessengerContext extends Context { } return this._client.passThreadControlToPageInbox( this._session.user.id, - metadata, - this._getMethodOptions({}) + metadata ); } @@ -500,11 +487,7 @@ class MessengerContext extends Context { ) ); } - return this._client.takeThreadControl( - this._session.user.id, - metadata, - this._getMethodOptions({}) - ); + return this._client.takeThreadControl(this._session.user.id, metadata); } /** @@ -530,11 +513,7 @@ class MessengerContext extends Context { ) ); } - return this._client.requestThreadControl( - this._session.user.id, - metadata, - this._getMethodOptions({}) - ); + return this._client.requestThreadControl(this._session.user.id, metadata); } /** @@ -557,10 +536,7 @@ class MessengerContext extends Context { ) ); } - return this._client.getThreadOwner( - this._session.user.id, - this._getMethodOptions({}) - ); + return this._client.getThreadOwner(this._session.user.id); } async isThreadOwner(): Promise { @@ -608,11 +584,7 @@ class MessengerContext extends Context { ) ); } - return this._client.associateLabel( - this._session.user.id, - labelId, - this._getMethodOptions({}) - ); + return this._client.associateLabel(this._session.user.id, labelId); } /** @@ -638,11 +610,7 @@ class MessengerContext extends Context { ) ); } - return this._client.dissociateLabel( - this._session.user.id, - labelId, - this._getMethodOptions({}) - ); + return this._client.dissociateLabel(this._session.user.id, labelId); } /** @@ -690,10 +658,7 @@ class MessengerContext extends Context { ) ); } - return this._client.getAssociatedLabels( - this._session.user.id, - this._getMethodOptions({}) - ); + return this._client.getAssociatedLabels(this._session.user.id); } async sendMessage( diff --git a/packages/bottender/src/messenger/__tests__/MessengerConnector.spec.ts b/packages/bottender/src/messenger/__tests__/MessengerConnector.spec.ts index 8a7169c59..220d70326 100644 --- a/packages/bottender/src/messenger/__tests__/MessengerConnector.spec.ts +++ b/packages/bottender/src/messenger/__tests__/MessengerConnector.spec.ts @@ -300,9 +300,7 @@ describe('#updateSession', () => { const session = {}; await connector.updateSession(session, request); - expect(client.getUserProfile).toBeCalledWith('1412611362105802', { - accessToken: undefined, - }); + expect(client.getUserProfile).toBeCalledWith('1412611362105802'); expect(session).toEqual({ page: { _updatedAt: expect.any(String), @@ -337,9 +335,7 @@ describe('#updateSession', () => { }; await connector.updateSession(session, request); - expect(client.getUserProfile).toBeCalledWith('1412611362105802', { - accessToken: undefined, - }); + expect(client.getUserProfile).toBeCalledWith('1412611362105802'); expect(session).toEqual({ page: { _updatedAt: expect.any(String), @@ -374,9 +370,7 @@ describe('#updateSession', () => { }; await connector.updateSession(session, request); - expect(client.getUserProfile).toBeCalledWith('1412611362105802', { - accessToken: undefined, - }); + expect(client.getUserProfile).toBeCalledWith('1412611362105802'); expect(session).toEqual({ page: { _updatedAt: expect.any(String), @@ -411,9 +405,7 @@ describe('#updateSession', () => { }; await connector.updateSession(session, request); - expect(client.getUserProfile).toBeCalledWith('1412611362105802', { - accessToken: undefined, - }); + expect(client.getUserProfile).toBeCalledWith('1412611362105802'); expect(session).toEqual({ page: { _updatedAt: expect.any(String), @@ -437,9 +429,7 @@ describe('#updateSession', () => { const session = {}; await connector.updateSession(session, request); - expect(client.getUserProfile).toBeCalledWith('1412611362105802', { - accessToken: undefined, - }); + expect(client.getUserProfile).toBeCalledWith('1412611362105802'); expect(session).toEqual({ page: { _updatedAt: expect.any(String), diff --git a/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts b/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts index f82835636..9e2d484ac 100644 --- a/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts +++ b/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts @@ -37,7 +37,7 @@ const setup = ( } ) => { const client = new MessengerClient({ - accessToken: ACCESS_TOKEN, + accessToken: customAccessToken ?? ACCESS_TOKEN, appSecret: APP_SECRET, }); const args = { @@ -496,26 +496,7 @@ describe('#sendSenderAction', () => { expect(client.sendSenderAction).toBeCalledWith( session.user.id, 'typing_on', - { - accessToken: undefined, - } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.sendSenderAction('typing_on'); - - expect(client.sendSenderAction).toBeCalledWith( - session.user.id, - 'typing_on', - { - accessToken: 'anyToken', - } + {} ); }); @@ -538,22 +519,7 @@ describe('#typingOn', () => { await context.typingOn(); - expect(client.typingOn).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.typingOn(); - - expect(client.typingOn).toBeCalledWith(session.user.id, { - accessToken: 'anyToken', - }); + expect(client.typingOn).toBeCalledWith(session.user.id, {}); }); it('should call warning and not to send if dont have session', async () => { @@ -575,22 +541,7 @@ describe('#typingOff', () => { await context.typingOff(); - expect(client.typingOff).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.typingOff(); - - expect(client.typingOff).toBeCalledWith(session.user.id, { - accessToken: 'anyToken', - }); + expect(client.typingOff).toBeCalledWith(session.user.id, {}); }); it('should call warning and not to send if dont have session', async () => { @@ -612,22 +563,7 @@ describe('#markSeen', () => { await context.markSeen(); - expect(client.markSeen).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.markSeen(); - - expect(client.markSeen).toBeCalledWith(session.user.id, { - accessToken: 'anyToken', - }); + expect(client.markSeen).toBeCalledWith(session.user.id); }); it('should call warning and not to send if dont have session', async () => { diff --git a/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts b/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts index 2e130756c..35c283533 100644 --- a/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts +++ b/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts @@ -38,7 +38,7 @@ const setup = ( } ) => { const client = new MessengerClient({ - accessToken: ACCESS_TOKEN, + accessToken: customAccessToken ?? ACCESS_TOKEN, appSecret: APP_SECRET, }); diff --git a/packages/bottender/src/messenger/__tests__/MessengerContext.spec.ts b/packages/bottender/src/messenger/__tests__/MessengerContext.spec.ts index 8cfd09aca..cfa1774fe 100644 --- a/packages/bottender/src/messenger/__tests__/MessengerContext.spec.ts +++ b/packages/bottender/src/messenger/__tests__/MessengerContext.spec.ts @@ -36,7 +36,9 @@ const setup = ( defaultRawEvent, } ) => { - const client = new MessengerClient(); + const client = new MessengerClient({ + accessToken: customAccessToken ?? '', + }); const args = { appId: APP_ID, client, @@ -73,7 +75,7 @@ it('get #client works', () => { }); describe('#getUserProfile', () => { - it('should call client sendSenderAction', async () => { + it('should call client getUserProfile', async () => { const { context, client, session } = setup(); const user = { @@ -88,9 +90,7 @@ describe('#getUserProfile', () => { const result = await context.getUserProfile(); - expect(client.getUserProfile).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); + expect(client.getUserProfile).toBeCalledWith(session.user.id, {}); expect(result).toEqual(user); }); @@ -134,31 +134,6 @@ describe('#getUserProfile', () => { 'timezone', 'gender', ], - accessToken: undefined, - }); - expect(result).toEqual(user); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - const user = { - id: session.user.id, - name: 'Kevin Durant', - firstName: 'Kevin', - lastName: 'Durant', - profilePic: 'https://example.com/pic.png', - }; - - mocked(client.getUserProfile).mockResolvedValue(user); - - const result = await context.getUserProfile(); - - expect(client.getUserProfile).toBeCalledWith(session.user.id, { - accessToken: 'anyToken', }); expect(result).toEqual(user); }); @@ -204,9 +179,7 @@ describe('Persistent Menu', () => { const result = await context.getUserPersistentMenu(); - expect(client.getUserPersistentMenu).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); + expect(client.getUserPersistentMenu).toBeCalledWith(session.user.id); expect(result).toEqual(persistentMenu); }); @@ -251,9 +224,7 @@ describe('Persistent Menu', () => { expect(client.setUserPersistentMenu).toBeCalledWith( session.user.id, persistentMenu, - { - accessToken: undefined, - } + {} ); expect(result).toBeUndefined(); @@ -278,9 +249,7 @@ describe('Persistent Menu', () => { const result = await context.deleteUserPersistentMenu(); - expect(client.deleteUserPersistentMenu).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); + expect(client.deleteUserPersistentMenu).toBeCalledWith(session.user.id); expect(result).toBeUndefined(); }); @@ -308,28 +277,7 @@ describe('#passThreadControl', () => { expect(client.passThreadControl).toBeCalledWith( session.user.id, 263902037430900, - 'metadata', - { - accessToken: undefined, - } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.passThreadControl(263902037430900, 'metadata'); - - expect(client.passThreadControl).toBeCalledWith( - session.user.id, - 263902037430900, - 'metadata', - { - accessToken: 'anyToken', - } + 'metadata' ); }); @@ -354,27 +302,7 @@ describe('#passThreadControlToPageInbox', () => { expect(client.passThreadControlToPageInbox).toBeCalledWith( session.user.id, - 'metadata', - { - accessToken: undefined, - } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.passThreadControlToPageInbox(); - - expect(client.passThreadControlToPageInbox).toBeCalledWith( - session.user.id, - undefined, - { - accessToken: 'anyToken', - } + 'metadata' ); }); @@ -399,27 +327,7 @@ describe('#takeThreadControl', () => { expect(client.takeThreadControl).toBeCalledWith( session.user.id, - 'metadata', - { - accessToken: undefined, - } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.takeThreadControl('metadata'); - - expect(client.takeThreadControl).toBeCalledWith( - session.user.id, - 'metadata', - { - accessToken: 'anyToken', - } + 'metadata' ); }); @@ -444,27 +352,7 @@ describe('#requestThreadControl', () => { expect(client.requestThreadControl).toBeCalledWith( session.user.id, - 'metadata', - { - accessToken: undefined, - } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.requestThreadControl('metadata'); - - expect(client.requestThreadControl).toBeCalledWith( - session.user.id, - 'metadata', - { - accessToken: 'anyToken', - } + 'metadata' ); }); @@ -487,22 +375,7 @@ describe('#getThreadOwner', () => { await context.getThreadOwner(); - expect(client.getThreadOwner).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.getThreadOwner(); - - expect(client.getThreadOwner).toBeCalledWith(session.user.id, { - accessToken: 'anyToken', - }); + expect(client.getThreadOwner).toBeCalledWith(session.user.id); }); it('should call warning if dont have session', async () => { @@ -544,23 +417,7 @@ describe('#associateLabel', () => { expect(client.associateLabel).toBeCalledWith( session.user.id, - 1712444532121303, - { accessToken: undefined } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.associateLabel(1712444532121303); - - expect(client.associateLabel).toBeCalledWith( - session.user.id, - 1712444532121303, - { accessToken: 'anyToken' } + 1712444532121303 ); }); @@ -585,23 +442,7 @@ describe('#dissociateLabel', () => { expect(client.dissociateLabel).toBeCalledWith( session.user.id, - 1712444532121303, - { accessToken: undefined } - ); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - await context.dissociateLabel(1712444532121303); - - expect(client.dissociateLabel).toBeCalledWith( - session.user.id, - 1712444532121303, - { accessToken: 'anyToken' } + 1712444532121303 ); }); @@ -645,43 +486,7 @@ describe('#getAssociatedLabels', () => { await context.getAssociatedLabels(); - expect(client.getAssociatedLabels).toBeCalledWith(session.user.id, { - accessToken: undefined, - }); - }); - - it('should use custom access token', async () => { - const { context, client, session } = setup({ - session: userSession, - customAccessToken: 'anyToken', - }); - - client.getAssociatedLabels.mockReturnValue({ - data: [ - { - name: 'myLabel', - id: '1001200005003', - }, - { - name: 'myOtherLabel', - id: '1001200005002', - }, - ], - paging: { - cursors: { - before: - 'QVFIUmx1WTBpMGpJWXprYzVYaVhabW55dVpycko4U2xURGE5ODNtNFZAPal94a1hTUnNVMUtoMVVoTzlzSDktUkMtQkUzWEFLSXlMS3ZALYUw3TURLelZAPOGVR', - after: - 'QVFIUmItNkpTbjVzakxFWGRydzdaVUFNNnNPaUl0SmwzVHN5ZAWZAEQ3lZANDAzTXFIM0NHbHdYSkQ5OG1GaEozdjkzRmxpUFhxTDl4ZAlBibnE4LWt1eGlTa3Bn', - }, - }, - }); - - await context.getAssociatedLabels(); - - expect(client.getAssociatedLabels).toBeCalledWith(session.user.id, { - accessToken: 'anyToken', - }); + expect(client.getAssociatedLabels).toBeCalledWith(session.user.id); }); it('should call warning if dont have session', async () => { @@ -703,17 +508,10 @@ describe('persona', () => { const { context, client, session } = setup(); context.usePersona(PERSONA_ID); - await context.markSeen(); await context.typingOn(); await context.typingOff(); await context.sendText('hi'); - expect(client.markSeen).toBeCalledWith( - session.user.id, - expect.objectContaining({ - personaId: PERSONA_ID, - }) - ); expect(client.typingOn).toBeCalledWith( session.user.id, expect.objectContaining({ @@ -740,17 +538,10 @@ describe('persona', () => { it('should call API with personaId', async () => { const { context, client, session } = setup(); - await context.markSeen({ personaId: PERSONA_ID }); await context.typingOn({ personaId: PERSONA_ID }); await context.typingOff({ personaId: PERSONA_ID }); await context.sendText('hi', { personaId: PERSONA_ID }); - expect(client.markSeen).toBeCalledWith( - session.user.id, - expect.objectContaining({ - personaId: PERSONA_ID, - }) - ); expect(client.typingOn).toBeCalledWith( session.user.id, expect.objectContaining({ diff --git a/yarn.lock b/yarn.lock index 1c6beabdb..1bfc3e33c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2917,7 +2917,7 @@ axios@^0.19.2: dependencies: follow-redirects "1.5.10" -axios@^0.21.1: +axios@^0.21.1, axios@^0.21.4: version "0.21.4" resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg== @@ -4997,14 +4997,6 @@ extsprintf@^1.2.0: resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8= -facebook-batch@1.0.0-beta.32: - version "1.0.0-beta.32" - resolved "https://registry.yarnpkg.com/facebook-batch/-/facebook-batch-1.0.0-beta.32.tgz#e60316f81e31d3ea4d87d4cc56ebd43c8780a412" - integrity sha512-DI4Uezes+f8s/HDLdE7QGQrWoCEmdBXprcGzbQewQJKfQd1W8IofGeKHbfQxMEkzoS4Ob+t6nJtdip8cEOV7GQ== - dependencies: - messaging-api-messenger "^1.0.0-beta.31" - type-fest "^0.15.1" - facebook-batch@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/facebook-batch/-/facebook-batch-1.0.6.tgz#38ad1a45a941787a8e73e2ebd78e625eab991ef6" @@ -7872,24 +7864,7 @@ merge2@^1.3.0: resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== -messaging-api-common@1.0.0-beta.29, messaging-api-common@^1.0.0-beta.29: - version "1.0.0-beta.29" - resolved "https://registry.yarnpkg.com/messaging-api-common/-/messaging-api-common-1.0.0-beta.29.tgz#70e1fb149a81b04f675c41a5e4aa8b1850507309" - integrity sha512-kR4aEx4qN9DkqmDV6s0xsnHkI8QwrvlKZhZ2ivgjoofGB/lAFhYsv4e5gTUEiaxo6c6L2fh3iU+9qYMYKO/nWw== - dependencies: - "@types/debug" "^4.1.5" - "@types/lodash" "^4.14.156" - "@types/url-join" "^4.0.0" - axios "^0.19.2" - camel-case "^4.1.1" - debug "^4.1.1" - lodash "^4.17.15" - map-obj "^4.1.0" - pascal-case "^3.1.1" - snake-case "^3.0.3" - url-join "^4.0.1" - -messaging-api-common@^1.0.4: +messaging-api-common@1.0.4, messaging-api-common@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/messaging-api-common/-/messaging-api-common-1.0.4.tgz#793d5cca5e97793ecaea238ff61bd901cfffac56" integrity sha512-riYl+FnUtbUxxBfmUXBZSw4akK9hWAGGobulT81DK4Y5s/zeCKQcwa5uKHLG5HrR0RCtATIj7tQM8J29z61jRg== @@ -7906,55 +7881,21 @@ messaging-api-common@^1.0.4: snake-case "^3.0.3" url-join "^4.0.1" -messaging-api-line@1.0.0-beta.33: - version "1.0.0-beta.33" - resolved "https://registry.yarnpkg.com/messaging-api-line/-/messaging-api-line-1.0.0-beta.33.tgz#dab867e25f74d24d61b71a11841a49499ac5032d" - integrity sha512-gvCmv1T9ExMIjMlr9CecREUrgUscDI+tmEJP6NlZx5Ly7fCKUrpToNT/N8eFKxjoQ85YTSnXupazXSklpclExA== +messaging-api-line@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/messaging-api-line/-/messaging-api-line-1.0.6.tgz#e723e838726652ee513ee6caf400632575169f0c" + integrity sha512-RlJTonApLF4X4zR//9l0+cjCfrxng9InqHGZPya5Afr6PhGmLttzjOFkGVLE5uOM/RpiivciylueAay2tBu9Gw== dependencies: "@types/warning" "^3.0.0" - axios "^0.19.2" - axios-error "^1.0.0-beta.27" + axios "^0.21.1" + axios-error "^1.0.4" image-type "^4.1.0" - messaging-api-common "^1.0.0-beta.29" + messaging-api-common "^1.0.4" ts-invariant "^0.4.4" type-fest "^0.15.1" warning "^4.0.3" -messaging-api-messenger@1.0.0-beta.33: - version "1.0.0-beta.33" - resolved "https://registry.yarnpkg.com/messaging-api-messenger/-/messaging-api-messenger-1.0.0-beta.33.tgz#8856d174a400fa1401afb9f7aef8aba53a216189" - integrity sha512-iGIUzaqRaddt+Wt7mz5hyo/5dQaq0WHkEDoSRctVmYnEyIgZtyvIVsxOp9RKWPY4U5KDjkMwLjgt7y8/TD8ttQ== - dependencies: - "@types/append-query" "^2.0.0" - "@types/lodash" "^4.14.156" - "@types/warning" "^3.0.0" - append-query "^2.1.0" - axios "^0.19.2" - axios-error "^1.0.0-beta.27" - form-data "^3.0.0" - lodash "^4.17.15" - messaging-api-common "^1.0.0-beta.29" - ts-invariant "^0.4.4" - warning "^4.0.3" - -messaging-api-messenger@^1.0.0-beta.31: - version "1.0.0-beta.31" - resolved "https://registry.yarnpkg.com/messaging-api-messenger/-/messaging-api-messenger-1.0.0-beta.31.tgz#1bb2db861df7c2310d70b93bdc853f35af481f4d" - integrity sha512-UWe9vjOKAO2w3MGW53ZJAmml4bS8UsnH20C10xVm35WJufAjWvoVu8/PkEhhn7c2X3P3OHNuBxgt+/EY0z4wFw== - dependencies: - "@types/append-query" "^2.0.0" - "@types/lodash" "^4.14.156" - "@types/warning" "^3.0.0" - append-query "^2.1.0" - axios "^0.19.2" - axios-error "^1.0.0-beta.27" - form-data "^3.0.0" - lodash "^4.17.15" - messaging-api-common "^1.0.0-beta.29" - ts-invariant "^0.4.4" - warning "^4.0.3" - -messaging-api-messenger@^1.0.6: +messaging-api-messenger@1.0.6, messaging-api-messenger@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/messaging-api-messenger/-/messaging-api-messenger-1.0.6.tgz#606209b615dd539d82ec5b6e813b2a2dfea47585" integrity sha512-yLrUGMF5v/PHMtEbfB62C70bqHsL9L9XGGA1v/GCJQeyjS4OWmSXOJTwDUm31chuppWaYx4br7WkxGM8UCDCfQ== @@ -7971,42 +7912,43 @@ messaging-api-messenger@^1.0.6: ts-invariant "^0.4.4" warning "^4.0.3" -messaging-api-slack@1.0.0-beta.33: - version "1.0.0-beta.33" - resolved "https://registry.yarnpkg.com/messaging-api-slack/-/messaging-api-slack-1.0.0-beta.33.tgz#b03e9672f6db866deebaab535692da6fa2c40bc6" - integrity sha512-oKPbsK87EDfMWsUVNZvFEdfpBxfu2b0PQ/HyAFTBFmcYgp2h/tEYLS7ocAiZ5LSXCR/3Y0W7KgCA9BlPnh+gEA== +messaging-api-slack@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/messaging-api-slack/-/messaging-api-slack-1.0.6.tgz#26328c03c70d53ac2ef483bba0029e4bb809e166" + integrity sha512-A49Z+64mHhj42m+MwZiHjFti5A2nZtCv+DCgxQdBSKcG4oXwb3hHcXr0LNCuZBCPVJz+1XszGvHKf+LZy3+K5Q== dependencies: "@types/lodash" "^4.14.156" "@types/warning" "^3.0.0" - axios "^0.19.2" - axios-error "^1.0.0-beta.27" + axios "^0.21.1" + axios-error "^1.0.4" lodash "^4.17.15" - messaging-api-common "^1.0.0-beta.29" + messaging-api-common "^1.0.4" ts-invariant "^0.4.4" + warning "^4.0.3" -messaging-api-telegram@1.0.0-beta.33: - version "1.0.0-beta.33" - resolved "https://registry.yarnpkg.com/messaging-api-telegram/-/messaging-api-telegram-1.0.0-beta.33.tgz#dbf67e7e34cae9c5ea126f363214e2a66d6d13bd" - integrity sha512-naE0DgYYdZOfkDMxDdEnDfUomzNB0TkOKS09YkpTVKjUCeB3JJenXfEtVqqk8digfxuDo9C9KdFLiPCZ1jW4uQ== +messaging-api-telegram@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/messaging-api-telegram/-/messaging-api-telegram-1.0.6.tgz#16aeb10ec60ee28b2f934787089cc4af4de911ae" + integrity sha512-DX2R1DcnSx4fLvlGAJliSJjixhIaZdXigCtamuBSuNHPIW75WDoOgNtJekK2sJlNW6+Us3wppkkxlg/IukNn/Q== dependencies: "@types/lodash" "^4.14.156" "@types/warning" "^3.0.0" - axios "^0.19.2" - axios-error "^1.0.0-beta.27" + axios "^0.21.1" + axios-error "^1.0.4" lodash "^4.17.15" - messaging-api-common "^1.0.0-beta.29" + messaging-api-common "^1.0.4" ts-invariant "^0.4.4" warning "^4.0.3" -messaging-api-viber@1.0.0-beta.33: - version "1.0.0-beta.33" - resolved "https://registry.yarnpkg.com/messaging-api-viber/-/messaging-api-viber-1.0.0-beta.33.tgz#7a9f1cfffe99f32b23f60a4f24daf5121bc7228a" - integrity sha512-cGxVaHjyXsHDtiHzgzuqYT4IvoTZ7JvlNzQK+7h1J6k3niyb1UQwjd8uC1dcpB86nO9/P98c7OarkY+TbAk0QA== +messaging-api-viber@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/messaging-api-viber/-/messaging-api-viber-1.0.6.tgz#d796a5cc78750e6c9e86fb7d463013ea00664bee" + integrity sha512-e2U72f5L8bPcubRfX4V1mRbL0d/sdxBxpbptNv3gV70K1diSv2kPXWfiDziMojYQ/Ob66SMR4354iHlm8qWXaw== dependencies: "@types/warning" "^3.0.0" - axios "^0.19.2" - axios-error "^1.0.0-beta.27" - messaging-api-common "^1.0.0-beta.29" + axios "^0.21.1" + axios-error "^1.0.4" + messaging-api-common "^1.0.4" ts-invariant "^0.4.4" warning "^4.0.3"