Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/web-api/src/WebClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>) =>
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.`;
Expand Down
10 changes: 9 additions & 1 deletion packages/web-api/src/types/request/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,19 @@ export interface ChannelAndAttachments extends Channel, Partial<Text> {
*/
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗣️ note: Including markdown_text here was found to be helpful in avoiding typescript errors since none of the other "content" arguments are required!

⏳ ramble: Otherwise an attachments was expected I noticed-

export interface ThreadTS {
/**
* @description Provide another message's `ts` value to post this message in a thread. Avoid using a reply's `ts`
Expand Down
37 changes: 32 additions & 5 deletions packages/web-api/test/types/methods/chat.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
);
Expand Down Expand Up @@ -250,14 +250,21 @@ expectAssignable<Parameters<typeof web.chat.postEphemeral>>([
as_user: false, // ... or with as_user=false
},
]);
expectAssignable<Parameters<typeof web.chat.postEphemeral>>([
{
channel: 'C1234',
user: 'U1234',
markdown_text: '**bold**',
},
]);

// chat.postMessage
// -- sad path
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(
Expand Down Expand Up @@ -376,6 +383,12 @@ expectAssignable<Parameters<typeof web.chat.postMessage>>([
as_user: false, // ... or with as_user=false
},
]);
expectAssignable<Parameters<typeof web.chat.postMessage>>([
{
channel: 'C1234',
markdown_text: '**bold**',
},
]);
expectAssignable<Parameters<typeof web.chat.postMessage>>([
{
channel: 'C1234',
Expand Down Expand Up @@ -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',
}),
);
Expand Down Expand Up @@ -511,6 +524,13 @@ expectAssignable<Parameters<typeof web.chat.scheduleMessage>>([
text: 'fallback',
},
]);
expectAssignable<Parameters<typeof web.chat.scheduleMessage>>([
{
channel: 'C1234',
markdown_text: '**bold**',
post_at: 299876400,
},
]);
expectAssignable<Parameters<typeof web.chat.scheduleMessage>>([
{
channel: 'C1234',
Expand Down Expand Up @@ -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',
}),
);
Expand Down Expand Up @@ -705,6 +725,13 @@ expectAssignable<Parameters<typeof web.chat.update>>([
text: 'fallback',
},
]);
expectAssignable<Parameters<typeof web.chat.update>>([
{
channel: 'C1234',
ts: '1234.56',
markdown_text: '**bold**',
},
]);
expectAssignable<Parameters<typeof web.chat.update>>([
{
channel: 'C1234',
Expand Down
Loading