From bd12002c7dfc0b5bb4bbb6097970fbf4041bd00f Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Mon, 10 May 2021 16:29:12 +0530 Subject: [PATCH 1/6] Fix errors while submitting app to marketplace --- app.json | 8 ++++++-- package-lock.json | 6 ++++++ package.json | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app.json b/app.json index 20916d3..0a23f2a 100644 --- a/app.json +++ b/app.json @@ -11,5 +11,9 @@ "name": "Dialogflow", "nameSlug": "dialogflow", "classFile": "DialogflowApp.ts", - "description": "Integration between Rocket.Chat and the Dialogflow Chatbot platform" -} + "description": "Integration between Rocket.Chat and the Dialogflow Chatbot platform", + "implements": [ + "IPostMessageSent", + "IUIKitLivechatInteractionHandler" + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fd7d474..b6050ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -284,6 +284,12 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "prettier": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", + "dev": true + }, "resolve": { "version": "1.17.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", diff --git a/package.json b/package.json index 5ee6ffb..2483bd0 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "devDependencies": { "@rocket.chat/apps-engine": "^1.17.0", - "@types/node": "^10.17.24", - "tslint": "^5.10.0", + "@types/node": "^10.17.5", + "prettier": "^2.0.5", + "tslint": "^5.20.1", "typescript": "^2.9.1" } } From 130c9a47d5db6d868b7defd686c560003be8ba45 Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Mon, 10 May 2021 23:11:03 +0530 Subject: [PATCH 2/6] Fix errors while submitting to marketplace --- package-lock.json | 90 ++++++++++++++++++++++++++++++----------------- package.json | 2 +- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index b6050ae..9d2e645 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,35 +3,35 @@ "lockfileVersion": 1, "dependencies": { "@babel/code-frame": { - "version": "7.10.1", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.1.tgz", - "integrity": "sha512-IGhtTmpjGbYzcEDOw7DcQtbQSXcG9ftmAXtWTu9V936vDye4xjjekktFAtgZsWpzTj/X01jocB46mTywm/4SZw==", + "version": "7.12.13", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz", + "integrity": "sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==", "dev": true, "requires": { - "@babel/highlight": "^7.10.1" + "@babel/highlight": "^7.12.13" } }, "@babel/helper-validator-identifier": { - "version": "7.10.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.1.tgz", - "integrity": "sha512-5vW/JXLALhczRCWP0PnFDMCJAchlBvM7f4uk/jXritBnIa6E1KmqmtrS3yn1LAnxFBypQ3eneLuXjsnfQsgILw==", + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.0.tgz", + "integrity": "sha512-V3ts7zMSu5lfiwWDVWzRDGIN+lnCEUdaXgtVHJgLb1rGaA6jMrtB9EmE7L18foXJIE8Un/A/h6NJfGQp/e1J4A==", "dev": true }, "@babel/highlight": { - "version": "7.10.1", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.1.tgz", - "integrity": "sha512-8rMof+gVP8mxYZApLF/JgNDAkdKa+aJt3ZYxF8z6+j/hpeXL7iMsKCPHa2jNMHu/qqBwzQF4OHNoYi8dMA/rYg==", + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.14.0.tgz", + "integrity": "sha512-YSCOwxvTYEIMSGaBQb5kDDsCopDdiUGsqpatp3fOlI4+2HQSkTmEVWnVuySdAC5EWCqSWWTv0ib63RjR7dTBdg==", "dev": true, "requires": { - "@babel/helper-validator-identifier": "^7.10.1", + "@babel/helper-validator-identifier": "^7.14.0", "chalk": "^2.0.0", "js-tokens": "^4.0.0" } }, "@rocket.chat/apps-engine": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.17.0.tgz", - "integrity": "sha512-4jsN9RUQR9zvZnOr4IZj9bnZR5/kAuSpKJ3JwqTv/DXBeHRSrCCCX0EDoZh5akmQu6x9tRpAXd1DRJWRfI5/Jw==", + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.25.0.tgz", + "integrity": "sha512-Dd66C0JbaXwzVL8JxeK3q1v0DcGyWiuSJNwmSkqkwba5arh7XLSP9WdFbwlGI8ckBbXzFCpmow5LSc9tDYAGBg==", "dev": true, "requires": { "adm-zip": "^0.4.9", @@ -39,14 +39,13 @@ "lodash.clonedeep": "^4.5.0", "semver": "^5.5.0", "stack-trace": "0.0.10", - "typescript": "^2.9.2", "uuid": "^3.2.1" } }, "@types/node": { - "version": "10.17.24", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.24.tgz", - "integrity": "sha512-5SCfvCxV74kzR3uWgTYiGxrd69TbT1I6+cMx1A5kEly/IVveJBimtAMlXiEyVFn5DvUFewQWxOOiJhlxeQwxgA==", + "version": "10.17.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.5.tgz", + "integrity": "sha512-RElZIr/7JreF1eY6oD5RF3kpmdcreuQPjg5ri4oQ5g9sq7YWU8HkfB3eH8GwAwxf5OaCh0VPi7r4N/yoTGelrA==", "dev": true }, "adm-zip": { @@ -74,9 +73,9 @@ } }, "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "boom": { @@ -175,10 +174,16 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -189,6 +194,15 @@ "path-is-absolute": "^1.0.0" } }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -217,6 +231,15 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "is-core-module": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz", + "integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -224,9 +247,9 @@ "dev": true }, "js-yaml": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", - "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -291,11 +314,12 @@ "dev": true }, "resolve": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", - "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", + "integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==", "dev": true, "requires": { + "is-core-module": "^2.2.0", "path-parse": "^1.0.6" } }, @@ -327,9 +351,9 @@ } }, "tslib": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", - "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, "tslint": { diff --git a/package.json b/package.json index 2483bd0..3f4bae3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "devDependencies": { "@rocket.chat/apps-engine": "^1.17.0", - "@types/node": "^10.17.5", + "@types/node": "10.17.5", "prettier": "^2.0.5", "tslint": "^5.20.1", "typescript": "^2.9.1" From 15c423565f1615571aa1b28568959bd0e14e7e0e Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Fri, 11 Jun 2021 13:55:35 +0530 Subject: [PATCH 3/6] Unify Quick Replies format across all Omnichannel apps --- endpoints/FulfillmentsEndpoint.ts | 2 +- endpoints/IncomingEndpoint.ts | 8 ++-- handler/ExecuteLivechatBlockActionHandler.ts | 6 +-- handler/PostMessageSentHandler.ts | 7 ++-- lib/Message.ts | 41 ++++++++++++-------- lib/Room.ts | 7 ++-- lib/SynchronousHandover.ts | 5 ++- 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/endpoints/FulfillmentsEndpoint.ts b/endpoints/FulfillmentsEndpoint.ts index f2d5089..e365233 100644 --- a/endpoints/FulfillmentsEndpoint.ts +++ b/endpoints/FulfillmentsEndpoint.ts @@ -35,6 +35,6 @@ export class FulfillmentsEndpoint extends ApiEndpoint { if (!message) { throw new Error(Logs.INVALID_REQUEST_CONTENT); } if (!message.sessionId) { throw new Error(Logs.INVALID_SESSION_ID); } - await createDialogflowMessage(message.sessionId, read, modify, message); + await createDialogflowMessage(this.app, message.sessionId, read, modify, message); } } diff --git a/endpoints/IncomingEndpoint.ts b/endpoints/IncomingEndpoint.ts index 0f93180..6483788 100644 --- a/endpoints/IncomingEndpoint.ts +++ b/endpoints/IncomingEndpoint.ts @@ -1,7 +1,7 @@ import { HttpStatusCode, IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { ApiEndpoint, IApiEndpointInfo, IApiRequest, IApiResponse } from '@rocket.chat/apps-engine/definition/api'; import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; -import { IDialogflowMessage, DialogflowRequestType } from '../enum/Dialogflow'; +import { DialogflowRequestType, IDialogflowMessage } from '../enum/Dialogflow'; import { EndpointActionNames, IActionsEndpointContent } from '../enum/Endpoints'; import { Headers, Response } from '../enum/Http'; import { Logs } from '../enum/Logs'; @@ -43,7 +43,7 @@ export class IncomingEndpoint extends ApiEndpoint { const room = await read.getRoomReader().getById(sessionId) as ILivechatRoom; if (!room) { throw new Error(); } const { visitor: { token: visitorToken } } = room; - await performHandover(modify, read, sessionId, visitorToken, targetDepartment); + await performHandover(this.app, modify, read, sessionId, visitorToken, targetDepartment); break; case EndpointActionNames.TRIGGER_EVENT: const { actionData: { event = null } = {} } = endpointContent; @@ -51,7 +51,7 @@ export class IncomingEndpoint extends ApiEndpoint { try { const response: IDialogflowMessage = await Dialogflow.sendRequest(http, read, modify, sessionId, event, DialogflowRequestType.EVENT); - await createDialogflowMessage(sessionId, read, modify, response); + await createDialogflowMessage(this.app, sessionId, read, modify, response); } catch (error) { this.app.getLogger().error(`${Logs.DIALOGFLOW_REST_API_ERROR} ${error.message}`); throw new Error(`${Logs.DIALOGFLOW_REST_API_ERROR} ${error.message}`); @@ -60,7 +60,7 @@ export class IncomingEndpoint extends ApiEndpoint { case EndpointActionNames.SEND_MESSAGE: const { actionData: { messages = null } = {} } = endpointContent; if (!messages) { throw new Error(Logs.INVALID_MESSAGES); } - await createDialogflowMessage(sessionId, read, modify, { messages, isFallback: false }); + await createDialogflowMessage(this.app, sessionId, read, modify, { messages, isFallback: false }); break; default: throw new Error(Logs.INVALID_ENDPOINT_ACTION); diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 174c014..c02e98b 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -40,10 +40,10 @@ export class ExecuteLivechatBlockActionHandler { case ActionIds.PERFORM_HANDOVER: const targetDepartment: string = value || await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); if (!targetDepartment) { - await createMessage(rid, this.read, this.modify, { text: DefaultMessage.DEFAULT_DialogflowRequestFailedMessage }); + await createMessage(this.app, rid, this.read, this.modify, { text: DefaultMessage.DEFAULT_DialogflowRequestFailedMessage }); break; } - await performHandover(this.modify, this.read, rid, visitor.token, targetDepartment); + await performHandover(this.app, this.modify, this.read, rid, visitor.token, targetDepartment); break; case ActionIds.CLOSE_CHAT: @@ -51,7 +51,7 @@ export class ExecuteLivechatBlockActionHandler { break; default: - await createLivechatMessage(rid, this.read, this.modify, { text: value }, visitor); + await createLivechatMessage(this.app, rid, this.read, this.modify, { text: value }, visitor); break; } diff --git a/handler/PostMessageSentHandler.ts b/handler/PostMessageSentHandler.ts index 3c3325e..9dc38da 100644 --- a/handler/PostMessageSentHandler.ts +++ b/handler/PostMessageSentHandler.ts @@ -54,7 +54,8 @@ export class PostMessageSentHandler { const serviceUnavailable: string = await getAppSettingValue(this.read, AppSetting.DialogflowServiceUnavailableMessage); - await createMessage(rid, + await createMessage(this.app, + rid, this.read, this.modify, { text: serviceUnavailable ? serviceUnavailable : DefaultMessage.DEFAULT_DialogflowServiceUnavailableMessage }); @@ -62,12 +63,12 @@ export class PostMessageSentHandler { return; } - await createDialogflowMessage(rid, this.read, this.modify, response); + await createDialogflowMessage(this.app, rid, this.read, this.modify, response); // synchronous handover check const { isFallback } = response; if (isFallback) { - return incFallbackIntent(this.read, this.modify, rid); + return incFallbackIntent(this.app, this.read, this.modify, rid); } return resetFallbackIntent(this.read, this.modify, rid); } diff --git a/lib/Message.ts b/lib/Message.ts index 6049c0a..9f7fc0c 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -1,6 +1,7 @@ import { IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors'; +import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { IVisitor } from '@rocket.chat/apps-engine/definition/livechat'; -import { BlockElementType, BlockType, IActionsBlock, IButtonElement, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit'; +import { BlockElementType, IButtonElement, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit'; import { IUser } from '@rocket.chat/apps-engine/definition/users'; import { AppSetting } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; @@ -9,7 +10,7 @@ import { Logs } from '../enum/Logs'; import { uuid } from './Helper'; import { getAppSettingValue } from './Settings'; -export const createDialogflowMessage = async (rid: string, read: IRead, modify: IModify, dialogflowMessage: IDialogflowMessage): Promise => { +export const createDialogflowMessage = async (app: IApp, rid: string, read: IRead, modify: IModify, dialogflowMessage: IDialogflowMessage): Promise => { const { messages = [] } = dialogflowMessage; for (const message of messages) { @@ -34,45 +35,52 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: return buttonElement; }); - const actionsBlock: IActionsBlock = { type: BlockType.ACTIONS, elements }; + const blocks = modify.getCreator().getBlockBuilder(); - await createMessage(rid, read, modify, { text }); - await createMessage(rid, read, modify, { actionsBlock }); + blocks.addSectionBlock({ + text: blocks.newMarkdownTextObject(text) + }); + + blocks.addActionsBlock({ + elements, + }); + + await createMessage(app, rid, read, modify, { blocks }); } else { // message is instanceof string if ((message as string).trim().length > 0) { - await createMessage(rid, read, modify, { text: message }); + await createMessage(app, rid, read, modify, { text: message }); } } } }; -export const createMessage = async (rid: string, read: IRead, modify: IModify, message: any ): Promise => { +export const createMessage = async (app: IApp, rid: string, read: IRead, modify: IModify, message: any ): Promise => { if (!message) { return; } const botUserName = await getAppSettingValue(read, AppSetting.DialogflowBotUsername); if (!botUserName) { - this.app.getLogger().error(Logs.EMPTY_BOT_USERNAME_SETTING); + app.getLogger().error(Logs.EMPTY_BOT_USERNAME_SETTING); return; } const sender = await read.getUserReader().getByUsername(botUserName); if (!sender) { - this.app.getLogger().error(Logs.INVALID_BOT_USERNAME_SETTING); + app.getLogger().error(Logs.INVALID_BOT_USERNAME_SETTING); return; } const room = await read.getRoomReader().getById(rid); if (!room) { - this.app.getLogger().error(`${Logs.INVALID_ROOM_ID} ${rid}`); + app.getLogger().error(`${Logs.INVALID_ROOM_ID} ${rid}`); return; } const msg = modify.getCreator().startMessage().setRoom(room).setSender(sender); - const { text, actionsBlock, attachment } = message; + const { text, blocks, attachment } = message; if (text) { msg.setText(text); @@ -82,9 +90,8 @@ export const createMessage = async (rid: string, read: IRead, modify: IModify, msg.addAttachment(attachment); } - if (actionsBlock) { - const { elements } = actionsBlock as IActionsBlock; - msg.addBlocks(modify.getCreator().getBlockBuilder().addActionsBlock({ elements })); + if (blocks) { + msg.addBlocks(blocks); } return new Promise(async (resolve) => { @@ -94,20 +101,20 @@ export const createMessage = async (rid: string, read: IRead, modify: IModify, }); }; -export const createLivechatMessage = async (rid: string, read: IRead, modify: IModify, message: any, visitor: IVisitor ): Promise => { +export const createLivechatMessage = async (app: IApp, rid: string, read: IRead, modify: IModify, message: any, visitor: IVisitor ): Promise => { if (!message) { return; } const botUserName = await getAppSettingValue(read, AppSetting.DialogflowBotUsername); if (!botUserName) { - this.app.getLogger().error(Logs.EMPTY_BOT_USERNAME_SETTING); + app.getLogger().error(Logs.EMPTY_BOT_USERNAME_SETTING); return; } const room = await read.getRoomReader().getById(rid); if (!room) { - this.app.getLogger().error(`${ Logs.INVALID_ROOM_ID } ${ rid }`); + app.getLogger().error(`${ Logs.INVALID_ROOM_ID } ${ rid }`); return; } diff --git a/lib/Room.ts b/lib/Room.ts index 9d6be93..38798b0 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -1,4 +1,5 @@ import { IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors'; +import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { IDepartment, ILivechatRoom, ILivechatTransferData, IVisitor } from '@rocket.chat/apps-engine/definition/livechat'; import { IRoom } from '@rocket.chat/apps-engine/definition/rooms'; import { AppSetting, DefaultMessage } from '../config/Settings'; @@ -42,10 +43,10 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string) => { if (!result) { throw new Error(Logs.CLOSE_CHAT_REQUEST_FAILED_ERROR); } }; -export const performHandover = async (modify: IModify, read: IRead, rid: string, visitorToken: string, targetDepartmentName?: string) => { +export const performHandover = async (app: IApp, modify: IModify, read: IRead, rid: string, visitorToken: string, targetDepartmentName?: string) => { const handoverMessage: string = await getAppSettingValue(read, AppSetting.DialogflowHandoverMessage); - await createMessage(rid, read, modify, { text: handoverMessage ? handoverMessage : DefaultMessage.DEFAULT_DialogflowHandoverMessage }); + await createMessage(app, rid, read, modify, { text: handoverMessage ? handoverMessage : DefaultMessage.DEFAULT_DialogflowHandoverMessage }); const room: ILivechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (!room) { throw new Error(Logs.INVALID_ROOM_ID); } @@ -71,6 +72,6 @@ export const performHandover = async (modify: IModify, read: IRead, rid: string, if (!result) { const offlineMessage: string = await getAppSettingValue(read, AppSetting.DialogflowServiceUnavailableMessage); - await createMessage(rid, read, modify, { text: offlineMessage ? offlineMessage : DefaultMessage.DEFAULT_DialogflowServiceUnavailableMessage }); + await createMessage(app, rid, read, modify, { text: offlineMessage ? offlineMessage : DefaultMessage.DEFAULT_DialogflowServiceUnavailableMessage }); } }; diff --git a/lib/SynchronousHandover.ts b/lib/SynchronousHandover.ts index dd822ee..6c7d44c 100644 --- a/lib/SynchronousHandover.ts +++ b/lib/SynchronousHandover.ts @@ -1,11 +1,12 @@ import { IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; +import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; import { AppSetting } from '../config/Settings'; import { Logs } from '../enum/Logs'; import { performHandover, updateRoomCustomFields } from './Room'; import { getAppSettingValue } from './Settings'; -export const incFallbackIntent = async (read: IRead, modify: IModify, sessionId: string) => { +export const incFallbackIntent = async (app: IApp, read: IRead, modify: IModify, sessionId: string) => { const fallbackThreshold = (await getAppSettingValue(read, AppSetting.DialogflowFallbackResponsesLimit)) as number; if (!fallbackThreshold || (fallbackThreshold && fallbackThreshold === 0)) { return; } @@ -26,7 +27,7 @@ export const incFallbackIntent = async (read: IRead, modify: IModify, sessionId: const targetDepartmentName: string | undefined = await getAppSettingValue(read, AppSetting.FallbackTargetDepartment); // Session Id from Dialogflow will be the same as Room id - await performHandover(modify, read, sessionId, visitorToken, targetDepartmentName); + await performHandover(app, modify, read, sessionId, visitorToken, targetDepartmentName); } }; From b054982ac039e5fe30131ec58e1c36edca58125a Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Fri, 11 Jun 2021 17:32:38 +0530 Subject: [PATCH 4/6] Bump app version --- app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.json b/app.json index 0a23f2a..4273c2e 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,6 @@ { "id": "21b7d3ba-031b-41d9-8ff2-fbbfa081ae90", - "version": "1.2.1", + "version": "1.2.2", "requiredApiVersion": "^1.17.0", "iconFile": "icon.png", "author": { @@ -16,4 +16,4 @@ "IPostMessageSent", "IUIKitLivechatInteractionHandler" ] -} \ No newline at end of file +} From 0138a7c52fe32ffd52cc92752ec01059f0ae8dec Mon Sep 17 00:00:00 2001 From: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Date: Mon, 14 Jun 2021 17:14:47 +0530 Subject: [PATCH 5/6] remove only action buttons from blocks while hiding quick replies buttons --- lib/Message.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Message.ts b/lib/Message.ts index 9f7fc0c..d7103ed 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -1,7 +1,7 @@ import { IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { IVisitor } from '@rocket.chat/apps-engine/definition/livechat'; -import { BlockElementType, IButtonElement, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit'; +import { BlockElementType, BlockType, IActionsBlock, IBlock, IButtonElement, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit'; import { IUser } from '@rocket.chat/apps-engine/definition/users'; import { AppSetting } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; @@ -37,8 +37,8 @@ export const createDialogflowMessage = async (app: IApp, rid: string, read: IRea const blocks = modify.getCreator().getBlockBuilder(); - blocks.addSectionBlock({ - text: blocks.newMarkdownTextObject(text) + blocks.addSectionBlock({ + text: blocks.newMarkdownTextObject(text), }); blocks.addActionsBlock({ @@ -139,6 +139,14 @@ export const createLivechatMessage = async (app: IApp, rid: string, read: IRead, export const deleteAllActionBlocks = async (modify: IModify, appUser: IUser, msgId: string): Promise => { const msgBuilder = await modify.getUpdater().message(msgId, appUser); - msgBuilder.setEditor(appUser).setBlocks(modify.getCreator().getBlockBuilder().getBlocks()); + + const withoutActionBlocks: Array = msgBuilder.getBlocks().filter( + (block) => (!( + block.type === BlockType.ACTIONS && + (block as IActionsBlock).elements.some((element) => (element.type === BlockElementType.BUTTON)) + ) + )); + + msgBuilder.setEditor(appUser).setBlocks(withoutActionBlocks); return modify.getUpdater().finish(msgBuilder); }; From e3859033172b1392f4aa67b8ff6fedae11908820 Mon Sep 17 00:00:00 2001 From: Shailesh Baldaniya Date: Mon, 9 Aug 2021 22:15:12 +0530 Subject: [PATCH 6/6] Remove console log --- lib/Message.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Message.ts b/lib/Message.ts index 849d418..6c73847 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -49,8 +49,6 @@ export const createDialogflowMessage = async (app: IApp, rid: string, read: IRea elements, }); - console.error(blocks); - data.blocks = blocks; }