Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/slack-lists-message-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/web-api": patch
---

Correct Slack Lists item message field response typing to accept single and multiple message objects.
41 changes: 40 additions & 1 deletion packages/web-api/src/types/request/slackLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ export interface SlackListsItemFieldMessage {
message: string[];
}

/**
* @description Message field value returned for Slack Lists items.
*/
export interface SlackListsItemMessage {
text?: string;
ts?: string;
user?: string;
team?: string;
type?: string;
}

/**
* @description Message field returned for Slack Lists items.
*/
export interface SlackListsItemFieldMessageResponse {
column_id: string;
message: SlackListsItemMessage | SlackListsItemMessage[];
}

/**
* @description Number field with numeric values.
*/
Expand Down Expand Up @@ -153,6 +172,26 @@ export type SlackListsItemField =
| SlackListsItemFieldTimestamp
| SlackListsItemFieldUser;

/**
* @description Union type of all possible Slack Lists item field types returned by the API.
*/
export type SlackListsItemResponseField =
| SlackListsItemFieldAttachment
| SlackListsItemFieldChannel
| SlackListsItemFieldCheckbox
| SlackListsItemFieldDate
| SlackListsItemFieldEmail
| SlackListsItemFieldLink
| SlackListsItemFieldMessageResponse
| SlackListsItemFieldNumber
| SlackListsItemFieldPhone
| SlackListsItemFieldRating
| SlackListsItemFieldReference
| SlackListsItemFieldRichText
| SlackListsItemFieldSelect
| SlackListsItemFieldTimestamp
| SlackListsItemFieldUser;

/**
* @description Slack Lists item structure.
*/
Expand Down Expand Up @@ -180,7 +219,7 @@ export interface SlackListsItem {
/**
* @description Array of field data for this item.
*/
fields: SlackListsItemField[];
fields: SlackListsItemResponseField[];
/**
* @description String representation of the last update timestamp.
*/
Expand Down
34 changes: 33 additions & 1 deletion packages/web-api/test/types/methods/slacklists.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectAssignable, expectError } from 'tsd';

import type { SlackListsItemsListResponse } from '../../../src/types/response/SlackListsItemsListResponse';
import { WebClient } from '../../../src/WebClient';

const web = new WebClient('TOKEN');
Expand Down Expand Up @@ -77,8 +77,15 @@ expectError(web.slackLists.items.create({})); // missing list_id
expectAssignable<Parameters<typeof web.slackLists.items.create>>([
{
list_id: 'L1234567890',
initial_fields: [{ column_id: 'Col1234567890', message: ['https://example.slack.com/archives/C123/p123'] }],
},
]);
expectError(
web.slackLists.items.create({
list_id: 'L1234567890',
initial_fields: [{ column_id: 'Col1234567890', message: { text: 'message objects are only returned by the API' } }],
}),
);

// slackLists.items.delete
// -- sad path
Expand Down Expand Up @@ -159,3 +166,28 @@ expectAssignable<Parameters<typeof web.slackLists.update>>([
id: 'L1234567890',
},
]);

// slackLists.items.list response fields
expectAssignable<SlackListsItemsListResponse>({
ok: true,
items: [
{
id: 'Rec014K005UQJ',
list_id: 'L1234567890',
date_created: 1710000000,
created_by: 'U01284PCR98',
updated_by: 'U01284PCR98',
fields: [{ column_id: 'Col014K005UQJ', message: { text: 'hello', ts: '123.456', user: 'U01284PCR98' } }],
updated_timestamp: '1710000000.000000',
},
{
id: 'Rec014K005UQK',
list_id: 'L1234567890',
date_created: 1710000001,
created_by: 'U01284PCR98',
updated_by: 'U01284PCR98',
fields: [{ column_id: 'Col014K005UQJ', message: [{ text: 'first' }, { text: 'second', ts: '123.457' }] }],
updated_timestamp: '1710000001.000000',
},
],
});