diff --git a/packages/web-api/src/WebClient.spec.ts b/packages/web-api/src/WebClient.spec.ts index eeb46e9a1..80770dd24 100644 --- a/packages/web-api/src/WebClient.spec.ts +++ b/packages/web-api/src/WebClient.spec.ts @@ -219,6 +219,21 @@ describe('WebClient', () => { }); } + const markdownTextPatterns = textWarningTestPatterns.reduce((acc, { method, args }) => { + const textPatterns = [{ markdown_text: '# example' }].map((v) => ({ + method, + args: Object.assign({}, v, args), + })); + return acc.concat(textPatterns); + }, [] as MethodArgs[]); + for (const { method, args } of markdownTextPatterns) { + it(`should not send warning to logs when client executes ${method} with markdown_text argument`, async () => { + const warnClient = new WebClient(token, { logLevel: LogLevel.WARN, logger }); + await warnClient.apiCall(method, args); + assert.isTrue((logger.warn as sinon.SinonStub).calledThrice); + }); + } + const textPatterns = textWarningTestPatterns.reduce((acc, { method, args }) => { const textPatterns = [{ text: '' }, { text: null }, {}].map((v) => ({ method, diff --git a/packages/web-api/src/WebClient.ts b/packages/web-api/src/WebClient.ts index 36eecc0ac..bbccfaee0 100644 --- a/packages/web-api/src/WebClient.ts +++ b/packages/web-api/src/WebClient.ts @@ -995,7 +995,8 @@ function warnIfFallbackIsMissing(method: string, logger: Logger, options?: Recor args.attachments.some((attachment) => !attachment.fallback || attachment.fallback.trim() === ''); const isEmptyText = (args: Record) => - args.text === undefined || args.text === null || args.text === ''; + (args.text === undefined || args.text === null || args.text === '') && + (args.markdown_text === undefined || args.markdown === null || args.markdown_text === ''); const buildMissingTextWarning = () => `The top-level \`text\` argument is missing in the request payload for a ${method} call - It's a best practice to always provide a \`text\` argument when posting a message. The \`text\` is used in places where the content cannot be rendered such as: system push notifications, assistive technology such as screen readers, etc.`; diff --git a/packages/web-api/src/types/request/chat.ts b/packages/web-api/src/types/request/chat.ts index e611d1211..61d91c4ef 100644 --- a/packages/web-api/src/types/request/chat.ts +++ b/packages/web-api/src/types/request/chat.ts @@ -68,11 +68,19 @@ export interface ChannelAndAttachments extends Channel, Partial { */ attachments: MessageAttachment[]; } +export interface ChannelAndMarkdownText extends Channel { + /** + * @description Accepts message text formatted in markdown. This argument should not be used in conjunction with `blocks` or `text`. Limit this field to 12,000 characters. + * @example **This is bold text** + */ + markdown_text: string; +} // Models message-creation arguments, user must provide one of the following combinations: // 1. channel and text // 2. channel and blocks // 3. channel and attachments -type MessageContents = ChannelAndText | ChannelAndBlocks | ChannelAndAttachments; +// 4. channel and markdown_text +type MessageContents = ChannelAndText | ChannelAndBlocks | ChannelAndAttachments | ChannelAndMarkdownText; export interface ThreadTS { /** * @description Provide another message's `ts` value to post this message in a thread. Avoid using a reply's `ts` diff --git a/packages/web-api/test/types/methods/chat.test-d.ts b/packages/web-api/test/types/methods/chat.test-d.ts index cf5349a30..2d861b046 100644 --- a/packages/web-api/test/types/methods/chat.test-d.ts +++ b/packages/web-api/test/types/methods/chat.test-d.ts @@ -98,12 +98,12 @@ expectError(web.chat.postEphemeral()); // lacking argument expectError(web.chat.postEphemeral({})); // empty argument expectError( web.chat.postEphemeral({ - channel: 'C1234', // missing text/attachments/blocks and user + channel: 'C1234', // missing text/attachments/blocks/markdown_text and user }), ); expectError( web.chat.postEphemeral({ - channel: 'C1234', // missing text/attachments/blocks + channel: 'C1234', // missing text/attachments/blocks/markdown_text user: 'U1234', }), ); @@ -250,6 +250,13 @@ expectAssignable>([ as_user: false, // ... or with as_user=false }, ]); +expectAssignable>([ + { + channel: 'C1234', + user: 'U1234', + markdown_text: '**bold**', + }, +]); // chat.postMessage // -- sad path @@ -257,7 +264,7 @@ expectError(web.chat.postMessage()); // lacking argument expectError(web.chat.postMessage({})); // empty argument expectError( web.chat.postMessage({ - channel: 'C1234', // missing text/attachments/blocks + channel: 'C1234', // missing text/attachments/blocks/markdown_text }), ); expectError( @@ -376,6 +383,12 @@ expectAssignable>([ as_user: false, // ... or with as_user=false }, ]); +expectAssignable>([ + { + channel: 'C1234', + markdown_text: '**bold**', + }, +]); expectAssignable>([ { channel: 'C1234', @@ -425,7 +438,7 @@ expectError( ); expectError( web.chat.scheduleMessage({ - channel: 'C1234', // missing text/attachments/blocks + channel: 'C1234', // missing text/attachments/blocks/markdown_text post_at: 'U1234', }), ); @@ -511,6 +524,13 @@ expectAssignable>([ text: 'fallback', }, ]); +expectAssignable>([ + { + channel: 'C1234', + markdown_text: '**bold**', + post_at: 299876400, + }, +]); expectAssignable>([ { channel: 'C1234', @@ -612,7 +632,7 @@ expectError( ); expectError( web.chat.update({ - channel: 'C1234', // missing text/attachments/blocks + channel: 'C1234', // missing text/attachments/blocks/markdown_text ts: '1234.56', }), ); @@ -705,6 +725,13 @@ expectAssignable>([ text: 'fallback', }, ]); +expectAssignable>([ + { + channel: 'C1234', + ts: '1234.56', + markdown_text: '**bold**', + }, +]); expectAssignable>([ { channel: 'C1234',