Skip to content

Commit a3261a5

Browse files
committed
Add assistant search Web API methods
1 parent f430ae8 commit a3261a5

8 files changed

Lines changed: 249 additions & 1 deletion

File tree

.changeset/quick-maps-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@slack/web-api": patch
3+
---
4+
5+
Add support for assistant.search.context and assistant.search.info Web API methods.

packages/web-api/src/methods.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ import type {
107107
AppsManifestValidateArguments,
108108
AppsUninstallArguments,
109109
AppsUserConnectionUpdateArguments,
110+
AssistantSearchContextArguments,
111+
AssistantSearchInfoArguments,
110112
AssistantThreadsSetStatusArguments,
111113
AssistantThreadsSetSuggestedPromptsArguments,
112114
AssistantThreadsSetTitleArguments,
@@ -381,6 +383,8 @@ import type {
381383
AppsManifestValidateResponse,
382384
AppsUninstallResponse,
383385
AppsUserConnectionUpdateResponse,
386+
AssistantSearchContextResponse,
387+
AssistantSearchInfoResponse,
384388
AssistantThreadsSetStatusResponse,
385389
AssistantThreadsSetSuggestedPromptsResponse,
386390
AssistantThreadsSetTitleResponse,
@@ -1383,6 +1387,24 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
13831387
};
13841388

13851389
public readonly assistant = {
1390+
search: {
1391+
/**
1392+
* @description Searches messages, files, channels and users across your Slack organization.
1393+
* @see {@link https://docs.slack.dev/reference/methods/assistant.search.context `assistant.search.context` API reference}.
1394+
*/
1395+
context: bindApiCall<AssistantSearchContextArguments, AssistantSearchContextResponse>(
1396+
this,
1397+
'assistant.search.context',
1398+
),
1399+
/**
1400+
* @description Returns search capabilities on a given team.
1401+
* @see {@link https://docs.slack.dev/reference/methods/assistant.search.info `assistant.search.info` API reference}.
1402+
*/
1403+
info: bindApiCallWithOptionalArgument<AssistantSearchInfoArguments, AssistantSearchInfoResponse>(
1404+
this,
1405+
'assistant.search.info',
1406+
),
1407+
},
13861408
threads: {
13871409
/**
13881410
* @description Set loading status to indicate that the app is building a response.

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
1-
import type { TokenOverridable } from './common';
1+
import type { OptionalArgument } from '../helpers';
2+
import type { CursorPaginationEnabled, SortDir, TokenOverridable } from './common';
3+
4+
type AssistantSearchChannelType = 'public_channel' | 'private_channel' | 'mpim' | 'im';
5+
type AssistantSearchContentType = 'messages' | 'files' | 'channels' | 'users';
6+
type AssistantSearchSort = 'score' | 'timestamp';
7+
8+
// https://docs.slack.dev/reference/methods/assistant.search.context
9+
export interface AssistantSearchContextArguments extends TokenOverridable, CursorPaginationEnabled, SortDir {
10+
/** @description User prompt or search query. */
11+
query: string;
12+
/** @description Send `action_token` as received in a message event. */
13+
action_token?: string;
14+
/** @description UNIX timestamp filter. If present, filters for results after this date. */
15+
after?: number;
16+
/** @description UNIX timestamp filter. If present, filters for results before this date. */
17+
before?: number;
18+
/** @description Mix and match channel types to search. */
19+
channel_types?: AssistantSearchChannelType[];
20+
/** @description Content types to include in search results. */
21+
content_types?: AssistantSearchContentType[];
22+
/** @description Context channel ID to support scoping the search when applicable. */
23+
context_channel_id?: string;
24+
/** @description Whether to disable semantic search. When true, only keyword-based search is used. */
25+
disable_semantic_search?: boolean;
26+
/** @description Whether to highlight the search query in the results. */
27+
highlight?: boolean;
28+
/** @description Whether the results should include archived channels. */
29+
include_archived_channels?: boolean;
30+
/** @description Whether the results should include bots. */
31+
include_bots?: boolean;
32+
/** @description Whether to include context messages surrounding the main message result. */
33+
include_context_messages?: boolean;
34+
/** @description Whether to include deleted users in user search results. */
35+
include_deleted_users?: boolean;
36+
/** @description Whether to return message blocks in the response. */
37+
include_message_blocks?: boolean;
38+
/** @description A list of keyword clauses used to match search results. */
39+
keywords_clauses?: string[][];
40+
/** @description A string containing only modifiers in the format of `modifier:value`. */
41+
modifiers?: string;
42+
/** @description The field to sort the results by. Defaults to `score`. */
43+
sort?: AssistantSearchSort;
44+
/** @description A list of term clauses. Search results returned will match every term clause specified. */
45+
term_clauses?: string[];
46+
}
47+
48+
// https://docs.slack.dev/reference/methods/assistant.search.info
49+
export type AssistantSearchInfoArguments = OptionalArgument<TokenOverridable>;
250

351
// https://docs.slack.dev/reference/methods/assistant.threads.setStatus
452
export interface AssistantThreadsSetStatusArguments extends TokenOverridable {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ export type {
130130
AppsUserConnectionUpdateArguments,
131131
} from './apps';
132132
export type {
133+
AssistantSearchContextArguments,
134+
AssistantSearchInfoArguments,
133135
AssistantThreadsSetStatusArguments,
134136
AssistantThreadsSetSuggestedPromptsArguments,
135137
AssistantThreadsSetTitleArguments,
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import type { Block, KnownBlock } from '@slack/types';
2+
import type { WebAPICallResult } from '../../WebClient';
3+
4+
export type AssistantSearchContextResponse = WebAPICallResult & {
5+
error?: string;
6+
needed?: string;
7+
ok?: boolean;
8+
provided?: string;
9+
response_metadata?: AssistantSearchContextResponseMetadata;
10+
results?: AssistantSearchContextResults;
11+
warning?: string;
12+
};
13+
14+
export interface AssistantSearchContextResponseMetadata {
15+
next_cursor?: string;
16+
}
17+
18+
export interface AssistantSearchContextResults {
19+
channels?: AssistantSearchContextChannelResult[];
20+
files?: AssistantSearchContextFileResult[];
21+
messages?: AssistantSearchContextMessageResult[];
22+
users?: AssistantSearchContextUserResult[];
23+
}
24+
25+
export interface AssistantSearchContextMessageResult {
26+
author_name?: string;
27+
author_user_id?: string;
28+
blocks?: (Block | KnownBlock)[];
29+
channel_id?: string;
30+
channel_name?: string;
31+
content?: string;
32+
context_messages?: AssistantSearchContextMessages;
33+
is_author_bot?: boolean;
34+
message_ts?: string;
35+
permalink?: string;
36+
team_id?: string;
37+
}
38+
39+
export interface AssistantSearchContextMessages {
40+
after?: AssistantSearchContextMessage[];
41+
before?: AssistantSearchContextMessage[];
42+
}
43+
44+
export interface AssistantSearchContextMessage {
45+
blocks?: (Block | KnownBlock)[];
46+
text?: string;
47+
ts?: string;
48+
user_id?: string;
49+
}
50+
51+
export interface AssistantSearchContextFileResult {
52+
author_name?: string;
53+
author_user_id?: string;
54+
content?: string;
55+
date_created?: number;
56+
date_updated?: number;
57+
file_id?: string;
58+
file_type?: string;
59+
permalink?: string;
60+
team_id?: string;
61+
title?: string;
62+
uploader_user_id?: string;
63+
}
64+
65+
export interface AssistantSearchContextChannelResult {
66+
creator_name?: string;
67+
creator_user_id?: string;
68+
date_created?: number;
69+
date_updated?: number;
70+
name?: string;
71+
permalink?: string;
72+
purpose?: string;
73+
team_id?: string;
74+
topic?: string;
75+
}
76+
77+
export interface AssistantSearchContextUserResult {
78+
content?: string;
79+
name?: string;
80+
permalink?: string;
81+
real_name?: string;
82+
team_id?: string;
83+
user_id?: string;
84+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { WebAPICallResult } from '../../WebClient';
2+
3+
export type AssistantSearchInfoResponse = WebAPICallResult & {
4+
error?: string;
5+
is_ai_search_enabled?: boolean;
6+
needed?: string;
7+
ok?: boolean;
8+
provided?: string;
9+
warning?: string;
10+
};

packages/web-api/src/types/response/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export { AppsPermissionsUsersListResponse } from './AppsPermissionsUsersListResp
117117
export { AppsPermissionsUsersRequestResponse } from './AppsPermissionsUsersRequestResponse';
118118
export { AppsUninstallResponse } from './AppsUninstallResponse';
119119
export { AppsUserConnectionUpdateResponse } from './AppsUserConnectionUpdateResponse';
120+
export { AssistantSearchContextResponse } from './AssistantSearchContextResponse';
121+
export { AssistantSearchInfoResponse } from './AssistantSearchInfoResponse';
120122
export { AssistantThreadsSetStatusResponse } from './AssistantThreadsSetStatusResponse';
121123
export { AssistantThreadsSetSuggestedPromptsResponse } from './AssistantThreadsSetSuggestedPromptsResponse';
122124
export { AssistantThreadsSetTitleResponse } from './AssistantThreadsSetTitleResponse';

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,81 @@ import { WebClient } from '../../../src/WebClient';
33

44
const web = new WebClient('TOKEN');
55

6+
// assistant.search.context
7+
// -- sad path
8+
expectError(web.assistant.search.context()); // lacking argument
9+
expectError(web.assistant.search.context({})); // empty argument
10+
expectError(
11+
web.assistant.search.context({
12+
query: 123, // not a string
13+
}),
14+
web.assistant.search.context({
15+
query: 'What is project gizmo?',
16+
channel_types: ['public_channel', 'channel'], // unsupported channel type
17+
}),
18+
web.assistant.search.context({
19+
query: 'What is project gizmo?',
20+
content_types: ['messages', 'posts'], // unsupported content type
21+
}),
22+
web.assistant.search.context({
23+
query: 'What is project gizmo?',
24+
include_bots: 'false', // not a boolean
25+
}),
26+
web.assistant.search.context({
27+
query: 'What is project gizmo?',
28+
keywords_clauses: ['project'], // not an array of string arrays
29+
}),
30+
web.assistant.search.context({
31+
query: 'What is project gizmo?',
32+
sort: 'date', // unsupported sort field
33+
}),
34+
web.assistant.search.context({
35+
query: 'What is project gizmo?',
36+
sort_dir: 'down', // unsupported sort direction
37+
}),
38+
);
39+
// -- happy path
40+
expectAssignable<Parameters<typeof web.assistant.search.context>>([
41+
{
42+
query: 'What is project gizmo?',
43+
},
44+
]);
45+
expectAssignable<Parameters<typeof web.assistant.search.context>>([
46+
{
47+
query: 'What is the latest on project Gizmo?',
48+
action_token: '12345.98765.abcd2358fdea',
49+
after: 1752512713,
50+
before: 1755191113,
51+
channel_types: ['public_channel', 'private_channel', 'mpim', 'im'],
52+
content_types: ['messages', 'files', 'channels', 'users'],
53+
context_channel_id: 'C1234',
54+
cursor: 'asf91j9jfd',
55+
disable_semantic_search: false,
56+
highlight: true,
57+
include_archived_channels: true,
58+
include_bots: false,
59+
include_context_messages: true,
60+
include_deleted_users: false,
61+
include_message_blocks: true,
62+
keywords_clauses: [['project', 'gizmo']],
63+
limit: 20,
64+
modifiers: 'has:pin before:yesterday',
65+
sort: 'timestamp',
66+
sort_dir: 'asc',
67+
term_clauses: ['project gizmo'],
68+
},
69+
]);
70+
71+
// assistant.search.info
72+
// -- happy path
73+
expectAssignable<Parameters<typeof web.assistant.search.info>>([]);
74+
expectAssignable<Parameters<typeof web.assistant.search.info>>([{}]);
75+
expectAssignable<Parameters<typeof web.assistant.search.info>>([
76+
{
77+
token: 'TOKEN',
78+
},
79+
]);
80+
681
// assistant.threads.setStatus
782
// -- sad path
883
expectError(web.assistant.threads.setStatus()); // lacking argument

0 commit comments

Comments
 (0)