Skip to content
Draft
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/quick-maps-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/web-api": patch
---

Add support for assistant.search.context and assistant.search.info Web API methods.
22 changes: 22 additions & 0 deletions packages/web-api/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ import type {
AppsManifestValidateArguments,
AppsUninstallArguments,
AppsUserConnectionUpdateArguments,
AssistantSearchContextArguments,
AssistantSearchInfoArguments,
AssistantThreadsSetStatusArguments,
AssistantThreadsSetSuggestedPromptsArguments,
AssistantThreadsSetTitleArguments,
Expand Down Expand Up @@ -381,6 +383,8 @@ import type {
AppsManifestValidateResponse,
AppsUninstallResponse,
AppsUserConnectionUpdateResponse,
AssistantSearchContextResponse,
AssistantSearchInfoResponse,
AssistantThreadsSetStatusResponse,
AssistantThreadsSetSuggestedPromptsResponse,
AssistantThreadsSetTitleResponse,
Expand Down Expand Up @@ -1383,6 +1387,24 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
};

public readonly assistant = {
search: {
/**
* @description Searches messages, files, channels and users across your Slack organization.
* @see {@link https://docs.slack.dev/reference/methods/assistant.search.context `assistant.search.context` API reference}.
*/
context: bindApiCall<AssistantSearchContextArguments, AssistantSearchContextResponse>(
this,
'assistant.search.context',
),
/**
* @description Returns search capabilities on a given team.
* @see {@link https://docs.slack.dev/reference/methods/assistant.search.info `assistant.search.info` API reference}.
*/
info: bindApiCallWithOptionalArgument<AssistantSearchInfoArguments, AssistantSearchInfoResponse>(
this,
'assistant.search.info',
),
},
threads: {
/**
* @description Set loading status to indicate that the app is building a response.
Expand Down
50 changes: 49 additions & 1 deletion packages/web-api/src/types/request/assistant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
import type { TokenOverridable } from './common';
import type { OptionalArgument } from '../helpers';
import type { CursorPaginationEnabled, SortDir, TokenOverridable } from './common';

type AssistantSearchChannelType = 'public_channel' | 'private_channel' | 'mpim' | 'im';
type AssistantSearchContentType = 'messages' | 'files' | 'channels' | 'users';
type AssistantSearchSort = 'score' | 'timestamp';

// https://docs.slack.dev/reference/methods/assistant.search.context
export interface AssistantSearchContextArguments extends TokenOverridable, CursorPaginationEnabled, SortDir {
/** @description User prompt or search query. */
query: string;
/** @description Send `action_token` as received in a message event. */
action_token?: string;
/** @description UNIX timestamp filter. If present, filters for results after this date. */
after?: number;
/** @description UNIX timestamp filter. If present, filters for results before this date. */
before?: number;
/** @description Mix and match channel types to search. */
channel_types?: AssistantSearchChannelType[];
/** @description Content types to include in search results. */
content_types?: AssistantSearchContentType[];
/** @description Context channel ID to support scoping the search when applicable. */
context_channel_id?: string;
/** @description Whether to disable semantic search. When true, only keyword-based search is used. */
disable_semantic_search?: boolean;
/** @description Whether to highlight the search query in the results. */
highlight?: boolean;
/** @description Whether the results should include archived channels. */
include_archived_channels?: boolean;
/** @description Whether the results should include bots. */
include_bots?: boolean;
/** @description Whether to include context messages surrounding the main message result. */
include_context_messages?: boolean;
/** @description Whether to include deleted users in user search results. */
include_deleted_users?: boolean;
/** @description Whether to return message blocks in the response. */
include_message_blocks?: boolean;
/** @description A list of keyword clauses used to match search results. */
keywords_clauses?: string[][];
/** @description A string containing only modifiers in the format of `modifier:value`. */
modifiers?: string;
/** @description The field to sort the results by. Defaults to `score`. */
sort?: AssistantSearchSort;
/** @description A list of term clauses. Search results returned will match every term clause specified. */
term_clauses?: string[];
}

// https://docs.slack.dev/reference/methods/assistant.search.info
export type AssistantSearchInfoArguments = OptionalArgument<TokenOverridable>;

// https://docs.slack.dev/reference/methods/assistant.threads.setStatus
export interface AssistantThreadsSetStatusArguments extends TokenOverridable {
Expand Down
2 changes: 2 additions & 0 deletions packages/web-api/src/types/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export type {
AppsUserConnectionUpdateArguments,
} from './apps';
export type {
AssistantSearchContextArguments,
AssistantSearchInfoArguments,
AssistantThreadsSetStatusArguments,
AssistantThreadsSetSuggestedPromptsArguments,
AssistantThreadsSetTitleArguments,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import type { WebAPICallResult } from '../../WebClient';
export type AssistantSearchContextResponse = WebAPICallResult & {
error?: string;
needed?: string;
ok?: boolean;
provided?: string;
response_metadata?: ResponseMetadata;
results?: Results;
warning?: string;
};

export interface ResponseMetadata {
messages?: string[];
next_cursor?: string;
warnings?: string[];
}

export interface Results {
channels?: Channel[];
files?: File[];
messages?: Message[];
users?: User[];
}

export interface Channel {
creator_name?: string;
creator_user_id?: string;
date_created?: number;
date_updated?: number;
name?: string;
permalink?: string;
purpose?: string;
team_id?: string;
topic?: string;
}

export interface File {
author_name?: string;
author_user_id?: string;
content?: string;
date_created?: number;
date_updated?: number;
file_id?: string;
file_type?: string;
permalink?: string;
team_id?: string;
title?: string;
uploader_user_id?: string;
}

export interface Message {
author_name?: string;
author_user_id?: string;
blocks?: any[];
channel_id?: string;
channel_name?: string;
content?: string;
context_messages?: ContextMessages;
is_author_bot?: boolean;
message_ts?: string;
permalink?: string;
team_id?: string;
}

export interface ContextMessages {
after?: After[];
before?: After[];
}

export interface After {
blocks?: any[];
text?: string;
ts?: string;
user_id?: string;
}

export interface User {
content?: string;
name?: string;
permalink?: string;
real_name?: string;
team_id?: string;
user_id?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import type { WebAPICallResult } from '../../WebClient';
export type AssistantSearchInfoResponse = WebAPICallResult & {
error?: string;
is_ai_search_enabled?: boolean;
needed?: string;
ok?: boolean;
provided?: string;
warning?: string;
};
2 changes: 2 additions & 0 deletions packages/web-api/src/types/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export { AppsPermissionsUsersListResponse } from './AppsPermissionsUsersListResp
export { AppsPermissionsUsersRequestResponse } from './AppsPermissionsUsersRequestResponse';
export { AppsUninstallResponse } from './AppsUninstallResponse';
export { AppsUserConnectionUpdateResponse } from './AppsUserConnectionUpdateResponse';
export { AssistantSearchContextResponse } from './AssistantSearchContextResponse';
export { AssistantSearchInfoResponse } from './AssistantSearchInfoResponse';
export { AssistantThreadsSetStatusResponse } from './AssistantThreadsSetStatusResponse';
export { AssistantThreadsSetSuggestedPromptsResponse } from './AssistantThreadsSetSuggestedPromptsResponse';
export { AssistantThreadsSetTitleResponse } from './AssistantThreadsSetTitleResponse';
Expand Down
75 changes: 75 additions & 0 deletions packages/web-api/test/types/methods/assistant.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,81 @@ import { WebClient } from '../../../src/WebClient';

const web = new WebClient('TOKEN');

// assistant.search.context
// -- sad path
expectError(web.assistant.search.context()); // lacking argument
expectError(web.assistant.search.context({})); // empty argument
expectError(
web.assistant.search.context({
query: 123, // not a string
}),
web.assistant.search.context({
query: 'What is project gizmo?',
channel_types: ['public_channel', 'channel'], // unsupported channel type
}),
web.assistant.search.context({
query: 'What is project gizmo?',
content_types: ['messages', 'posts'], // unsupported content type
}),
web.assistant.search.context({
query: 'What is project gizmo?',
include_bots: 'false', // not a boolean
}),
web.assistant.search.context({
query: 'What is project gizmo?',
keywords_clauses: ['project'], // not an array of string arrays
}),
web.assistant.search.context({
query: 'What is project gizmo?',
sort: 'date', // unsupported sort field
}),
web.assistant.search.context({
query: 'What is project gizmo?',
sort_dir: 'down', // unsupported sort direction
}),
);
// -- happy path
expectAssignable<Parameters<typeof web.assistant.search.context>>([
{
query: 'What is project gizmo?',
},
]);
expectAssignable<Parameters<typeof web.assistant.search.context>>([
{
query: 'What is the latest on project Gizmo?',
action_token: '12345.98765.abcd2358fdea',
after: 1752512713,
before: 1755191113,
channel_types: ['public_channel', 'private_channel', 'mpim', 'im'],
content_types: ['messages', 'files', 'channels', 'users'],
context_channel_id: 'C1234',
cursor: 'asf91j9jfd',
disable_semantic_search: false,
highlight: true,
include_archived_channels: true,
include_bots: false,
include_context_messages: true,
include_deleted_users: false,
include_message_blocks: true,
keywords_clauses: [['project', 'gizmo']],
limit: 20,
modifiers: 'has:pin before:yesterday',
sort: 'timestamp',
sort_dir: 'asc',
term_clauses: ['project gizmo'],
},
]);

// assistant.search.info
// -- happy path
expectAssignable<Parameters<typeof web.assistant.search.info>>([]);
expectAssignable<Parameters<typeof web.assistant.search.info>>([{}]);
expectAssignable<Parameters<typeof web.assistant.search.info>>([
{
token: 'TOKEN',
},
]);

// assistant.threads.setStatus
// -- sad path
expectError(web.assistant.threads.setStatus()); // lacking argument
Expand Down