Skip to content

Commit b66a2cb

Browse files
feat(web-api): add markdown_text property to chat.{postEphemeral|postMessage|scheduleMessage|update} methods (#2330)
Co-authored-by: Eden Zimbelman <[email protected]>
1 parent c2a8c84 commit b66a2cb

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

packages/web-api/src/WebClient.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,21 @@ describe('WebClient', () => {
219219
});
220220
}
221221

222+
const markdownTextPatterns = textWarningTestPatterns.reduce((acc, { method, args }) => {
223+
const textPatterns = [{ markdown_text: '# example' }].map((v) => ({
224+
method,
225+
args: Object.assign({}, v, args),
226+
}));
227+
return acc.concat(textPatterns);
228+
}, [] as MethodArgs[]);
229+
for (const { method, args } of markdownTextPatterns) {
230+
it(`should not send warning to logs when client executes ${method} with markdown_text argument`, async () => {
231+
const warnClient = new WebClient(token, { logLevel: LogLevel.WARN, logger });
232+
await warnClient.apiCall(method, args);
233+
assert.isTrue((logger.warn as sinon.SinonStub).calledThrice);
234+
});
235+
}
236+
222237
const textPatterns = textWarningTestPatterns.reduce((acc, { method, args }) => {
223238
const textPatterns = [{ text: '' }, { text: null }, {}].map((v) => ({
224239
method,

packages/web-api/src/WebClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,8 @@ function warnIfFallbackIsMissing(method: string, logger: Logger, options?: Recor
995995
args.attachments.some((attachment) => !attachment.fallback || attachment.fallback.trim() === '');
996996

997997
const isEmptyText = (args: Record<string, unknown>) =>
998-
args.text === undefined || args.text === null || args.text === '';
998+
(args.text === undefined || args.text === null || args.text === '') &&
999+
(args.markdown_text === undefined || args.markdown === null || args.markdown_text === '');
9991000

10001001
const buildMissingTextWarning = () =>
10011002
`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.`;

packages/web-api/src/types/request/chat.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,19 @@ export interface ChannelAndAttachments extends Channel, Partial<Text> {
6868
*/
6969
attachments: MessageAttachment[];
7070
}
71+
export interface ChannelAndMarkdownText extends Channel {
72+
/**
73+
* @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.
74+
* @example **This is bold text**
75+
*/
76+
markdown_text: string;
77+
}
7178
// Models message-creation arguments, user must provide one of the following combinations:
7279
// 1. channel and text
7380
// 2. channel and blocks
7481
// 3. channel and attachments
75-
type MessageContents = ChannelAndText | ChannelAndBlocks | ChannelAndAttachments;
82+
// 4. channel and markdown_text
83+
type MessageContents = ChannelAndText | ChannelAndBlocks | ChannelAndAttachments | ChannelAndMarkdownText;
7684
export interface ThreadTS {
7785
/**
7886
* @description Provide another message's `ts` value to post this message in a thread. Avoid using a reply's `ts`

packages/web-api/test/types/methods/chat.test-d.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ expectError(web.chat.postEphemeral()); // lacking argument
9898
expectError(web.chat.postEphemeral({})); // empty argument
9999
expectError(
100100
web.chat.postEphemeral({
101-
channel: 'C1234', // missing text/attachments/blocks and user
101+
channel: 'C1234', // missing text/attachments/blocks/markdown_text and user
102102
}),
103103
);
104104
expectError(
105105
web.chat.postEphemeral({
106-
channel: 'C1234', // missing text/attachments/blocks
106+
channel: 'C1234', // missing text/attachments/blocks/markdown_text
107107
user: 'U1234',
108108
}),
109109
);
@@ -250,14 +250,21 @@ expectAssignable<Parameters<typeof web.chat.postEphemeral>>([
250250
as_user: false, // ... or with as_user=false
251251
},
252252
]);
253+
expectAssignable<Parameters<typeof web.chat.postEphemeral>>([
254+
{
255+
channel: 'C1234',
256+
user: 'U1234',
257+
markdown_text: '**bold**',
258+
},
259+
]);
253260

254261
// chat.postMessage
255262
// -- sad path
256263
expectError(web.chat.postMessage()); // lacking argument
257264
expectError(web.chat.postMessage({})); // empty argument
258265
expectError(
259266
web.chat.postMessage({
260-
channel: 'C1234', // missing text/attachments/blocks
267+
channel: 'C1234', // missing text/attachments/blocks/markdown_text
261268
}),
262269
);
263270
expectError(
@@ -376,6 +383,12 @@ expectAssignable<Parameters<typeof web.chat.postMessage>>([
376383
as_user: false, // ... or with as_user=false
377384
},
378385
]);
386+
expectAssignable<Parameters<typeof web.chat.postMessage>>([
387+
{
388+
channel: 'C1234',
389+
markdown_text: '**bold**',
390+
},
391+
]);
379392
expectAssignable<Parameters<typeof web.chat.postMessage>>([
380393
{
381394
channel: 'C1234',
@@ -425,7 +438,7 @@ expectError(
425438
);
426439
expectError(
427440
web.chat.scheduleMessage({
428-
channel: 'C1234', // missing text/attachments/blocks
441+
channel: 'C1234', // missing text/attachments/blocks/markdown_text
429442
post_at: 'U1234',
430443
}),
431444
);
@@ -511,6 +524,13 @@ expectAssignable<Parameters<typeof web.chat.scheduleMessage>>([
511524
text: 'fallback',
512525
},
513526
]);
527+
expectAssignable<Parameters<typeof web.chat.scheduleMessage>>([
528+
{
529+
channel: 'C1234',
530+
markdown_text: '**bold**',
531+
post_at: 299876400,
532+
},
533+
]);
514534
expectAssignable<Parameters<typeof web.chat.scheduleMessage>>([
515535
{
516536
channel: 'C1234',
@@ -612,7 +632,7 @@ expectError(
612632
);
613633
expectError(
614634
web.chat.update({
615-
channel: 'C1234', // missing text/attachments/blocks
635+
channel: 'C1234', // missing text/attachments/blocks/markdown_text
616636
ts: '1234.56',
617637
}),
618638
);
@@ -705,6 +725,13 @@ expectAssignable<Parameters<typeof web.chat.update>>([
705725
text: 'fallback',
706726
},
707727
]);
728+
expectAssignable<Parameters<typeof web.chat.update>>([
729+
{
730+
channel: 'C1234',
731+
ts: '1234.56',
732+
markdown_text: '**bold**',
733+
},
734+
]);
708735
expectAssignable<Parameters<typeof web.chat.update>>([
709736
{
710737
channel: 'C1234',

0 commit comments

Comments
 (0)