-
Notifications
You must be signed in to change notification settings - Fork 13.5k
refactor(api): migrate chat.postMessage endpoint to the new openAPI format #39611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Migrate chat.postMessage endpoint to make it openAPI and AJV compatible |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { Message } from '@rocket.chat/core-services'; | ||
| import type { IMessage, IThreadMainMessage } from '@rocket.chat/core-typings'; | ||
| import type { IMessage, MessageAttachment, IThreadMainMessage } from '@rocket.chat/core-typings'; | ||
| import { MessageTypes } from '@rocket.chat/message-types'; | ||
| import { Messages, Users, Rooms, Subscriptions } from '@rocket.chat/models'; | ||
| import { | ||
|
|
@@ -11,7 +11,6 @@ import { | |
| isChatDeleteProps, | ||
| isChatSyncMessagesProps, | ||
| isChatGetMessageProps, | ||
| isChatPostMessageProps, | ||
| isChatSearchProps, | ||
| isChatSendMessageProps, | ||
| isChatIgnoreUserProps, | ||
|
|
@@ -119,6 +118,132 @@ const ChatUnfollowMessageLocalSchema = { | |
| additionalProperties: false, | ||
| }; | ||
|
|
||
| //chat.postMessage starts | ||
| type ChatPostMessage = | ||
| | { | ||
| roomId: string | string[]; | ||
| text?: string; | ||
| alias?: string; | ||
| emoji?: string; | ||
| avatar?: string; | ||
| attachments?: MessageAttachment[]; | ||
| customFields?: IMessage['customFields']; | ||
| } | ||
| | { | ||
| channel: string | string[]; | ||
| text?: string; | ||
| alias?: string; | ||
| emoji?: string; | ||
| avatar?: string; | ||
| attachments?: MessageAttachment[]; | ||
| customFields?: IMessage['customFields']; | ||
| }; | ||
|
|
||
| const ChatPostMessageSchema = { | ||
| oneOf: [ | ||
| { | ||
| type: 'object', | ||
| properties: { | ||
| roomId: { | ||
| oneOf: [ | ||
| { type: 'string' }, | ||
| { | ||
| type: 'array', | ||
| items: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| text: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| alias: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| emoji: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| avatar: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| attachments: { | ||
| type: 'array', | ||
| items: { | ||
| type: 'object', | ||
| }, | ||
| nullable: true, | ||
| }, | ||
| tmid: { | ||
| type: 'string', | ||
| }, | ||
| customFields: { | ||
| type: 'object', | ||
| nullable: true, | ||
| }, | ||
| parseUrls: { | ||
| type: 'boolean', | ||
| }, | ||
| }, | ||
| required: ['roomId'], | ||
| additionalProperties: false, | ||
| }, | ||
| { | ||
| type: 'object', | ||
| properties: { | ||
| channel: { | ||
| oneOf: [ | ||
| { type: 'string' }, | ||
| { | ||
| type: 'array', | ||
| items: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| text: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| alias: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| emoji: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| avatar: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| attachments: { | ||
| type: 'array', | ||
| items: { | ||
| type: 'object', | ||
| }, | ||
| nullable: true, | ||
| }, | ||
| customFields: { | ||
| type: 'object', | ||
| nullable: true, | ||
| }, | ||
| parseUrls: { | ||
| type: 'boolean', | ||
| }, | ||
| }, | ||
| required: ['channel'], | ||
| additionalProperties: false, | ||
|
Comment on lines
+122
to
+241
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 181 allows Proposed fix type ChatPostMessage =
| {
roomId: string | string[];
text?: string;
alias?: string;
emoji?: string;
avatar?: string;
attachments?: MessageAttachment[];
+ tmid?: string;
customFields?: IMessage['customFields'];
+ parseUrls?: boolean;
}
| {
channel: string | string[];
text?: string;
alias?: string;
emoji?: string;
avatar?: string;
attachments?: MessageAttachment[];
+ tmid?: string;
customFields?: IMessage['customFields'];
+ parseUrls?: boolean;
};
@@
{
type: 'object',
properties: {
channel: {
@@
attachments: {
type: 'array',
items: {
type: 'object',
},
nullable: true,
},
+ tmid: {
+ type: 'string',
+ },
customFields: {
type: 'object',
nullable: true,
},Also applies to: 255-255, 689-740 🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want tmid and parseURls in schema or not?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainLet me check the original schema and what 🏁 Script executed: Length of output: 1401
And the original Since both schema objects have Recommended fix:
attachments: {
type: 'array',
items: { type: 'object' },
nullable: true,
},
+ tmid: {
+ type: 'string',
+ },
customFields: {
type: 'object',
nullable: true,
},
type ChatPostMessage =
| {
roomId: string | string[];
text?: string;
alias?: string;
emoji?: string;
avatar?: string;
attachments?: MessageAttachment[];
+ tmid?: string;
customFields?: IMessage['customFields'];
+ parseUrls?: boolean;
}
| {
channel: string | string[];
text?: string;
alias?: string;
emoji?: string;
avatar?: string;
attachments?: MessageAttachment[];
+ tmid?: string;
customFields?: IMessage['customFields'];
+ parseUrls?: boolean;
};🧠 Learnings used |
||
| }, | ||
| ], | ||
| }; | ||
| //chat.postMessage ends | ||
|
|
||
| const isChatStarMessageLocalProps = ajv.compile<ChatStarMessageLocal>(ChatStarMessageLocalSchema); | ||
|
|
||
| const isChatUnstarMessageLocalProps = ajv.compile<ChatUnstarMessageLocal>(ChatUnstarMessageLocalSchema); | ||
|
|
@@ -127,6 +252,8 @@ const isChatFollowMessageLocalProps = ajv.compile<ChatFollowMessageLocal>(ChatFo | |
|
|
||
| const isChatUnfollowMessageLocalProps = ajv.compile<ChatUnfollowMessageLocal>(ChatUnfollowMessageLocalSchema); | ||
|
|
||
| const isChatPostMessageLocalProps = ajv.compile<ChatPostMessage>(ChatPostMessageSchema); | ||
|
|
||
| API.v1.addRoute( | ||
| 'chat.delete', | ||
| { authRequired: true, validateParams: isChatDeleteProps }, | ||
|
|
@@ -558,13 +685,29 @@ const chatEndpoints = API.v1 | |
|
|
||
| return API.v1.success(); | ||
| }, | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| 'chat.postMessage', | ||
| { authRequired: true, validateParams: isChatPostMessageProps }, | ||
| { | ||
| async post() { | ||
| ) | ||
| .post( | ||
| 'chat.postMessage', | ||
| { | ||
| authRequired: true, | ||
| body: isChatPostMessageLocalProps, | ||
| response: { | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| 200: ajv.compile({ | ||
| type: 'object', | ||
| properties: { | ||
| ts: { type: 'number' }, | ||
| channel: { type: 'string' }, | ||
| message: { $ref: '#/components/schemas/IMessage' }, | ||
| success: { type: 'boolean', enum: [true] }, | ||
| }, | ||
| required: ['ts', 'channel', 'message', 'success'], | ||
| additionalProperties: false, | ||
| }), | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { text, attachments } = this.bodyParams; | ||
| const maxAllowedSize = settings.get<number>('Message_MaxAllowedSize') ?? 0; | ||
|
|
||
|
|
@@ -594,8 +737,7 @@ API.v1.addRoute( | |
| message, | ||
| }); | ||
| }, | ||
| }, | ||
| ); | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| 'chat.search', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1:
chat.postMessageschema rejectstmidwhen usingchannel, breaking thread replies for channel-based requests.Prompt for AI agents