11import { Message } from '@rocket.chat/core-services' ;
2- import type { IMessage , IUser , IRoom , IThreadMainMessage , MessageAttachment , RequiredField } from '@rocket.chat/core-typings' ;
2+ import type { IMessage , IUser , IThreadMainMessage , MessageAttachment , RequiredField } from '@rocket.chat/core-typings' ;
33import { Messages , Users , Rooms , Subscriptions } from '@rocket.chat/models' ;
44import {
55 isChatReportMessageProps ,
@@ -29,6 +29,7 @@ import {
2929 isChatGetStarredMessagesProps ,
3030 isChatGetDiscussionsProps ,
3131} from '@rocket.chat/rest-typings' ;
32+ import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv' ;
3233import { escapeRegExp } from '@rocket.chat/string-helpers' ;
3334import { Meteor } from 'meteor/meteor' ;
3435
@@ -318,6 +319,7 @@ const chatPostMessageEndpoints = API.v1.post(
318319 'chat.postMessage' ,
319320 {
320321 authRequired : true ,
322+ validateParams : isChatPostMessageProps ,
321323 body : isChatPostMessageProps ,
322324 response : {
323325 400 : ajv . compile ( {
@@ -351,7 +353,7 @@ const chatPostMessageEndpoints = API.v1.post(
351353 } ) ,
352354 200 : ajv . compile < {
353355 ts : number ;
354- channel : string | string [ ] ;
356+ channel : string ;
355357 message : IMessage ;
356358 success : boolean ;
357359 } > ( {
@@ -426,7 +428,7 @@ const chatPostMessageEndpoints = API.v1.post(
426428 } ,
427429 } ,
428430 async function action ( ) {
429- const { text, attachments } = this . bodyParams ;
431+ const { text, attachments } = this . bodyParams as ChatPostMessage ;
430432 const maxAllowedSize = settings . get < number > ( 'Message_MaxAllowedSize' ) ?? 0 ;
431433
432434 if ( text && text . length > maxAllowedSize ) {
@@ -451,7 +453,7 @@ const chatPostMessageEndpoints = API.v1.post(
451453 return API . v1 . failure ( 'unknown-error' ) ;
452454 }
453455
454- const [ message ] = await normalizeMessagesForUser ( [ messageReturn . message ] , this . userId ) ;
456+ const [ message ] = ( await normalizeMessagesForUser ( [ messageReturn . message ] , this . userId ) ) as IMessage [ ] ;
455457
456458 return API . v1 . success ( {
457459 ts : Date . now ( ) ,
0 commit comments