From 61a6c47ab2d9a5d88467f2f467cfe62fb56c4798 Mon Sep 17 00:00:00 2001 From: Dmitrii Ostasevich <90881+kwinto@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:35:24 +0200 Subject: [PATCH 1/2] update xApp interfaces --- src/interfaces/messageData.ts | 374 ++++++++++++++++++---------------- 1 file changed, 195 insertions(+), 179 deletions(-) diff --git a/src/interfaces/messageData.ts b/src/interfaces/messageData.ts index 363bd43..b112ee3 100644 --- a/src/interfaces/messageData.ts +++ b/src/interfaces/messageData.ts @@ -1,279 +1,295 @@ -import { IAdaptiveCard } from 'adaptivecards'; +import { IAdaptiveCard } from "adaptivecards"; /** - * - * Fields used by chat-components and currently added by the Webchat Client. + * + * Fields used by chat-components and currently added by the Webchat Client. * Expected to be present in the socket message sent by endpoint at some point. -*/ + */ export interface IWebchatClientMessage { - avatarUrl?: string; - avatarName?: string; - timestamp?: string; + avatarUrl?: string; + avatarName?: string; + timestamp?: string; } // We temporary extend IMessage with IWebchatClientMessage // to avoid making changes in the codebase. See prev. comment. -export interface IMessage extends IWebchatClientMessage{ - text?: string | null; - data?: IMessageData; - source?: "user" | "bot" | "engagement" | "agent"; - disableSensitiveLogging?: boolean; - traceId?: string; -}; +export interface IMessage extends IWebchatClientMessage { + text?: string | null; + data?: IMessageData; + source?: "user" | "bot" | "engagement" | "agent"; + disableSensitiveLogging?: boolean; + traceId?: string; +} export interface IMessageData { - _cognigy?: ICognigyData; - _plugin?: IPluginDatepicker | IPluginXApp | IPluginXAppSubmit; - attachments?: IUploadFileAttachmentData[]; + _cognigy?: ICognigyData; + _plugin?: IPluginDatepicker; + attachments?: IUploadFileAttachmentData[]; } export interface ICognigyData { - _default?: IDefaultMessage; - _webchat?: IWebchatMessage | IAdaptiveCardMessage; - _plugin?: unknown; - _facebook?: IWebchatMessage; - syncWebchatWithFacebook?: boolean; - controlCommands?: ISetRatingControlCommand[]; -} - -export interface IPluginXApp { - type: "x-app"; - data: { - sessionUrl: string; - openButtonLabel?: string; - immediateOpen?: boolean; - headerTitle?: string; - }; + _default?: IDefaultMessage; + _webchat?: IWebchatMessage | IAdaptiveCardMessage; + _plugin?: unknown; + _app?: unknown; + _facebook?: IWebchatMessage; + syncWebchatWithFacebook?: boolean; + controlCommands?: ISetRatingControlCommand[]; } export interface IPluginXAppSubmit { - type: "x-app-submit"; - data: { - success: boolean; - }; + type: "x-app-submit"; + data: { + success: boolean; + text?: string; + }; } export interface IPluginDatepicker { - type: "date-picker"; - data: { - eventName?: string; - locale?: string; - enableTime?: string | boolean; - defaultDate?: string, - mode?: "range" | "single" | "multiple"; - wantDisable?: string | boolean; - enable_disable?: string[] | boolean | null; - function_enable_disable?: string; - minDate?: string; - maxDate?: string; - openPickerButtonText?: string; - cancelButtonText?: string; - submitButtonText?: string; - time_24hr?: string | boolean; - dateFormat?: string; - defaultHour?: number; - defaultMinute?: number; - enableSeconds?: number; - hourIncrement?: number; - minuteIncrement?: number; - noCalendar?: boolean; - weekNumbers?: boolean; - }; + type: "date-picker"; + data: { + eventName?: string; + locale?: string; + enableTime?: string | boolean; + defaultDate?: string; + mode?: "range" | "single" | "multiple"; + wantDisable?: string | boolean; + enable_disable?: string[] | boolean | null; + function_enable_disable?: string; + minDate?: string; + maxDate?: string; + openPickerButtonText?: string; + cancelButtonText?: string; + submitButtonText?: string; + time_24hr?: string | boolean; + dateFormat?: string; + defaultHour?: number; + defaultMinute?: number; + enableSeconds?: number; + hourIncrement?: number; + minuteIncrement?: number; + noCalendar?: boolean; + weekNumbers?: boolean; + }; } export type TButtonType = "postback" | "web_url" | "phone_number"; /** * Default Message Interfaces -*/ + */ export interface IDefaultMessage { - _quickReplies?: IDefaultQuickReplies; - _gallery?: IDefaultGallery; - _buttons?: IDefaultButtons; - _list?: IDefaultList; - _audio?: IDefaultAudio; - _image?: IDefaultImage; - _video?: IDefaultVideo; - _adaptiveCard?: IAdaptiveCardMessage; -}; + _quickReplies?: IDefaultQuickReplies; + _gallery?: IDefaultGallery; + _buttons?: IDefaultButtons; + _list?: IDefaultList; + _audio?: IDefaultAudio; + _image?: IDefaultImage; + _video?: IDefaultVideo; + _adaptiveCard?: IAdaptiveCardMessage; +} export interface IDefaultQuickReplies { - type: string; - quickReplies: IDefaultQuickReply[]; - text: string; + type: string; + quickReplies: IDefaultQuickReply[]; + text: string; } export interface IDefaultButtons { - type: string; - buttons: IDefaultButton[]; - text: string; + type: string; + buttons: IDefaultButton[]; + text: string; } export interface IDefaultQuickReply { - id: number; - title: string; - imageAltText?: string; - imageUrl?: string; - contentType: string; - payload: string; + id: number; + title: string; + imageAltText?: string; + imageUrl?: string; + contentType: string; + payload: string; } export interface IDefaultButton { - id?: number; - title: string; - type: TButtonType; - payload?: string; - url?: string; - target?: "_blank" | "_self"; + id?: number; + title: string; + type: TButtonType; + payload?: string; + url?: string; + target?: "_blank" | "_self"; } export interface IDefaultGallery { - type: "carousel"; - items: IDefaultGalleryItem[]; + type: "carousel"; + items: IDefaultGalleryItem[]; } export interface IDefaultItem { - title: string; - subtitle: string; - imageUrl: string; - buttons?: IDefaultButton[] | null; - imageAltText?: string; + title: string; + subtitle: string; + imageUrl: string; + buttons?: IDefaultButton[] | null; + imageAltText?: string; } export interface IDefaultGalleryItem extends IDefaultItem { - id: number; + id: number; } export interface IDefaultList { - type: "list"; - items?: IDefaultListItem[]; - button: IDefaultListButton; + type: "list"; + items?: IDefaultListItem[]; + button: IDefaultListButton; } export interface IDefaultListItem extends IDefaultItem { - defaultActionUrl: string; + defaultActionUrl: string; } export interface IDefaultListButton extends IDefaultButton { - condition: string; + condition: string; } export interface IDefaultAudio { - type: "audio"; - audioUrl: string; - audioAltText: string; + type: "audio"; + audioUrl: string; + audioAltText: string; } export interface IDefaultImage { - type: "image"; - imageUrl: string; - imageAltText: string; - buttons?: IWebchatButton[] | null; + type: "image"; + imageUrl: string; + imageAltText: string; + buttons?: IWebchatButton[] | null; } export interface IDefaultVideo { - type: "video"; - videoUrl: string; - videoAltText: string; + type: "video"; + videoUrl: string; + videoAltText: string; } export interface IAdaptiveCardMessage { - type: "adaptiveCard"; - adaptiveCard: IAdaptiveCard; + type: "adaptiveCard"; + adaptiveCard: IAdaptiveCard; } /** * Webchat Message Interfaces -*/ + */ export interface IWebchatMessage { - message?: { - text?: string; - quick_replies?: IWebchatQuickReply[]; - attachment?: IWebchatTemplateAttachment | IWebchatAudioAttachment | IWebchatImageAttachment | IWebchatVideoAttachment; - }, + message?: { + text?: string; + quick_replies?: IWebchatQuickReply[]; + attachment?: + | IWebchatTemplateAttachment + | IWebchatAudioAttachment + | IWebchatImageAttachment + | IWebchatVideoAttachment; + }; } export interface IWebchatQuickReply { - title: string; - payload?: string; - image_alt_text?: string; - image_url?: string; - content_type: string; + title: string; + payload?: string; + image_alt_text?: string; + image_url?: string; + content_type: string; } export interface IWebchatTemplateAttachment { - type: "template"; - payload: { - template_type: "generic" | "button" | "list"; - elements?: IWebchatAttachmentElement[]; - buttons?: IWebchatButton[] | null; - text?: string; - top_element_style?: "compact" | "large" | boolean; - }; + type: "template"; + payload: { + template_type: "generic" | "button" | "list"; + elements?: IWebchatAttachmentElement[]; + buttons?: IWebchatButton[] | null; + text?: string; + top_element_style?: "compact" | "large" | boolean; + }; } export interface IWebchatAudioAttachment { - type: "audio"; - payload: { - url: string; - altText: string; - }; + type: "audio"; + payload: { + url: string; + altText: string; + }; } export interface IWebchatImageAttachment { - type: "image"; - payload: { - url: string; - altText: string; - buttons?: IWebchatButton[] | null; - }; + type: "image"; + payload: { + url: string; + altText: string; + buttons?: IWebchatButton[] | null; + }; } export interface IWebchatVideoAttachment { - type: "video"; - payload: { - url: string; - altText: string; - }; + type: "video"; + payload: { + url: string; + altText: string; + }; } export interface IWebchatAttachmentElement { - title: string; - subtitle: string; - image_url: string; - image_alt_text?: string; - buttons?: IWebchatButton[] | null; - default_action?: { - type: string; - url?: string; - }; + title: string; + subtitle: string; + image_url: string; + image_alt_text?: string; + buttons?: IWebchatButton[] | null; + default_action?: { + type: string; + url?: string; + }; } export interface IWebchatButton { - title: string; - type: TButtonType; - payload?: string; - url?: string; - webview_height_ratio?: string; - messenger_extensions?: boolean; - target?: "_blank" | "_self"; + title: string; + type: TButtonType; + payload?: string; + url?: string; + webview_height_ratio?: string; + messenger_extensions?: boolean; + target?: "_blank" | "_self"; } export interface ISetRatingControlCommand { - type: "setRating"; - parameters: { - rating: number; - comment?: string; - showRatingStatus?: boolean; - }; + type: "setRating"; + parameters: { + rating: number; + comment?: string; + showRatingStatus?: boolean; + }; } export interface IUploadFileAttachmentData { - runtimeFileId: string; - fileName: string; - status?: "infected" | "scanned"; - mimeType: string; - size: number; - url: string; -} \ No newline at end of file + runtimeFileId: string; + fileName: string; + status?: "infected" | "scanned"; + mimeType: string; + size: number; + url: string; +} + +export interface IXAppOverlayMessage extends IMessage { + data: { + _cognigy: { + _app: { + overlaySettings: ISetAppStateOverlaySettings; + url: string; + }; + }; + }; +} + +export interface ISetAppStateOverlaySettings { + autoOpen: boolean; + closeOnSubmit: boolean; + feedbackMessage: string; + screenTitle: string; + sendEventOnCloseIconClick: boolean; + showCloseIcon: boolean; +} From a66ed7495933628ac744b454aab1ada1688e5b9d Mon Sep 17 00:00:00 2001 From: Dmitrii Ostasevich <90881+kwinto@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:43:37 +0200 Subject: [PATCH 2/2] update button types --- src/interfaces/messageData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/messageData.ts b/src/interfaces/messageData.ts index b112ee3..bb25031 100644 --- a/src/interfaces/messageData.ts +++ b/src/interfaces/messageData.ts @@ -72,7 +72,7 @@ export interface IPluginDatepicker { }; } -export type TButtonType = "postback" | "web_url" | "phone_number"; +export type TButtonType = "postback" | "web_url" | "phone_number" | "openXApp"; /** * Default Message Interfaces