import { type Conversation, type Message, type User } from '@botpress/client'; import type { commonTypes } from '../../common'; import { Request, Response } from '../../serve'; import { Cast, Merge, ValueOf } from '../../utils/type-utils'; import { IntegrationSpecificClient } from '../client'; import { BaseIntegration } from '../common'; import { type IntegrationLogger } from './integration-logger'; type IntegrationContextConfig = { configurationType: null; configuration: TIntegration['configuration']; } | ValueOf<{ [TConfigType in keyof TIntegration['configurations']]: { configurationType: TConfigType; configuration: TIntegration['configurations'][TConfigType]; }; }>; export type IntegrationContext = { botId: string; botUserId: string; integrationId: string; integrationAlias: string; webhookId: string; operation: string; } & IntegrationContextConfig; export type CommonHandlerProps = { ctx: IntegrationContext; client: IntegrationSpecificClient; logger: IntegrationLogger; }; export type RegisterPayload = { webhookUrl: string; }; export type RegisterHandlerProps = CommonHandlerProps & RegisterPayload; export type RegisterHandler = (props: RegisterHandlerProps) => Promise; export type UnregisterPayload = { webhookUrl: string; }; export type UnregisterHandlerProps = CommonHandlerProps & UnregisterPayload; export type UnregisterHandler = (props: UnregisterHandlerProps) => Promise; export type WebhookPayload = { req: Request; }; export type WebhookHandlerProps = CommonHandlerProps & WebhookPayload; export type WebhookHandler = (props: WebhookHandlerProps) => Promise; export type ActionMetadata = { setCost: (cost: number) => void; }; export type ActionPayload = { type: T; input: I; metadata: ActionMetadata; }; export type ActionHandlerProps = CommonHandlerProps & ActionPayload; export type ActionHandlers = { [ActionType in keyof TIntegration['actions']]: (props: ActionHandlerProps, TIntegration['actions'][ActionType]['input']>) => Promise; }; export type CreateUserPayload = { tags: commonTypes.ToTags; }; export type CreateUserHandlerProps = CommonHandlerProps & CreateUserPayload; export type CreateUserHandler = (props: CreateUserHandlerProps) => Promise; export type CreateConversationPayload = { channel: TChannel; tags: commonTypes.ToTags; }; export type CreateConversationHandlerProps = CommonHandlerProps & CreateConversationPayload; export type CreateConversationHandler = (props: CreateConversationHandlerProps) => Promise; export type MessagePayload = { type: TMessage; payload: TIntegration['channels'][TChannel]['messages'][TMessage]; conversation: Merge; }>; message: Merge; }>; user: Merge; }>; }; export type MessageHandlerProps = CommonHandlerProps & MessagePayload & { ack: (props: { tags: commonTypes.ToTags; }) => Promise; }; export type ChannelHandlers = { [ChannelName in keyof TIntegration['channels']]: { messages: { [MessageType in keyof TIntegration['channels'][ChannelName]['messages']]: (props: CommonHandlerProps & MessageHandlerProps) => Promise; }; }; }; export type UnknownOperationHandler = (props: CommonHandlerProps & { req: Request; }) => Promise; export type IntegrationHandlers = { register: RegisterHandler; unregister: UnregisterHandler; webhook: WebhookHandler; createUser?: CreateUserHandler; createConversation?: CreateConversationHandler; actions: ActionHandlers; channels: ChannelHandlers; unknownOperationHandler?: UnknownOperationHandler; }; export {};