diff --git a/apps/meteor/app/lib/server/functions/processWebhookMessage.ts b/apps/meteor/app/lib/server/functions/processWebhookMessage.js similarity index 70% rename from apps/meteor/app/lib/server/functions/processWebhookMessage.ts rename to apps/meteor/app/lib/server/functions/processWebhookMessage.js index 5671f47adf47..1e5c34b287bb 100644 --- a/apps/meteor/app/lib/server/functions/processWebhookMessage.ts +++ b/apps/meteor/app/lib/server/functions/processWebhookMessage.js @@ -1,4 +1,3 @@ -import type { IMessage, IUser } from '@rocket.chat/core-typings'; import { Meteor } from 'meteor/meteor'; import _ from 'underscore'; @@ -8,39 +7,9 @@ import { validateRoomMessagePermissionsAsync } from '../../../authorization/serv import { getRoomByNameOrIdWithOptionToJoin } from './getRoomByNameOrIdWithOptionToJoin'; import { sendMessage } from './sendMessage'; -type Payload = { - channel?: string | string[]; - roomId?: string | string[]; - text?: IMessage['msg']; - msg?: IMessage['msg']; // overrided if text is present - username?: IMessage['alias']; - alias?: IMessage['alias']; // overrided if username is present - icon_emoji?: IMessage['emoji']; - emoji?: IMessage['emoji']; // overrided if icon_emoji is present - icon_url?: IMessage['avatar']; - avatar?: IMessage['avatar']; // overrided if icon_url is present - attachments?: IMessage['attachments']; - parseUrls?: boolean; - bot?: IMessage['bot']; - groupable?: IMessage['groupable']; - tmid?: IMessage['tmid']; -}; - -type DefaultValues = { - channel: string | string[]; - alias: string; - avatar: string; - emoji: string; -}; - -export const processWebhookMessage = async function ( - messageObj: Payload, - user: IUser & { username: Exclude }, - defaultValues: DefaultValues = { channel: '', alias: '', avatar: '', emoji: '' }, -) { +export const processWebhookMessage = async function (messageObj, user, defaultValues = { channel: '', alias: '', avatar: '', emoji: '' }) { const sentData = []; - - const channels: Array = [...new Set(messageObj.channel || messageObj.roomId || defaultValues.channel)]; + const channels = [].concat(messageObj.channel || messageObj.roomId || defaultValues.channel); for await (const channel of channels) { const channelType = channel[0]; @@ -100,7 +69,7 @@ export const processWebhookMessage = async function ( messageObj.attachments = undefined; } - const message: Partial & { parseUrls?: boolean } = { + const message = { alias: messageObj.username || messageObj.alias || defaultValues.alias, msg: trim(messageObj.text || messageObj.msg || ''), attachments: messageObj.attachments || [], @@ -122,7 +91,7 @@ export const processWebhookMessage = async function ( if (Array.isArray(message.attachments)) { for (let i = 0; i < message.attachments.length; i++) { - const attachment = message.attachments[i] as Exclude[number] & { msg?: string }; + const attachment = message.attachments[i]; if (attachment.msg) { attachment.text = trim(attachment.msg); delete attachment.msg; diff --git a/packages/rest-typings/src/v1/chat.ts b/packages/rest-typings/src/v1/chat.ts index ccfaa2c4a2fa..b8def106c78a 100644 --- a/packages/rest-typings/src/v1/chat.ts +++ b/packages/rest-typings/src/v1/chat.ts @@ -697,8 +697,8 @@ const ChatGetDeletedMessagesSchema = { export const isChatGetDeletedMessagesProps = ajv.compile(ChatGetDeletedMessagesSchema); type ChatPostMessage = - | { roomId: string | string[]; text?: string; alias?: string; emoji?: string; avatar?: string; attachments?: MessageAttachment[] } - | { channel: string | string[]; text?: string; alias?: string; emoji?: string; avatar?: string; attachments?: MessageAttachment[] }; + | { roomId: string; text?: string; alias?: string; emoji?: string; avatar?: string; attachments?: MessageAttachment[] } + | { channel: string; text?: string; alias?: string; emoji?: string; avatar?: string; attachments?: MessageAttachment[] }; const ChatPostMessageSchema = { oneOf: [ @@ -706,15 +706,7 @@ const ChatPostMessageSchema = { type: 'object', properties: { roomId: { - oneOf: [ - { type: 'string' }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], + type: 'string', }, text: { type: 'string', @@ -746,16 +738,8 @@ const ChatPostMessageSchema = { { type: 'object', properties: { - roomId: { - oneOf: [ - { type: 'string' }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], + channel: { + type: 'string', }, text: { type: 'string',