From 2de9e12692934ae47830b428046674ebcde70480 Mon Sep 17 00:00:00 2001 From: chentsulin Date: Mon, 13 Jan 2020 18:41:37 +0800 Subject: [PATCH] feat(Context): add context.setAsHandled() and context.setAsNotHandled() --- packages/bottender-dialogflow/src/index.ts | 3 + packages/bottender-luis/src/index.ts | 3 + packages/bottender-qna-maker/src/index.ts | 3 + packages/bottender-rasa/src/index.ts | 3 + .../bottender/src/console/ConsoleContext.ts | 2 - .../console/__tests__/ConsoleContext.spec.ts | 16 - packages/bottender/src/context/Context.ts | 20 +- .../src/context/__tests__/Context.spec.ts | 40 ++ packages/bottender/src/line/LineContext.ts | 6 - .../src/line/__tests__/LineContext.spec.ts | 36 -- .../src/messenger/MessengerContext.ts | 19 - .../__tests__/MessengerContext-send.spec.ts | 85 ---- .../MessengerContext-sendTemplate.spec.ts | 81 ---- packages/bottender/src/slack/SlackContext.ts | 26 -- .../src/slack/__tests__/SlackContext.spec.ts | 16 - .../bottender/src/telegram/TelegramContext.ts | 86 ---- .../__tests__/TelegramContext.spec.ts | 385 ------------------ packages/bottender/src/viber/ViberContext.ts | 20 - .../src/viber/__tests__/ViberContext.spec.ts | 91 ----- 19 files changed, 70 insertions(+), 871 deletions(-) diff --git a/packages/bottender-dialogflow/src/index.ts b/packages/bottender-dialogflow/src/index.ts index 0fe30b7f1..2808d56fc 100644 --- a/packages/bottender-dialogflow/src/index.ts +++ b/packages/bottender-dialogflow/src/index.ts @@ -59,6 +59,9 @@ module.exports = function dialogflow({ if (intent) { context.setIntent(intent.displayName); + context.setAsHandled(); + } else { + context.setAsNotHandled(); } const Action = actions[intent.name] || actions[intent.displayName]; diff --git a/packages/bottender-luis/src/index.ts b/packages/bottender-luis/src/index.ts index 2b648af65..5de5577f2 100644 --- a/packages/bottender-luis/src/index.ts +++ b/packages/bottender-luis/src/index.ts @@ -75,6 +75,7 @@ module.exports = function luis({ if (topScoringIntent && topScoringIntent.score > scoreThreshold) { context.setIntent(topScoringIntent.intent); + context.setAsHandled(); const Action = actions[topScoringIntent.intent]; @@ -85,6 +86,8 @@ module.exports = function luis({ sentimentAnalysis, }); } + } else { + context.setAsNotHandled(); } return next; diff --git a/packages/bottender-qna-maker/src/index.ts b/packages/bottender-qna-maker/src/index.ts index 7f696c648..511e19886 100644 --- a/packages/bottender-qna-maker/src/index.ts +++ b/packages/bottender-qna-maker/src/index.ts @@ -71,6 +71,9 @@ module.exports = function qnaMaker({ return async function TopAnswer() { if (topAnswer.id !== -1) { context.setIntent(`qna_${topAnswer.id}`); + context.setAsHandled(); + } else { + context.setAsNotHandled(); } await context.sendText(topAnswer.answer); diff --git a/packages/bottender-rasa/src/index.ts b/packages/bottender-rasa/src/index.ts index beaabf651..65dff2d8f 100644 --- a/packages/bottender-rasa/src/index.ts +++ b/packages/bottender-rasa/src/index.ts @@ -55,11 +55,14 @@ module.exports = function rasa({ if (intent && intent.confidence > confidenceThreshold) { context.setIntent(intent.name); + context.setAsHandled(); const Action = actions[intent.name]; if (Action) { return withProps(Action as any, { intent, entities }); } + } else { + context.setAsNotHandled(); } return next; diff --git a/packages/bottender/src/console/ConsoleContext.ts b/packages/bottender/src/console/ConsoleContext.ts index 43b943921..b4f42299f 100644 --- a/packages/bottender/src/console/ConsoleContext.ts +++ b/packages/bottender/src/console/ConsoleContext.ts @@ -91,7 +91,6 @@ export default class ConsoleContext extends Context< * */ async sendText(text: string, ...args: any[]): Promise { - this._isHandled = true; if (args.length > 0 && this._fallbackMethods) { this._client.sendText( `${text}\nwith other args:\n${JSON.stringify(args, null, 2)}` @@ -102,7 +101,6 @@ export default class ConsoleContext extends Context< } async _methodMissing(method: string, args: any[]): Promise { - this._isHandled = true; this._client.sendText( `${method} with args:\n${JSON.stringify(args, null, 2)}` ); diff --git a/packages/bottender/src/console/__tests__/ConsoleContext.spec.ts b/packages/bottender/src/console/__tests__/ConsoleContext.spec.ts index 051a972c4..244129231 100644 --- a/packages/bottender/src/console/__tests__/ConsoleContext.spec.ts +++ b/packages/bottender/src/console/__tests__/ConsoleContext.spec.ts @@ -86,14 +86,6 @@ describe('#sendText', () => { expect(client.sendText).toBeCalledWith('hello'); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendText('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should support fallbackMethods with other args', async () => { const { context, client } = setup({ fallbackMethods: true }); @@ -131,14 +123,6 @@ describe('method missing', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup({ fallbackMethods: true }); - - await context.sendABC('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should not proxy blacklisted methods', async () => { const { context } = setup({ fallbackMethods: true }); diff --git a/packages/bottender/src/context/Context.ts b/packages/bottender/src/context/Context.ts index 89e3709fc..1f32238a4 100644 --- a/packages/bottender/src/context/Context.ts +++ b/packages/bottender/src/context/Context.ts @@ -34,7 +34,7 @@ export default abstract class Context { // eslint-disable-next-line @typescript-eslint/no-explicit-any abstract sendText(text: string, options?: Record): any; - _isHandled = false; + _isHandled: boolean | null = null; _isSessionWritten = false; @@ -117,7 +117,7 @@ export default abstract class Context { return this._session; } - get isHandled(): boolean { + get isHandled(): boolean | null { return this._isHandled; } @@ -205,6 +205,22 @@ export default abstract class Context { this._intent = intent; } + /** + * Set the conversation context as handled or not handled by boolean. + * + */ + setAsHandled(handled = true) { + this._isHandled = handled; + } + + /** + * Set the conversation context as not handled. + * + */ + setAsNotHandled() { + this.setAsHandled(false); + } + emitError(err: Error): void { if (this._emitter) { this._emitter.emit('error', err, this); diff --git a/packages/bottender/src/context/__tests__/Context.spec.ts b/packages/bottender/src/context/__tests__/Context.spec.ts index da09cb5d0..14aaf5d24 100644 --- a/packages/bottender/src/context/__tests__/Context.spec.ts +++ b/packages/bottender/src/context/__tests__/Context.spec.ts @@ -24,3 +24,43 @@ describe('intent', () => { expect(context.intent).toEqual('hello-world'); }); }); + +describe('handled', () => { + it('should default to null', () => { + const context = new TestContext({ client: {}, event: {} }); + + expect(context.isHandled).toBeNull(); + }); + + it('should be true after calling context.setAsHandled()', () => { + const context = new TestContext({ client: {}, event: {} }); + + context.setAsHandled(); + + expect(context.isHandled).toEqual(true); + }); + + it('should be true after calling context.setAsHandled(true)', () => { + const context = new TestContext({ client: {}, event: {} }); + + context.setAsHandled(true); + + expect(context.isHandled).toEqual(true); + }); + + it('should be false after calling context.setAsHandled(false)', () => { + const context = new TestContext({ client: {}, event: {} }); + + context.setAsHandled(false); + + expect(context.isHandled).toEqual(false); + }); + + it('should be false after calling context.setAsNotHandled()', () => { + const context = new TestContext({ client: {}, event: {} }); + + context.setAsNotHandled(); + + expect(context.isHandled).toEqual(false); + }); +}); diff --git a/packages/bottender/src/line/LineContext.ts b/packages/bottender/src/line/LineContext.ts index 60253512b..3d0a1d607 100644 --- a/packages/bottender/src/line/LineContext.ts +++ b/packages/bottender/src/line/LineContext.ts @@ -179,14 +179,12 @@ class LineContext extends Context { switch (this._session.type) { case 'room': - this._isHandled = true; return this._client.leaveRoom(this._session.room.id, { ...(this._customAccessToken ? { accessToken: this._customAccessToken } : undefined), } as any); case 'group': - this._isHandled = true; return this._client.leaveGroup(this._session.group.id, { ...(this._customAccessToken ? { accessToken: this._customAccessToken } @@ -446,8 +444,6 @@ class LineContext extends Context { reply(messages: LineTypes.Message[], options: LineTypes.MessageOptions = {}) { invariant(!this._isReplied, 'Can not reply event multiple times'); - this._isHandled = true; - if (this._shouldBatch) { this._replyMessages.push(...messages); @@ -614,8 +610,6 @@ class LineContext extends Context { return; } - this._isHandled = true; - if (this._shouldBatch) { this._pushMessages.push(...messages); return; diff --git a/packages/bottender/src/line/__tests__/LineContext.spec.ts b/packages/bottender/src/line/__tests__/LineContext.spec.ts index 579697164..71129ec43 100644 --- a/packages/bottender/src/line/__tests__/LineContext.spec.ts +++ b/packages/bottender/src/line/__tests__/LineContext.spec.ts @@ -189,7 +189,6 @@ describe('#leave', () => { expect(client.leaveGroup).not.toBeCalled(); expect(client.leaveRoom).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); it('leave group', async () => { @@ -198,7 +197,6 @@ describe('#leave', () => { await context.leave(); expect(client.leaveGroup).toBeCalledWith('fakeGroupId', {}); - expect(context.isHandled).toBe(true); }); it('leave room', async () => { @@ -207,7 +205,6 @@ describe('#leave', () => { await context.leave(); expect(client.leaveRoom).toBeCalledWith('fakeRoomId', {}); - expect(context.isHandled).toBe(true); }); it('not leave user', async () => { @@ -218,7 +215,6 @@ describe('#leave', () => { expect(client.leaveGroup).not.toBeCalled(); expect(client.leaveRoom).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); }); @@ -321,14 +317,6 @@ describe('#replyText', () => { expect(error.message).toEqual('Can not reply event multiple times'); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.replyText('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should support custom token', async () => { const { context, client } = setup({ customAccessToken: 'anyToken', @@ -457,14 +445,6 @@ describe('#pushText', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.pushText('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -513,14 +493,6 @@ describe('send APIs', () => { {} ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.send([Line.createText('2'), Line.createText('3')]); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendText', () => { @@ -1329,7 +1301,6 @@ describe('profile APIs', () => { expect(client.getGroupMemberProfile).not.toBeCalled(); expect(client.getRoomMemberProfile).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); it('not get profile without user in session', async () => { @@ -1349,7 +1320,6 @@ describe('profile APIs', () => { expect(client.getGroupMemberProfile).not.toBeCalled(); expect(client.getRoomMemberProfile).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); it('get user profile in group', async () => { @@ -1394,7 +1364,6 @@ describe('profile APIs', () => { expect(client.getGroupMemberProfile).not.toBeCalled(); expect(client.getRoomMemberProfile).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); it('get member profile in group', async () => { @@ -1429,7 +1398,6 @@ describe('profile APIs', () => { expect(client.getGroupMemberProfile).not.toBeCalled(); expect(client.getRoomMemberProfile).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); }); }); @@ -1444,7 +1412,6 @@ describe('member IDs APIs', () => { expect(client.getRoomMemberIds).not.toBeCalled(); expect(client.getGroupMemberIds).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); it('get memeber ids in group', async () => { @@ -1479,7 +1446,6 @@ describe('member IDs APIs', () => { expect(client.getRoomMemberIds).not.toBeCalled(); expect(client.getGroupMemberIds).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); }); @@ -1492,7 +1458,6 @@ describe('member IDs APIs', () => { expect(client.getAllRoomMemberIds).not.toBeCalled(); expect(client.getAllGroupMemberIds).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); it('get memeber ids in group', async () => { @@ -1519,7 +1484,6 @@ describe('member IDs APIs', () => { expect(client.getAllRoomMemberIds).not.toBeCalled(); expect(client.getAllGroupMemberIds).not.toBeCalled(); expect(warning).toBeCalled(); - expect(context.isHandled).toBe(false); }); }); }); diff --git a/packages/bottender/src/messenger/MessengerContext.ts b/packages/bottender/src/messenger/MessengerContext.ts index e59d79e77..034110af6 100644 --- a/packages/bottender/src/messenger/MessengerContext.ts +++ b/packages/bottender/src/messenger/MessengerContext.ts @@ -123,8 +123,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const messagingType = options && 'tag' in options ? 'MESSAGE_TAG' : 'RESPONSE'; @@ -189,8 +187,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, senderAction, @@ -218,8 +214,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, { @@ -246,8 +240,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, { @@ -274,8 +266,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, { @@ -311,8 +301,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, targetAppId, @@ -339,8 +327,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, metadata, @@ -366,8 +352,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, metadata, @@ -393,8 +377,6 @@ class MessengerContext extends Context { return; } - this._isHandled = true; - const args = [ this._session.user.id, metadata, @@ -563,7 +545,6 @@ sendMethods.forEach(([method, arity]) => { ); return; } - this._isHandled = true; const options = args[arity - 2]; const messagingType = options && options.tag ? 'MESSAGE_TAG' : 'RESPONSE'; diff --git a/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts b/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts index 65824aa41..ef735d471 100644 --- a/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts +++ b/packages/bottender/src/messenger/__tests__/MessengerContext-send.spec.ts @@ -111,14 +111,6 @@ describe('#sendText', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendText('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -191,19 +183,6 @@ describe('#sendAttachment', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendAttachment({ - type: 'image', - payload: { - url: 'https://example.com/pic.png', - }, - }); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -284,14 +263,6 @@ describe('#sendImage', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendImage('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -352,14 +323,6 @@ describe('#sendAudio', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendAudio('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -420,14 +383,6 @@ describe('#sendVideo', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendVideo('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -488,14 +443,6 @@ describe('#sendFile', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendFile('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -577,14 +524,6 @@ describe('#sendSenderAction', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendSenderAction('typing_on'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -622,14 +561,6 @@ describe('#typingOn', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.typingOn(); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -667,14 +598,6 @@ describe('#typingOff', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.typingOff(); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -712,14 +635,6 @@ describe('#markSeen', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.markSeen(); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); diff --git a/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts b/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts index 232eed77c..a9db887de 100644 --- a/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts +++ b/packages/bottender/src/messenger/__tests__/MessengerContext-sendTemplate.spec.ts @@ -145,17 +145,6 @@ describe('#sendGenericTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const elements = {}; - const ratio = ''; - - await context.sendGenericTemplate(elements, { imageAspectRatio: ratio }); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -235,16 +224,6 @@ describe('#sendButtonTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const buttons = []; - - await context.sendButtonTemplate('yayaya', buttons); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -339,16 +318,6 @@ describe('#sendMediaTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const elements = []; - - await context.sendMediaTemplate(elements); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -423,16 +392,6 @@ describe('#sendReceiptTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const receipt = {}; - - await context.sendReceiptTemplate(receipt); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -507,16 +466,6 @@ describe('#sendAirlineBoardingPassTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const boardingPass = {}; - - await context.sendAirlineBoardingPassTemplate(boardingPass); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -591,16 +540,6 @@ describe('#sendAirlineCheckinTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const checkin = {}; - - await context.sendAirlineCheckinTemplate(checkin); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -675,16 +614,6 @@ describe('#sendAirlineItineraryTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const itinerary = {}; - - await context.sendAirlineItineraryTemplate(itinerary); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -759,16 +688,6 @@ describe('#sendAirlineUpdateTemplate', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - const flightUpdate = {}; - - await context.sendAirlineUpdateTemplate(flightUpdate); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); diff --git a/packages/bottender/src/slack/SlackContext.ts b/packages/bottender/src/slack/SlackContext.ts index 5c0c48bfb..333234ac8 100644 --- a/packages/bottender/src/slack/SlackContext.ts +++ b/packages/bottender/src/slack/SlackContext.ts @@ -170,8 +170,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.postMessage({ threadTs: this._event.rawEvent.threadTs, channel, @@ -219,8 +217,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.postEphemeral({ channel, user: (this._session as any).user.id, @@ -242,8 +238,6 @@ export default class SlackContext extends Context< * https://api.slack.com/methods/chat.update */ _updateMessage(options: SlackTypes.UpdateMessageOptions): Promise { - this._isHandled = true; - return this._client.chat.update(options); } @@ -261,8 +255,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.delete({ channel, ...options, @@ -283,8 +275,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.meMessage({ channel, ...options }); } @@ -302,8 +292,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.getPermalink({ channel, ...options }); } @@ -321,8 +309,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.scheduleMessage({ channel, ...options, @@ -345,8 +331,6 @@ export default class SlackContext extends Context< return Promise.resolve(); } - this._isHandled = true; - return this._client.chat.deleteScheduledMessage({ channel, ...options, @@ -361,8 +345,6 @@ export default class SlackContext extends Context< _getScheduledMessages( options: SlackTypes.GetScheduledMessagesOptions ): Promise { - this._isHandled = true; - return this._client.chat.scheduledMessages.list(options); } @@ -372,8 +354,6 @@ export default class SlackContext extends Context< * https://api.slack.com/methods/views.open */ _openView(options: SlackTypes.OpenViewOptions): Promise { - this._isHandled = true; - return this._client.views.open({ ...options, view: { @@ -392,8 +372,6 @@ export default class SlackContext extends Context< * https://api.slack.com/methods/views.publish */ _publishView(options: SlackTypes.PublishViewOptions): Promise { - this._isHandled = true; - return this._client.views.publish(options); } @@ -403,8 +381,6 @@ export default class SlackContext extends Context< * https://api.slack.com/methods/views.update */ _updateView(options: SlackTypes.UpdateViewOptions): Promise { - this._isHandled = true; - return this._client.views.update(options); } @@ -414,8 +390,6 @@ export default class SlackContext extends Context< * https://api.slack.com/methods/views.push */ _pushView(options: SlackTypes.PushViewOptions): Promise { - this._isHandled = true; - return this._client.views.push(options); } } diff --git a/packages/bottender/src/slack/__tests__/SlackContext.spec.ts b/packages/bottender/src/slack/__tests__/SlackContext.spec.ts index da63e04bd..0d575ea2c 100644 --- a/packages/bottender/src/slack/__tests__/SlackContext.spec.ts +++ b/packages/bottender/src/slack/__tests__/SlackContext.spec.ts @@ -201,14 +201,6 @@ describe('#postMessage', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.postMessage('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have channelId', async () => { const { context, client } = setup({ session: false }); @@ -291,14 +283,6 @@ describe('#chat.postMessage', () => { }); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.chat.postMessage({ text: 'hello' }); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have channelId', async () => { const { context, client } = setup({ session: false }); diff --git a/packages/bottender/src/telegram/TelegramContext.ts b/packages/bottender/src/telegram/TelegramContext.ts index 881a2fb12..b99a27eed 100644 --- a/packages/bottender/src/telegram/TelegramContext.ts +++ b/packages/bottender/src/telegram/TelegramContext.ts @@ -41,8 +41,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -116,8 +114,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const shippingQueryId = (this._event.shippingQuery as any).id; return this._client.answerShippingQuery(shippingQueryId, ok, options); @@ -135,8 +131,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const preCheckoutQueryId = (this._event.preCheckoutQuery as any).id; return this._client.answerPreCheckoutQuery(preCheckoutQueryId, ok, options); @@ -154,8 +148,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const inlineQueryId = (this._event.inlineQuery as any).id; return this._client.answerInlineQuery(inlineQueryId, results, options); @@ -300,8 +292,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -332,8 +322,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -364,8 +352,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -396,8 +382,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -424,8 +408,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -452,8 +434,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -483,8 +463,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -515,8 +493,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -543,8 +519,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -571,8 +545,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -598,8 +570,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -625,8 +595,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -652,8 +620,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -679,8 +645,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -706,8 +670,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -733,8 +695,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -760,8 +720,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -787,8 +745,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -814,8 +770,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -841,8 +795,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -868,8 +820,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -896,8 +846,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -920,8 +868,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -948,8 +894,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -972,8 +916,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1000,8 +942,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1032,8 +972,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1056,8 +994,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1082,8 +1018,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1106,8 +1040,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1130,8 +1062,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1154,8 +1084,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1178,8 +1106,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1205,8 +1131,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1229,8 +1153,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1253,8 +1175,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1281,8 +1201,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1309,8 +1227,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - const chatId = this._getChatId(); if (chatId === null) { @@ -1337,8 +1253,6 @@ class TelegramContext extends Context { return null; } - this._isHandled = true; - return this._client.setGameScore(userId, score, options); } } diff --git a/packages/bottender/src/telegram/__tests__/TelegramContext.spec.ts b/packages/bottender/src/telegram/__tests__/TelegramContext.spec.ts index bb7f52f75..ad5f87ce8 100644 --- a/packages/bottender/src/telegram/__tests__/TelegramContext.spec.ts +++ b/packages/bottender/src/telegram/__tests__/TelegramContext.spec.ts @@ -91,14 +91,6 @@ describe('#sendText', () => { expect(client.sendMessage).toBeCalledWith(427770117, 'hello', undefined); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendText('hello'); - - expect(context._isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -118,14 +110,6 @@ describe('#sendMessage', () => { expect(client.sendMessage).toBeCalledWith(427770117, 'hello', undefined); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendMessage('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: null }); @@ -143,14 +127,6 @@ describe('#sendPhoto', () => { expect(client.sendPhoto).toBeCalledWith(427770117, 'xxx.png', undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendPhoto('xxx.png'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendAudio', () => { @@ -161,14 +137,6 @@ describe('#sendAudio', () => { expect(client.sendAudio).toBeCalledWith(427770117, 'xxx.mp3', undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendAudio('xxx.mp3'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendDocument', () => { @@ -179,14 +147,6 @@ describe('#sendDocument', () => { expect(client.sendDocument).toBeCalledWith(427770117, 'xxx.gif', undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendDocument('xxx.gif'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendSticker', () => { @@ -201,14 +161,6 @@ describe('#sendSticker', () => { undefined ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendSticker('CAADAgADQAADyIsGAAE7MpzFPFQX5QI'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendVideo', () => { @@ -219,14 +171,6 @@ describe('#sendVideo', () => { expect(client.sendVideo).toBeCalledWith(427770117, 'xxx.mp4', undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendVideo('xxx.mp4'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendAnimation', () => { @@ -241,14 +185,6 @@ describe('#sendAnimation', () => { undefined ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendAnimation('xxx.mp4'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendVoice', () => { @@ -259,14 +195,6 @@ describe('#sendVoice', () => { expect(client.sendVoice).toBeCalledWith(427770117, 'xxx.ogg', undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendVoice('xxx.ogg'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendVideoNote', () => { @@ -281,14 +209,6 @@ describe('#sendVideoNote', () => { undefined ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendVideoNote('xxx.mp4'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendMediaGroup', () => { @@ -305,16 +225,6 @@ describe('#sendMediaGroup', () => { undefined ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendMediaGroup([ - { type: 'photo', media: 'BQADBAADApYAAgcZZAfj2-xeidueWwI' }, - ]); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendLocation', () => { @@ -327,16 +237,6 @@ describe('#sendLocation', () => { expect(client.sendLocation).toBeCalledWith(427770117, location, undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - const location = {}; - - await context.sendLocation(location); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendVenue', () => { @@ -349,16 +249,6 @@ describe('#sendVenue', () => { expect(client.sendVenue).toBeCalledWith(427770117, venue, undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - const venue = {}; - - await context.sendVenue(venue); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendContact', () => { @@ -371,16 +261,6 @@ describe('#sendContact', () => { expect(client.sendContact).toBeCalledWith(427770117, contact, undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - const contact = {}; - - await context.sendContact(contact); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendPoll', () => { @@ -399,17 +279,6 @@ describe('#sendPoll', () => { undefined ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - const question = 'question'; - const options = ['a', 'b']; - - await context.sendPoll(question, options); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendChatAction', () => { @@ -420,14 +289,6 @@ describe('#sendChatAction', () => { expect(client.sendChatAction).toBeCalledWith(427770117, 'typing'); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendChatAction('typing'); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendInvoice', () => { @@ -450,14 +311,6 @@ describe('#sendInvoice', () => { expect(client.sendInvoice).toBeCalledWith(427770117, invoice, undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendInvoice(invoice); - - expect(context.isHandled).toBe(true); - }); }); describe('#sendGame', () => { @@ -468,14 +321,6 @@ describe('#sendGame', () => { expect(client.sendGame).toBeCalledWith(427770117, 'Mario Bros.', undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendGame('Mario Bros.'); - - expect(context.isHandled).toBe(true); - }); }); describe('#setGameScore', () => { @@ -486,14 +331,6 @@ describe('#setGameScore', () => { expect(client.setGameScore).toBeCalledWith(427770117, 999, undefined); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.setGameScore(427770117, 999); - - expect(context.isHandled).toBe(true); - }); }); describe('#getGameHighScores', () => { @@ -532,14 +369,6 @@ describe('#editMessageText', () => { messageId: 66, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.editMessageText('new text'); - - expect(context.isHandled).toBe(true); - }); }); describe('#editMessageCaption', () => { @@ -553,14 +382,6 @@ describe('#editMessageCaption', () => { messageId: 66, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.editMessageCaption('new caption'); - - expect(context.isHandled).toBe(true); - }); }); describe('#editMessageMedia', () => { @@ -575,14 +396,6 @@ describe('#editMessageMedia', () => { messageId: 66, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.editMessageMedia(66, { type: 'photo', media: 'xxx.png' }); - - expect(context.isHandled).toBe(true); - }); }); describe('#editMessageReplyMarkup', () => { @@ -602,14 +415,6 @@ describe('#editMessageReplyMarkup', () => { messageId: 66, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.editMessageReplyMarkup(markup); - - expect(context.isHandled).toBe(true); - }); }); describe('#deleteMessage', () => { @@ -620,14 +425,6 @@ describe('#deleteMessage', () => { expect(client.deleteMessage).toBeCalledWith(427770117, 66); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.deleteMessage(66); - - expect(context.isHandled).toBe(true); - }); }); describe('#editMessageLiveLocation', () => { @@ -646,14 +443,6 @@ describe('#editMessageLiveLocation', () => { messageId: 66, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.editMessageLiveLocation(location); - - expect(context.isHandled).toBe(true); - }); }); describe('#stopMessageLiveLocation', () => { @@ -666,14 +455,6 @@ describe('#stopMessageLiveLocation', () => { chatId: 427770117, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.stopMessageLiveLocation(); - - expect(context.isHandled).toBe(true); - }); }); describe('#forwardMessageFrom', () => { @@ -693,16 +474,6 @@ describe('#forwardMessageFrom', () => { } ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.forwardMessageFrom(313534466, 'messageId', { - disableNotification: true, - }); - - expect(context.isHandled).toBe(true); - }); }); describe('#forwardMessageTo', () => { @@ -722,16 +493,6 @@ describe('#forwardMessageTo', () => { } ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.forwardMessageTo(413534466, 'messageId', { - disableNotification: true, - }); - - expect(context.isHandled).toBe(true); - }); }); describe('#kickChatMember', () => { @@ -746,14 +507,6 @@ describe('#kickChatMember', () => { untilDate: 1502855973, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.kickChatMember(313534466); - - expect(context.isHandled).toBe(true); - }); }); describe('#unbanChatMember', () => { @@ -764,14 +517,6 @@ describe('#unbanChatMember', () => { expect(client.unbanChatMember).toBeCalledWith(427770117, 313534466); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.unbanChatMember(313534466); - - expect(context.isHandled).toBe(true); - }); }); describe('#restrictChatMember', () => { @@ -793,14 +538,6 @@ describe('#restrictChatMember', () => { undefined ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.restrictChatMember(313534466); - - expect(context.isHandled).toBe(true); - }); }); describe('#promoteChatMember', () => { @@ -819,14 +556,6 @@ describe('#promoteChatMember', () => { canDeleteMessages: true, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.promoteChatMember(313534466); - - expect(context.isHandled).toBe(true); - }); }); describe('#exportChatInviteLink', () => { @@ -837,14 +566,6 @@ describe('#exportChatInviteLink', () => { expect(client.exportChatInviteLink).toBeCalledWith(427770117); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.exportChatInviteLink(); - - expect(context.isHandled).toBe(true); - }); }); describe('#deleteChatPhoto', () => { @@ -855,14 +576,6 @@ describe('#deleteChatPhoto', () => { expect(client.deleteChatPhoto).toBeCalledWith(427770117); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.deleteChatPhoto(); - - expect(context.isHandled).toBe(true); - }); }); describe('#setChatTitle', () => { @@ -873,14 +586,6 @@ describe('#setChatTitle', () => { expect(client.setChatTitle).toBeCalledWith(427770117, 'New Title'); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.setChatTitle('New Title'); - - expect(context.isHandled).toBe(true); - }); }); describe('#setChatDescription', () => { @@ -894,14 +599,6 @@ describe('#setChatDescription', () => { 'New Description' ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.setChatDescription('New Description'); - - expect(context.isHandled).toBe(true); - }); }); describe('#setChatStickerSet', () => { @@ -915,14 +612,6 @@ describe('#setChatStickerSet', () => { 'Sticker Set Name' ); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.setChatStickerSet('Sticker Set Name'); - - expect(context.isHandled).toBe(true); - }); }); describe('#deleteChatStickerSet', () => { @@ -933,14 +622,6 @@ describe('#deleteChatStickerSet', () => { expect(client.deleteChatStickerSet).toBeCalledWith(427770117); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.deleteChatStickerSet(); - - expect(context.isHandled).toBe(true); - }); }); describe('#pinChatMessage', () => { @@ -955,14 +636,6 @@ describe('#pinChatMessage', () => { disableNotification: true, }); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.pinChatMessage(1); - - expect(context.isHandled).toBe(true); - }); }); describe('#unpinChatMessage', () => { @@ -973,14 +646,6 @@ describe('#unpinChatMessage', () => { expect(client.unpinChatMessage).toBeCalledWith(427770117); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.unpinChatMessage(); - - expect(context.isHandled).toBe(true); - }); }); describe('#leaveChat', () => { @@ -991,14 +656,6 @@ describe('#leaveChat', () => { expect(client.leaveChat).toBeCalledWith(427770117); }); - - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.leaveChat(); - - expect(context.isHandled).toBe(true); - }); }); describe('#answerShippingQuery', () => { @@ -1040,14 +697,6 @@ describe('#answerShippingQuery', () => { expect(result).toEqual(response); }); - it('should mark context as handled', async () => { - const { context } = setup({ rawEvent: shippingQuery }); - - await context.answerShippingQuery(true); - - expect(context.isHandled).toBe(true); - }); - it('should not call answerShippingQuery method if event type is not ShippingQuery', async () => { const { context, client } = setup(); @@ -1094,14 +743,6 @@ describe('#answerPreCheckoutQuery', () => { expect(result).toEqual(response); }); - it('should mark context as handled', async () => { - const { context } = setup({ rawEvent: preCheckoutQuery }); - - await context.answerPreCheckoutQuery(true); - - expect(context.isHandled).toBe(true); - }); - it('should not call answerPreCheckoutQuery method if event type is not PreCheckoutQuery', async () => { const { context, client } = setup(); @@ -1180,32 +821,6 @@ describe('#answerInlineQuery', () => { expect(result).toEqual(response); }); - it('should mark context as handled', async () => { - const { context } = setup({ rawEvent: inlineQuery }); - - await context.answerInlineQuery( - [ - { - type: 'photo', - id: 'UNIQUE_ID', - photoFileId: 'FILE_ID', - title: 'PHOTO_TITLE', - }, - { - type: 'audio', - id: 'UNIQUE_ID', - audioFileId: 'FILE_ID', - caption: 'AUDIO_TITLE', - }, - ], - { - cacheTime: 1000, - } - ); - - expect(context.isHandled).toBe(true); - }); - it('should not call answerInlineQuery method if event type is not InlineQuery', async () => { const { context, client } = setup(); diff --git a/packages/bottender/src/viber/ViberContext.ts b/packages/bottender/src/viber/ViberContext.ts index be77fc7b8..e47ef02ef 100644 --- a/packages/bottender/src/viber/ViberContext.ts +++ b/packages/bottender/src/viber/ViberContext.ts @@ -41,8 +41,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendText(this._session.user.id, text, options); } @@ -88,8 +86,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendMessage(this._session.user.id, message); } @@ -105,8 +101,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendPicture(this._session.user.id, picture, options); } @@ -122,8 +116,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendVideo(this._session.user.id, video, options); } @@ -139,8 +131,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendFile(this._session.user.id, file, options); } @@ -156,8 +146,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendContact(this._session.user.id, contact, options); } @@ -173,8 +161,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendLocation(this._session.user.id, location, options); } @@ -190,8 +176,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendURL(this._session.user.id, url, options); } @@ -207,8 +191,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendSticker(this._session.user.id, stickerId, options); } @@ -224,8 +206,6 @@ class ViberContext extends Context { return; } - this._isHandled = true; - return this._client.sendCarouselContent( this._session.user.id, richMedia, diff --git a/packages/bottender/src/viber/__tests__/ViberContext.spec.ts b/packages/bottender/src/viber/__tests__/ViberContext.spec.ts index 4512762ca..2074b08ec 100644 --- a/packages/bottender/src/viber/__tests__/ViberContext.spec.ts +++ b/packages/bottender/src/viber/__tests__/ViberContext.spec.ts @@ -86,14 +86,6 @@ describe('#sendText', () => { expect(client.sendText).toBeCalledWith(session.user.id, 'hello', undefined); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendText('hello'); - - expect(context.isHandled).toBe(true); - }); - it('should call warning and not to send if dont have session', async () => { const { context, client } = setup({ session: false }); @@ -125,18 +117,6 @@ describe('#sendPicture', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendPicture({ - text: 'Photo description', - media: 'http://www.images.com/img.jpg', - thumbnail: 'http://www.images.com/thumb.jpg', - }); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -173,19 +153,6 @@ describe('#sendVideo', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendVideo({ - media: 'http://www.images.com/video.mp4', - size: 10000, - thumbnail: 'http://www.images.com/thumb.jpg', - duration: 10, - }); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -221,18 +188,6 @@ describe('#sendFile', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendFile({ - media: 'http://www.images.com/file.doc', - size: 10000, - fileName: 'name_of_file.doc', - }); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -265,17 +220,6 @@ describe('#sendContact', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendContact({ - name: 'Itamar', - phoneNumber: '+972511123123', - }); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -307,17 +251,6 @@ describe('#sendLocation', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendLocation({ - lat: '37.7898', - lon: '-122.3942', - }); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -343,14 +276,6 @@ describe('#sendURL', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendURL('http://developers.viber.com'); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -373,14 +298,6 @@ describe('#sendSticker', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendSticker(46105); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined }); @@ -490,14 +407,6 @@ describe('#sendCarouselContent', () => { ); }); - it('should mark context as handled', async () => { - const { context } = setup(); - - await context.sendCarouselContent(richMedia); - - expect(context.isHandled).toBe(true); - }); - it('should not call send method if dont have session', async () => { const { context, client } = setup({ session: undefined });