Skip to content

Commit 15672f7

Browse files
committed
Fix PR.
1 parent f45f243 commit 15672f7

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/Helper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ export const base64EncodeData = (data: string, len: number, b64x: string, b64pad
3434

3535
return dst;
3636
};
37+
38+
export const uuid = (): string => {
39+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
40+
const r = Math.random() * 16 | 0;
41+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
42+
return v.toString(16);
43+
});
44+
};

lib/Message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { IUser } from '@rocket.chat/apps-engine/definition/users';
55
import { AppSetting } from '../config/Settings';
66
import { IDialogflowMessage, IDialogflowQuickReplies, IDialogflowQuickReplyOptions } from '../enum/Dialogflow';
77
import { Logs } from '../enum/Logs';
8+
import { uuid } from './Helper';
89
import { getAppSettingValue } from './Settings';
910

1011
export const createDialogflowMessage = async (rid: string, read: IRead, modify: IModify, dialogflowMessage: IDialogflowMessage): Promise<any> => {
1112
const { messages = [] } = dialogflowMessage;
1213

1314
for (const message of messages) {
1415
const { text, options } = message as IDialogflowQuickReplies;
15-
1616
if (text && options) {
1717
const elements: Array<IButtonElement> = options.map((payload: IDialogflowQuickReplyOptions) => ({
1818
type: BlockElementType.BUTTON,
@@ -21,7 +21,7 @@ export const createDialogflowMessage = async (rid: string, read: IRead, modify:
2121
text: payload.text,
2222
},
2323
value: payload.text,
24-
actionId: payload.actionId ? payload.actionId : String(Date.now()),
24+
actionId: payload.actionId || uuid(),
2525
...payload.buttonStyle && { style: payload.buttonStyle },
2626
} as IButtonElement));
2727

0 commit comments

Comments
 (0)