Commit c4e2bb08 authored by murtaza98's avatar murtaza98

convert rich message attachments to uikit actions

parent b6aab9a2
import { IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors';
import { IMessageAction, IMessageAttachment, MessageActionType, MessageProcessingType } from '@rocket.chat/apps-engine/definition/messages';
import { BlockElementType, IButtonElement, TextObjectType, IActionsBlock, BlockType } from '@rocket.chat/apps-engine/definition/uikit';
import { AppSetting } from '../config/Settings';
import { Logs } from '../enum/Logs';
import { IRasaMessage, IRasaQuickReplies, IRasaQuickReply } from '../enum/Rasa';
......@@ -10,15 +11,18 @@ export const createRasaMessage = async (rid: string, read: IRead, modify: IModi
if (text && quickReplies) {
// rasaMessage is instanceof IRasaQuickReplies
const actions: Array<IMessageAction> = quickReplies.map((payload: IRasaQuickReply) => ({
type: MessageActionType.BUTTON,
text: payload.title,
msg: payload.payload,
msg_in_chat_window: true,
msg_processing_type: MessageProcessingType.SendMessage,
} as IMessageAction));
const attachment: IMessageAttachment = { actions };
await createMessage(rid, read, modify, { text, attachment });
const elements: Array<IButtonElement> = quickReplies.map((payload: IRasaQuickReply) => ({
type: BlockElementType.BUTTON,
text: {
type: TextObjectType.PLAINTEXT,
text: payload.title,
},
actionId: payload.title,
} as IButtonElement));
const actionsBlock: IActionsBlock = { type: BlockType.ACTIONS, elements };
await createMessage(rid, read, modify, { text, actionsBlock });
} else {
// rasaMessage is instanceof string
await createMessage(rid, read, modify, { text: rasaMessage.message });
......@@ -49,14 +53,15 @@ export const createMessage = async (rid: string, read: IRead, modify: IModify,
}
const msg = modify.getCreator().startMessage().setRoom(room).setSender(sender);
const { text, attachment } = message;
const { text, actionsBlock } = message;
if (text) {
msg.setText(text);
}
if (attachment) {
msg.addAttachment(attachment);
if (actionsBlock) {
const { elements } = actionsBlock as IActionsBlock;
msg.addBlocks(modify.getCreator().getBlockBuilder().addActionsBlock({ elements }));
}
return new Promise(async (resolve) => {
......
......@@ -29,9 +29,9 @@
}
},
"@rocket.chat/apps-engine": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.15.0.tgz",
"integrity": "sha512-gwsHa/zTYMmoSG3PP3sZfmVRDRBmIDacOAdCv1FsgJog89ZBCICeoab3VyYAdOMliV5XoygygduYFtc6rinFHQ==",
"version": "1.17.0-beta.3629",
"resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.17.0-beta.3629.tgz",
"integrity": "sha512-pQMIJ1JOlRp5wzBm6LgTWPz6Yob0whExfJJ1XcFaq1JV6FBDg6sIyehMsYpop5z8EWZHBstZZc5duN9ixxDZmw==",
"dev": true,
"requires": {
"adm-zip": "^0.4.9",
......@@ -50,9 +50,9 @@
"dev": true
},
"adm-zip": {
"version": "0.4.14",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.14.tgz",
"integrity": "sha512-/9aQCnQHF+0IiCl0qhXoK7qs//SwYE7zX8lsr/DNk1BRAHYxeLZPL4pguwK29gUEqasYQjqPtEpDRSWEkdHn9g==",
"version": "0.4.16",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.16.tgz",
"integrity": "sha512-TFi4HBKSGfIKsK5YCkKaaFG2m4PEDyViZmEwof3MTIgzimHLto6muaHVpbrljdIvIrFZzEq/p4nafOeLcYegrg==",
"dev": true
},
"ansi-styles": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment