diff --git a/.changeset/quick-maps-search.md b/.changeset/quick-maps-search.md new file mode 100644 index 000000000..0375581c3 --- /dev/null +++ b/.changeset/quick-maps-search.md @@ -0,0 +1,5 @@ +--- +"@slack/web-api": patch +--- + +Add support for assistant.search.context and assistant.search.info Web API methods. diff --git a/packages/web-api/src/methods.ts b/packages/web-api/src/methods.ts index d6e584d9e..90eb2f8f7 100644 --- a/packages/web-api/src/methods.ts +++ b/packages/web-api/src/methods.ts @@ -107,6 +107,8 @@ import type { AppsManifestValidateArguments, AppsUninstallArguments, AppsUserConnectionUpdateArguments, + AssistantSearchContextArguments, + AssistantSearchInfoArguments, AssistantThreadsSetStatusArguments, AssistantThreadsSetSuggestedPromptsArguments, AssistantThreadsSetTitleArguments, @@ -381,6 +383,8 @@ import type { AppsManifestValidateResponse, AppsUninstallResponse, AppsUserConnectionUpdateResponse, + AssistantSearchContextResponse, + AssistantSearchInfoResponse, AssistantThreadsSetStatusResponse, AssistantThreadsSetSuggestedPromptsResponse, AssistantThreadsSetTitleResponse, @@ -1383,6 +1387,24 @@ export abstract class Methods extends EventEmitter { }; 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( + 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( + this, + 'assistant.search.info', + ), + }, threads: { /** * @description Set loading status to indicate that the app is building a response. diff --git a/packages/web-api/src/types/request/assistant.ts b/packages/web-api/src/types/request/assistant.ts index d3e8ef289..ae275b071 100644 --- a/packages/web-api/src/types/request/assistant.ts +++ b/packages/web-api/src/types/request/assistant.ts @@ -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; // https://docs.slack.dev/reference/methods/assistant.threads.setStatus export interface AssistantThreadsSetStatusArguments extends TokenOverridable { diff --git a/packages/web-api/src/types/request/index.ts b/packages/web-api/src/types/request/index.ts index fb387f1d4..b4b07beb1 100644 --- a/packages/web-api/src/types/request/index.ts +++ b/packages/web-api/src/types/request/index.ts @@ -130,6 +130,8 @@ export type { AppsUserConnectionUpdateArguments, } from './apps'; export type { + AssistantSearchContextArguments, + AssistantSearchInfoArguments, AssistantThreadsSetStatusArguments, AssistantThreadsSetSuggestedPromptsArguments, AssistantThreadsSetTitleArguments, diff --git a/packages/web-api/src/types/response/AssistantSearchContextResponse.ts b/packages/web-api/src/types/response/AssistantSearchContextResponse.ts new file mode 100644 index 000000000..489bec5e6 --- /dev/null +++ b/packages/web-api/src/types/response/AssistantSearchContextResponse.ts @@ -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; +} diff --git a/packages/web-api/src/types/response/AssistantSearchInfoResponse.ts b/packages/web-api/src/types/response/AssistantSearchInfoResponse.ts new file mode 100644 index 000000000..30dde0a7b --- /dev/null +++ b/packages/web-api/src/types/response/AssistantSearchInfoResponse.ts @@ -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; +}; diff --git a/packages/web-api/src/types/response/index.ts b/packages/web-api/src/types/response/index.ts index e1c324253..920ae69ea 100644 --- a/packages/web-api/src/types/response/index.ts +++ b/packages/web-api/src/types/response/index.ts @@ -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'; diff --git a/packages/web-api/test/types/methods/assistant.test-d.ts b/packages/web-api/test/types/methods/assistant.test-d.ts index a55ee4687..f1022f944 100644 --- a/packages/web-api/test/types/methods/assistant.test-d.ts +++ b/packages/web-api/test/types/methods/assistant.test-d.ts @@ -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>([ + { + query: 'What is project gizmo?', + }, +]); +expectAssignable>([ + { + 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>([]); +expectAssignable>([{}]); +expectAssignable>([ + { + token: 'TOKEN', + }, +]); + // assistant.threads.setStatus // -- sad path expectError(web.assistant.threads.setStatus()); // lacking argument