From 0f148f8f0dbeeede0101eb20359c40ef75efd326 Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Sat, 5 Sep 2020 02:24:42 +0530 Subject: [PATCH 01/13] adding pre-programmed button support --- docs/QuickReplies.md | 34 ++++++++++++++++++-- enum/ActionIds.ts | 4 +++ handler/ExecuteLivechatBlockActionHandler.ts | 20 ++++++++++-- 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 enum/ActionIds.ts diff --git a/docs/QuickReplies.md b/docs/QuickReplies.md index 22158ec..9d8ffff 100644 --- a/docs/QuickReplies.md +++ b/docs/QuickReplies.md @@ -26,6 +26,36 @@ | `text` | String | Title of the quick replies action. | Required | Any | ``` "text": "Start Chat" ``` | | `actionId` | String | Id of the quick replies action. | Optional | Any | ``` "actionId": "sflaia-start-chat" ``` | | `buttonStyle` | String | Button style of your quick replies action. Use `danger` to render a red colour action and `primary` for an action that matches your Livechat Bar colour. | Optional | `danger` or `primary` | ``` "buttonStyle": "primary" ``` | -### Example -![Quick Replies Example](https://user-images.githubusercontent.com/41849970/91997140-62939c00-ed57-11ea-8b27-82e650a502f0.png) +## Pre-Programmed Buttons + +This are buttons that performs specific actions in the app. You can add them by simply pasting the following block in your Quick Replies payload. **Note**: You can change the `text` and `buttonStyle` parameters as per your requirements, but only use the provided `actionId` for the button you want to add. + +### Handover Button + +- On clicking this button, the visitor will be handed over to another departement. You can set the target department in the app setting called **Target Department for Handover**. Add the following block in your Quick Replies payload, with **actionId** set as `df_perform_handover`, to include this button in your response: + +``` +{ + "text": "Perform Handover", + "buttonStyle": "primary", + "actionId": "df_perform_handover" +} +``` + +### Close Chat Button + +- When visitor clicks this button, the chat session will be closed. Add the following block in your Quick Replies payload, with **actionId** set as `df_close_chat`, to include this button in your response: + +``` +{ + "text": "Close Chat", + "buttonStyle": "danger", + "actionId": "df_close_chat" +} +``` + +## Example + +![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) + diff --git a/enum/ActionIds.ts b/enum/ActionIds.ts new file mode 100644 index 0000000..022f9b3 --- /dev/null +++ b/enum/ActionIds.ts @@ -0,0 +1,4 @@ +export enum ActionIds { + PERFORM_HANDOVER = 'df_perform_handover', + CLOSE_CHAT = 'df_close_chat', +} diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index e7e600e..0ab3d18 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -5,7 +5,9 @@ import { IUIKitResponse, UIKitLivechatBlockInteractionContext } from '@rocket.ch import { UIKitIncomingInteractionContainerType } from '@rocket.chat/apps-engine/definition/uikit/UIKitIncomingInteractionContainer'; import { IUser } from '@rocket.chat/apps-engine/definition/users'; import { AppSetting } from '../config/Settings'; +import { ActionIds } from '../enum/ActionIds'; import { createLivechatMessage, deleteAllActionBlocks } from '../lib/Message'; +import { closeChat, performHandover } from '../lib/Room'; import { getAppSettingValue } from '../lib/Settings'; export class ExecuteLivechatBlockActionHandler { @@ -19,8 +21,7 @@ export class ExecuteLivechatBlockActionHandler { public async run(): Promise { try { const interactionData = this.context.getInteractionData(); - - const { visitor, room, container: { id, type }, value } = interactionData; + const { visitor, room, container: { id, type }, value, actionId } = interactionData; if (type !== UIKitIncomingInteractionContainerType.MESSAGE) { return this.context.getInteractionResponder().successResponse(); @@ -35,7 +36,20 @@ export class ExecuteLivechatBlockActionHandler { const appUser = await this.read.getUserReader().getAppUser(this.app.getID()) as IUser; - await createLivechatMessage(rid, this.read, this.modify, { text: value }, visitor); + switch (actionId) { + case ActionIds.PERFORM_HANDOVER: + const targetDepartment: string = await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); + await performHandover(this.modify, this.read, rid, visitor.token, targetDepartment); + break; + + case ActionIds.CLOSE_CHAT: + await closeChat(this.modify, this.read, rid); + break; + + default: + await createLivechatMessage(rid, this.read, this.modify, { text: value }, visitor); + break; + } const { value: hideQuickRepliesSetting } = await this.read.getEnvironmentReader().getSettings().getById(AppSetting.DialogflowHideQuickReplies); if (hideQuickRepliesSetting) { From 8618ec489cc111ef24ec66e882f4edd96c851f56 Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Sat, 5 Sep 2020 02:29:45 +0530 Subject: [PATCH 02/13] typo fix --- docs/QuickReplies.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/QuickReplies.md b/docs/QuickReplies.md index 9d8ffff..27b517b 100644 --- a/docs/QuickReplies.md +++ b/docs/QuickReplies.md @@ -29,7 +29,7 @@ ## Pre-Programmed Buttons -This are buttons that performs specific actions in the app. You can add them by simply pasting the following block in your Quick Replies payload. **Note**: You can change the `text` and `buttonStyle` parameters as per your requirements, but only use the provided `actionId` for the button you want to add. +These buttons perform a specific action in the app. You can add them by simply pasting the following block in your Quick Replies payload. **Note**: You can change the `text` and `buttonStyle` parameters as per your requirements, but only use the provided `actionId` for the button you want to add. ### Handover Button From a87740469d975c94bba091790572cd81e02d90ad Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Wed, 9 Sep 2020 15:59:13 +0530 Subject: [PATCH 03/13] adding salesforce handover button --- docs/QuickReplies.md | 44 ++++++++++++++++++++ enum/ActionIds.ts | 1 + enum/Dialogflow.ts | 1 + handler/ExecuteLivechatBlockActionHandler.ts | 8 +++- lib/Message.ts | 2 +- 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/docs/QuickReplies.md b/docs/QuickReplies.md index 27b517b..fc01063 100644 --- a/docs/QuickReplies.md +++ b/docs/QuickReplies.md @@ -35,6 +35,16 @@ These buttons perform a specific action in the app. You can add them by simply p - On clicking this button, the visitor will be handed over to another departement. You can set the target department in the app setting called **Target Department for Handover**. Add the following block in your Quick Replies payload, with **actionId** set as `df_perform_handover`, to include this button in your response: +- Parameters: + +| Param Name | Dependency | Param Type | Acceptable Value | +|:-------------:|:------------:|:----------:|:---------------------:| +| `actionId` | **Required** | String | `df_perform_handover` | +| `text` | **Required** | String | **Any** | +| `buttonStyle` | **Optional** | String | `primary` or `danger` | + +- Example Structure: + ``` { "text": "Perform Handover", @@ -47,6 +57,16 @@ These buttons perform a specific action in the app. You can add them by simply p - When visitor clicks this button, the chat session will be closed. Add the following block in your Quick Replies payload, with **actionId** set as `df_close_chat`, to include this button in your response: +- Parameters: + +| Param Name | Dependency | Param Type | Acceptable Value | +|:-------------:|:------------:|:----------:|:---------------------:| +| `actionId` | **Required** | String | `df_close_chat` | +| `text` | **Required** | String | **Any** | +| `buttonStyle` | **Optional** | String | `primary` or `danger` | + +- Example Structure: + ``` { "text": "Close Chat", @@ -55,6 +75,30 @@ These buttons perform a specific action in the app. You can add them by simply p } ``` +### Salesforce Handover Button + +- If you are using Salesforce Liveagent integration app along side your Dialogflow chatbot, then you can use this button payload to perform handover and initiate chat session with given Salesforce **buttonId**. Add the following block in your Quick Replies payload, with **actionId** set as `sf_handover_with_buttonid` and **salesforceButtonId** set to the buttonId of your Liveagent instance, to include this button in your response: + +- Parameters: + +| Param Name | Dependency | Param Type | Acceptable Value | +|:--------------------:|:------------:|:----------:|:---------------------------:| +| `actionId` | **Required** | String | `sf_handover_with_buttonid` | +| `salesforceButtonId` | **Required** | String | **Any Liveagent ButtonId** | +| `text` | **Required** | String | **Any** | +| `buttonStyle` | **Optional** | String | `primary` or `danger` | + +- Example Structure: + +``` +{ + "text": "Perform Handover", + "salesforceButtonId": "5732w000000U9T6", + "actionId": "sf_handover_with_buttonid", + "buttonStyle": "danger" +} +``` + ## Example ![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) diff --git a/enum/ActionIds.ts b/enum/ActionIds.ts index 022f9b3..2e4a11d 100644 --- a/enum/ActionIds.ts +++ b/enum/ActionIds.ts @@ -1,4 +1,5 @@ export enum ActionIds { PERFORM_HANDOVER = 'df_perform_handover', CLOSE_CHAT = 'df_close_chat', + SALESFORCE_BUTTON_ID_HANDOVER = 'sf_handover_with_buttonid', } diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 0d7b550..4f73cf9 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -15,6 +15,7 @@ export interface IDialogflowQuickReplyOptions { text: string; actionId?: string; buttonStyle?: ButtonStyle; + salesforceButtonId?: string; } export interface IDialogflowAccessToken { diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 0ab3d18..e3faaa6 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -7,7 +7,7 @@ import { IUser } from '@rocket.chat/apps-engine/definition/users'; import { AppSetting } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; import { createLivechatMessage, deleteAllActionBlocks } from '../lib/Message'; -import { closeChat, performHandover } from '../lib/Room'; +import { closeChat, performHandover, updateRoomCustomFields } from '../lib/Room'; import { getAppSettingValue } from '../lib/Settings'; export class ExecuteLivechatBlockActionHandler { @@ -46,6 +46,12 @@ export class ExecuteLivechatBlockActionHandler { await closeChat(this.modify, this.read, rid); break; + case ActionIds.SALESFORCE_BUTTON_ID_HANDOVER: + const salesforceTargetDepartment: string = await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); + updateRoomCustomFields(rid, { reqButtonId: value }, this.read, this.modify); + await performHandover(this.modify, this.read, rid, visitor.token, salesforceTargetDepartment); + break; + default: await createLivechatMessage(rid, this.read, this.modify, { text: value }, visitor); break; diff --git a/lib/Message.ts b/lib/Message.ts index b2f63aa..a842ffd 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -20,7 +20,7 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: type: TextObjectType.PLAINTEXT, text: payload.text, }, - value: payload.text, + value: payload.salesforceButtonId ? payload.salesforceButtonId : payload.text, actionId: payload.actionId || uuid(), ...payload.buttonStyle && { style: payload.buttonStyle }, } as IButtonElement)); From 665c77b62bd22e44fd0d28dcf65f4acb5ffe9c92 Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Wed, 9 Sep 2020 18:51:04 +0530 Subject: [PATCH 04/13] removing salesforce handover button --- docs/QuickReplies.md | 24 -------------------- enum/ActionIds.ts | 1 - enum/Dialogflow.ts | 1 - handler/ExecuteLivechatBlockActionHandler.ts | 8 +------ lib/Message.ts | 2 +- 5 files changed, 2 insertions(+), 34 deletions(-) diff --git a/docs/QuickReplies.md b/docs/QuickReplies.md index fc01063..db9021b 100644 --- a/docs/QuickReplies.md +++ b/docs/QuickReplies.md @@ -75,30 +75,6 @@ These buttons perform a specific action in the app. You can add them by simply p } ``` -### Salesforce Handover Button - -- If you are using Salesforce Liveagent integration app along side your Dialogflow chatbot, then you can use this button payload to perform handover and initiate chat session with given Salesforce **buttonId**. Add the following block in your Quick Replies payload, with **actionId** set as `sf_handover_with_buttonid` and **salesforceButtonId** set to the buttonId of your Liveagent instance, to include this button in your response: - -- Parameters: - -| Param Name | Dependency | Param Type | Acceptable Value | -|:--------------------:|:------------:|:----------:|:---------------------------:| -| `actionId` | **Required** | String | `sf_handover_with_buttonid` | -| `salesforceButtonId` | **Required** | String | **Any Liveagent ButtonId** | -| `text` | **Required** | String | **Any** | -| `buttonStyle` | **Optional** | String | `primary` or `danger` | - -- Example Structure: - -``` -{ - "text": "Perform Handover", - "salesforceButtonId": "5732w000000U9T6", - "actionId": "sf_handover_with_buttonid", - "buttonStyle": "danger" -} -``` - ## Example ![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) diff --git a/enum/ActionIds.ts b/enum/ActionIds.ts index 2e4a11d..022f9b3 100644 --- a/enum/ActionIds.ts +++ b/enum/ActionIds.ts @@ -1,5 +1,4 @@ export enum ActionIds { PERFORM_HANDOVER = 'df_perform_handover', CLOSE_CHAT = 'df_close_chat', - SALESFORCE_BUTTON_ID_HANDOVER = 'sf_handover_with_buttonid', } diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 4f73cf9..0d7b550 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -15,7 +15,6 @@ export interface IDialogflowQuickReplyOptions { text: string; actionId?: string; buttonStyle?: ButtonStyle; - salesforceButtonId?: string; } export interface IDialogflowAccessToken { diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index e3faaa6..0ab3d18 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -7,7 +7,7 @@ import { IUser } from '@rocket.chat/apps-engine/definition/users'; import { AppSetting } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; import { createLivechatMessage, deleteAllActionBlocks } from '../lib/Message'; -import { closeChat, performHandover, updateRoomCustomFields } from '../lib/Room'; +import { closeChat, performHandover } from '../lib/Room'; import { getAppSettingValue } from '../lib/Settings'; export class ExecuteLivechatBlockActionHandler { @@ -46,12 +46,6 @@ export class ExecuteLivechatBlockActionHandler { await closeChat(this.modify, this.read, rid); break; - case ActionIds.SALESFORCE_BUTTON_ID_HANDOVER: - const salesforceTargetDepartment: string = await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); - updateRoomCustomFields(rid, { reqButtonId: value }, this.read, this.modify); - await performHandover(this.modify, this.read, rid, visitor.token, salesforceTargetDepartment); - break; - default: await createLivechatMessage(rid, this.read, this.modify, { text: value }, visitor); break; diff --git a/lib/Message.ts b/lib/Message.ts index a842ffd..b2f63aa 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -20,7 +20,7 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: type: TextObjectType.PLAINTEXT, text: payload.text, }, - value: payload.salesforceButtonId ? payload.salesforceButtonId : payload.text, + value: payload.text, actionId: payload.actionId || uuid(), ...payload.buttonStyle && { style: payload.buttonStyle }, } as IButtonElement)); From 79f86f28932a50b646d9d7467685598722981e51 Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Thu, 1 Oct 2020 23:59:06 +0530 Subject: [PATCH 05/13] fixing handover button and adding optional param --- config/Settings.ts | 1 + docs/QuickReplies.md | 17 ++++----- enum/Dialogflow.ts | 1 + handler/ExecuteLivechatBlockActionHandler.ts | 11 ++++-- lib/Message.ts | 38 ++++++++++++++------ 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/config/Settings.ts b/config/Settings.ts index f52cb84..02461b9 100644 --- a/config/Settings.ts +++ b/config/Settings.ts @@ -15,6 +15,7 @@ export enum AppSetting { export enum DefaultMessage { DEFAULT_DialogflowServiceUnavailableMessage = 'Sorry, I\'m having trouble answering your question.', + DEFAULT_DialogflowRequestFailedMessage = 'Apologies but your request cannot be completed.', DEFAULT_DialogflowHandoverMessage = 'Transferring to an online agent', DEFAULT_DialogflowCloseChatMessage = 'Closing the chat, Goodbye', } diff --git a/docs/QuickReplies.md b/docs/QuickReplies.md index db9021b..56213c8 100644 --- a/docs/QuickReplies.md +++ b/docs/QuickReplies.md @@ -37,11 +37,12 @@ These buttons perform a specific action in the app. You can add them by simply p - Parameters: -| Param Name | Dependency | Param Type | Acceptable Value | -|:-------------:|:------------:|:----------:|:---------------------:| -| `actionId` | **Required** | String | `df_perform_handover` | -| `text` | **Required** | String | **Any** | -| `buttonStyle` | **Optional** | String | `primary` or `danger` | +| Param Name | Dependency | Param Type | Acceptable Value | +|:----------------:|:------------:|:----------:|:-----------------------------------:| +| `actionId` | **Required** | String | `df_perform_handover` | +| `text` | **Required** | String | **Any** | +| `buttonStyle` | **Optional** | String | `primary` or `danger` | +| `departmentName` | **Optional** | String | **Any Omnichannel department name** | - Example Structure: @@ -49,7 +50,8 @@ These buttons perform a specific action in the app. You can add them by simply p { "text": "Perform Handover", "buttonStyle": "primary", - "actionId": "df_perform_handover" + "actionId": "df_perform_handover", + "departmentName": "sales" } ``` @@ -77,5 +79,4 @@ These buttons perform a specific action in the app. You can add them by simply p ## Example -![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) - +![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) \ No newline at end of file diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 0d7b550..263a6af 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -15,6 +15,7 @@ export interface IDialogflowQuickReplyOptions { text: string; actionId?: string; buttonStyle?: ButtonStyle; + departmentName?: string; } export interface IDialogflowAccessToken { diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 0ab3d18..5a3d1ca 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -4,9 +4,9 @@ import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; import { IUIKitResponse, UIKitLivechatBlockInteractionContext } from '@rocket.chat/apps-engine/definition/uikit'; import { UIKitIncomingInteractionContainerType } from '@rocket.chat/apps-engine/definition/uikit/UIKitIncomingInteractionContainer'; import { IUser } from '@rocket.chat/apps-engine/definition/users'; -import { AppSetting } from '../config/Settings'; +import { AppSetting, DefaultMessage } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; -import { createLivechatMessage, deleteAllActionBlocks } from '../lib/Message'; +import { createLivechatMessage, createMessage, deleteAllActionBlocks } from '../lib/Message'; import { closeChat, performHandover } from '../lib/Room'; import { getAppSettingValue } from '../lib/Settings'; @@ -38,7 +38,12 @@ export class ExecuteLivechatBlockActionHandler { switch (actionId) { case ActionIds.PERFORM_HANDOVER: - const targetDepartment: string = await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); + let targetDepartment: string = await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); + if (value !== undefined) { targetDepartment = value; } + if (!targetDepartment) { + await createMessage(rid, this.read, this.modify, { text: DefaultMessage.DEFAULT_DialogflowRequestFailedMessage }); + break; + } await performHandover(this.modify, this.read, rid, visitor.token, targetDepartment); break; diff --git a/lib/Message.ts b/lib/Message.ts index b2f63aa..aaa96db 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -3,6 +3,7 @@ import { IVisitor } from '@rocket.chat/apps-engine/definition/livechat'; import { BlockElementType, BlockType, IActionsBlock, 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'; import { IDialogflowMessage, IDialogflowQuickReplies, IDialogflowQuickReplyOptions } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { uuid } from './Helper'; @@ -14,16 +15,33 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: for (const message of messages) { const { text, options } = message as IDialogflowQuickReplies; if (text && options) { - const elements: Array = options.map((payload: IDialogflowQuickReplyOptions) => ({ - type: BlockElementType.BUTTON, - text: { - type: TextObjectType.PLAINTEXT, - text: payload.text, - }, - value: payload.text, - actionId: payload.actionId || uuid(), - ...payload.buttonStyle && { style: payload.buttonStyle }, - } as IButtonElement)); + const elements: Array = options.map((payload: IDialogflowQuickReplyOptions) => { + if (payload.actionId && payload.actionId === ActionIds.PERFORM_HANDOVER) { + const buttonElement: IButtonElement = { + type: BlockElementType.BUTTON, + actionId: payload.actionId || uuid(), + text: { + text: payload.text, + type: TextObjectType.PLAINTEXT, + }, + value: payload.departmentName ? payload.departmentName : undefined, + ...payload.buttonStyle && { style: payload.buttonStyle }, + }; + return buttonElement; + } else { + const buttonElement: IButtonElement = { + type: BlockElementType.BUTTON, + actionId: payload.actionId || uuid(), + text: { + text: payload.text, + type: TextObjectType.PLAINTEXT, + }, + value: payload.text, + ...payload.buttonStyle && { style: payload.buttonStyle }, + }; + return buttonElement; + } + }); const actionsBlock: IActionsBlock = { type: BlockType.ACTIONS, elements }; From f74d742d0068e11b67a70af2aa4bf9ea7777512a Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Fri, 2 Oct 2020 00:21:16 +0530 Subject: [PATCH 06/13] shorthanding the code --- lib/Message.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/Message.ts b/lib/Message.ts index aaa96db..15842da 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -16,19 +16,6 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: const { text, options } = message as IDialogflowQuickReplies; if (text && options) { const elements: Array = options.map((payload: IDialogflowQuickReplyOptions) => { - if (payload.actionId && payload.actionId === ActionIds.PERFORM_HANDOVER) { - const buttonElement: IButtonElement = { - type: BlockElementType.BUTTON, - actionId: payload.actionId || uuid(), - text: { - text: payload.text, - type: TextObjectType.PLAINTEXT, - }, - value: payload.departmentName ? payload.departmentName : undefined, - ...payload.buttonStyle && { style: payload.buttonStyle }, - }; - return buttonElement; - } else { const buttonElement: IButtonElement = { type: BlockElementType.BUTTON, actionId: payload.actionId || uuid(), @@ -39,8 +26,12 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: value: payload.text, ...payload.buttonStyle && { style: payload.buttonStyle }, }; + + if (payload.actionId && payload.actionId === ActionIds.PERFORM_HANDOVER) { + buttonElement.value = payload.departmentName ? payload.departmentName : undefined; + } + return buttonElement; - } }); const actionsBlock: IActionsBlock = { type: BlockType.ACTIONS, elements }; From 55b7c07579ccc552cd3ae9c6f50afded46e4e751 Mon Sep 17 00:00:00 2001 From: Raval Prajval Date: Fri, 2 Oct 2020 20:33:45 +0530 Subject: [PATCH 07/13] Update lib/Message.ts Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> --- lib/Message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Message.ts b/lib/Message.ts index 15842da..aa692cb 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -23,7 +23,7 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: text: payload.text, type: TextObjectType.PLAINTEXT, }, - value: payload.text, + value: payload.actionId && payload.actionId === ActionIds.PERFORM_HANDOVER ? payload.departmentName : payload.text,, ...payload.buttonStyle && { style: payload.buttonStyle }, }; From 07064607af570550e9a59b2748e46ded0e5a0dbe Mon Sep 17 00:00:00 2001 From: Raval Prajval Date: Fri, 2 Oct 2020 21:09:02 +0530 Subject: [PATCH 08/13] Update Message.ts --- lib/Message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Message.ts b/lib/Message.ts index aa692cb..15842da 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -23,7 +23,7 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: text: payload.text, type: TextObjectType.PLAINTEXT, }, - value: payload.actionId && payload.actionId === ActionIds.PERFORM_HANDOVER ? payload.departmentName : payload.text,, + value: payload.text, ...payload.buttonStyle && { style: payload.buttonStyle }, }; From 1f29da3fd41cd5e2196b8f9cb78e93db2965c4c4 Mon Sep 17 00:00:00 2001 From: Raval Prajval Date: Fri, 2 Oct 2020 21:41:11 +0530 Subject: [PATCH 09/13] Update QuickReplies.md --- docs/QuickReplies.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/QuickReplies.md b/docs/QuickReplies.md index 56213c8..1969d3e 100644 --- a/docs/QuickReplies.md +++ b/docs/QuickReplies.md @@ -33,7 +33,9 @@ These buttons perform a specific action in the app. You can add them by simply p ### Handover Button -- On clicking this button, the visitor will be handed over to another departement. You can set the target department in the app setting called **Target Department for Handover**. Add the following block in your Quick Replies payload, with **actionId** set as `df_perform_handover`, to include this button in your response: +- On clicking this button, the visitor will be handed over to another departement. You can set the target department in the app setting called **Target Department for Handover** or add a `departmentName` param in your payload. On failing to provide a department name in either way, will send a request failure message back to the visitor, when visitor clicks the button. + +- Add the following block in your Quick Replies payload, with **actionId** set as `df_perform_handover`, to include this button in your response: - Parameters: @@ -79,4 +81,4 @@ These buttons perform a specific action in the app. You can add them by simply p ## Example -![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) \ No newline at end of file +![Pre-Programmed Example Payload](https://user-images.githubusercontent.com/41849970/92283593-d5e70a80-ef1d-11ea-8860-e91a4980515f.png) From 346eb42e3c95cd15455d7c1306e773bf73683d78 Mon Sep 17 00:00:00 2001 From: Raval Prajval Date: Fri, 2 Oct 2020 21:47:44 +0530 Subject: [PATCH 10/13] Update handler/ExecuteLivechatBlockActionHandler.ts Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> --- handler/ExecuteLivechatBlockActionHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 5a3d1ca..42282c3 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -38,7 +38,7 @@ export class ExecuteLivechatBlockActionHandler { switch (actionId) { case ActionIds.PERFORM_HANDOVER: - let targetDepartment: string = await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); + const targetDepartment: string = value || await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); if (value !== undefined) { targetDepartment = value; } if (!targetDepartment) { await createMessage(rid, this.read, this.modify, { text: DefaultMessage.DEFAULT_DialogflowRequestFailedMessage }); From a3c7ba163d280a478a0c49cfadfd5b09e9cecb4a Mon Sep 17 00:00:00 2001 From: Raval Prajval Date: Fri, 2 Oct 2020 21:47:54 +0530 Subject: [PATCH 11/13] Update handler/ExecuteLivechatBlockActionHandler.ts Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> --- handler/ExecuteLivechatBlockActionHandler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 42282c3..174c014 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -39,7 +39,6 @@ export class ExecuteLivechatBlockActionHandler { switch (actionId) { case ActionIds.PERFORM_HANDOVER: const targetDepartment: string = value || await getAppSettingValue(this.read, AppSetting.FallbackTargetDepartment); - if (value !== undefined) { targetDepartment = value; } if (!targetDepartment) { await createMessage(rid, this.read, this.modify, { text: DefaultMessage.DEFAULT_DialogflowRequestFailedMessage }); break; From 7bd8796ec74b38e8b1849bb0a357497371e6e3dd Mon Sep 17 00:00:00 2001 From: Raval Prajval Date: Thu, 8 Oct 2020 13:09:40 +0530 Subject: [PATCH 12/13] Update config/Settings.ts Co-authored-by: Renato Becker --- config/Settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/Settings.ts b/config/Settings.ts index 02461b9..8c6ca0a 100644 --- a/config/Settings.ts +++ b/config/Settings.ts @@ -15,7 +15,7 @@ export enum AppSetting { export enum DefaultMessage { DEFAULT_DialogflowServiceUnavailableMessage = 'Sorry, I\'m having trouble answering your question.', - DEFAULT_DialogflowRequestFailedMessage = 'Apologies but your request cannot be completed.', + DEFAULT_DialogflowRequestFailedMessage = 'Sorry, something went wrong.', DEFAULT_DialogflowHandoverMessage = 'Transferring to an online agent', DEFAULT_DialogflowCloseChatMessage = 'Closing the chat, Goodbye', } From d7c061f8cd82bba98629b811504effc428618a21 Mon Sep 17 00:00:00 2001 From: Prajval Raval Date: Thu, 8 Oct 2020 13:57:00 +0530 Subject: [PATCH 13/13] adding data prop --- enum/Dialogflow.ts | 4 +++- lib/Message.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 263a6af..77b2505 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -15,7 +15,9 @@ export interface IDialogflowQuickReplyOptions { text: string; actionId?: string; buttonStyle?: ButtonStyle; - departmentName?: string; + data?: { + [prop: string]: any; + }; } export interface IDialogflowAccessToken { diff --git a/lib/Message.ts b/lib/Message.ts index 15842da..6049c0a 100644 --- a/lib/Message.ts +++ b/lib/Message.ts @@ -28,7 +28,7 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify: }; if (payload.actionId && payload.actionId === ActionIds.PERFORM_HANDOVER) { - buttonElement.value = payload.departmentName ? payload.departmentName : undefined; + buttonElement.value = payload.data && payload.data.departmentName ? payload.data.departmentName : undefined; } return buttonElement;