chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:34:48 +08:00
commit 77bb5bf71f
3762 changed files with 353249 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
import { state } from '@botpress/api'
import { OpenApi } from '@bpinternal/opapi'
import { conversationSchema } from './models/conversation'
import { eventSchema } from './models/event'
import { messageSchema } from './models/message'
import { userSchema } from './models/user'
import { apiVersion } from './version'
export const { errors } = state
export const sections = {
user: { description: '', title: 'User' },
conversation: { description: '', title: 'Conversation' },
message: { description: '', title: 'Message' },
event: { description: '', title: 'Event' },
} as const
export const parameters = {} as const
export const schemas = {
User: { schema: userSchema, section: 'user' },
Conversation: { schema: conversationSchema, section: 'conversation' },
Message: { schema: messageSchema, section: 'message' },
Event: { schema: eventSchema, section: 'event' },
} as const
export type Schemas = typeof schemas
export type Parameters = typeof parameters
export type Sections = typeof sections
export type ChatApi = OpenApi<keyof Schemas, keyof Parameters, keyof Sections>
export const chatApi = (): ChatApi =>
new OpenApi(
{
metadata: {
title: 'Chat API',
description: 'API for the Chat Integration',
server: 'https://chat.botpress.cloud/',
version: apiVersion,
},
sections,
schemas,
errors,
},
{
allowUnions: true,
}
)
+20
View File
@@ -0,0 +1,20 @@
import { exportZodSchemas } from '@bpinternal/opapi'
import _ from 'lodash'
import { chatApi } from './api'
import { createOperations } from './operations'
import { signalSchemas } from './signals'
import { apiVersion } from './version'
export { messagePayloadSchema } from './models/message'
export const api = chatApi()
const _operations = createOperations(api)
for (const op of _.values(_operations)) {
api.addOperation(op)
}
export const version = apiVersion
export const signals = {
exportSchemas: exportZodSchemas(signalSchemas),
}
@@ -0,0 +1,16 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
export const conversationIdSchema = schema(z.string(), {
description: 'Identifier of the [Conversation](#schema_conversation)',
})
export const conversationSchema = z.object({
id: conversationIdSchema,
createdAt: schema(z.date(), {
description: 'Creation date of the [Conversation](#schema_conversation) in ISO 8601 format',
}),
updatedAt: schema(z.date(), {
description: 'Updating date of the [Conversation](#schema_conversation) in ISO 8601 format',
}),
})
+21
View File
@@ -0,0 +1,21 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
export const eventPayloadSchema = schema(z.record(z.any()), {
description: 'Payload is the content of the custom event.',
additionalProperties: {
nullable: undefined, // fixes a weird issue with opapi zod to json conversion conversion
},
})
export const eventSchema = schema(
z.object({
id: schema(z.string(), { description: 'ID of the custom [Event](#schema_event).' }),
createdAt: schema(z.date(), {
description: 'Creation date of the custom [Event](#schema_event) in ISO 8601 format',
}),
payload: eventPayloadSchema,
conversationId: schema(z.string(), { description: 'ID of the [Conversation](#schema_conversation).' }),
userId: schema(z.string(), { description: 'ID of the [User](#schema_user).' }),
})
)
+4
View File
@@ -0,0 +1,4 @@
export * as conversation from './conversation'
export * as message from './message'
export * as user from './user'
export * as event from './event'
+131
View File
@@ -0,0 +1,131 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
const NonEmptyString = z.string().min(1)
const textMessageSchema = z.object({
type: z.literal('text'),
text: NonEmptyString,
})
const markdownMessageSchema = z.object({
type: z.literal('markdown'),
markdown: NonEmptyString,
})
const imageMessageSchema = z.object({
type: z.literal('image'),
imageUrl: NonEmptyString,
})
const audioMessageSchema = z.object({
type: z.literal('audio'),
audioUrl: NonEmptyString,
})
const videoMessageSchema = z.object({
type: z.literal('video'),
videoUrl: NonEmptyString,
})
const fileMessageSchema = z.object({
type: z.literal('file'),
fileUrl: NonEmptyString,
title: NonEmptyString.optional(),
})
const locationMessageSchema = z.object({
type: z.literal('location'),
latitude: z.number(),
longitude: z.number(),
address: z.string().optional(),
title: z.string().optional(),
})
const cardMessageSchema = z.object({
type: z.literal('card'),
title: NonEmptyString,
subtitle: NonEmptyString.optional(),
imageUrl: NonEmptyString.optional(),
actions: z.array(
z.object({
action: z.enum(['postback', 'url', 'say']),
label: NonEmptyString,
value: NonEmptyString,
})
),
})
const _optionMessageSchema = z.object({
text: NonEmptyString,
options: z.array(
z.object({
label: NonEmptyString,
value: NonEmptyString,
})
),
})
const choiceMessageSchema = _optionMessageSchema.extend({
type: z.literal('choice'),
})
const dropdownMessageSchema = _optionMessageSchema.extend({
type: z.literal('dropdown'),
})
const carouselMessageSchema = z.object({
type: z.literal('carousel'),
items: z.array(cardMessageSchema),
})
const blocMessageSchema = z.object({
type: z.literal('bloc'),
items: z.array(
z.union([
textMessageSchema,
markdownMessageSchema,
imageMessageSchema,
audioMessageSchema,
videoMessageSchema,
fileMessageSchema,
locationMessageSchema,
])
),
})
export const messagePayloadSchema = z.union([
audioMessageSchema,
cardMessageSchema,
carouselMessageSchema,
choiceMessageSchema,
dropdownMessageSchema,
fileMessageSchema,
imageMessageSchema,
locationMessageSchema,
textMessageSchema,
videoMessageSchema,
markdownMessageSchema,
blocMessageSchema,
]) satisfies z.ZodSchema<{ type: string }> // ensures that the type field can be used to discriminate
export const messageSchema = schema(
z.object({
id: schema(z.string(), {
description: 'Identifier of the [Message](#schema_message)',
}),
createdAt: schema(z.date(), {
description: 'Creation date of the [Message](#schema_message) in ISO 8601 format',
}),
payload: schema(messagePayloadSchema, {
description: 'Payload is the content type of the message.',
}),
userId: schema(z.string(), { description: 'ID of the [User](#schema_user)' }),
conversationId: schema(z.string(), { description: 'ID of the [Conversation](#schema_conversation)' }),
metadata: schema(z.record(z.any()).optional(), { description: 'Metadata of the message' }),
}),
{
description:
'The Message object represents a message in a [Conversation](#schema_conversation) for a specific [User](#schema_user).',
}
)
+29
View File
@@ -0,0 +1,29 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
export const userIdSchema = schema(z.string(), {
description: 'Identifier of the [User](#schema_user)',
})
export const userSchema = schema(
z.object({
id: userIdSchema,
name: schema(z.string().optional(), {
description: 'Name of the [User](#schema_user)',
}),
pictureUrl: schema(z.string().optional(), { description: 'Picture url of the [User](#schema_user)' }),
profile: schema(z.string().optional(), {
description: 'Custom profile data of the [User](#schema_user) encoded as a string',
}),
createdAt: schema(z.date(), {
description: 'Creation date of the [User](#schema_user) in ISO 8601 format',
}),
updatedAt: schema(z.date(), {
description: 'Updating date of the [User](#schema_user) in ISO 8601 format',
}),
}),
{
description:
'The user object represents someone interacting with the bot within a specific integration. The same person interacting with a bot in slack and messenger will be represented with two different users.',
}
)
+10
View File
@@ -0,0 +1,10 @@
import { Parameter } from '@bpinternal/opapi'
export const authHeaders = {
'x-user-key': {
in: 'header',
type: 'string',
description: 'Authentication Key',
required: true,
},
} satisfies Record<string, Parameter>
@@ -0,0 +1,277 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
import { conversationSchema, conversationIdSchema } from '../models/conversation'
import { authHeaders } from './auth'
import { pagedResponseMeta, pagingParameters } from './paging'
import { OperationFunc } from './types'
const section = 'conversation' as const
export const getConversationOperation: OperationFunc = (api) => ({
name: 'getConversation',
description: 'Retrieves the [Conversation](#schema_conversation) object for a valid identifier.',
method: 'get',
path: '/conversations/{id}',
parameters: {
...authHeaders,
id: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
},
section,
response: {
description: 'Returns a [Conversation](#schema_conversation) object if a valid identifier was provided',
schema: schema(
z.object({
conversation: api.getModelRef('Conversation'),
})
),
},
})
export const createConversationOperation: OperationFunc = (api) => ({
name: 'createConversation',
description: 'Creates a new [Conversation](#schema_conversation)',
method: 'post',
path: '/conversations',
parameters: authHeaders,
requestBody: {
description: 'Conversation data',
schema: z.object({
id: conversationIdSchema.optional(),
}),
},
section,
response: {
status: 201,
description: 'Returns a [Conversation](#schema_conversation)',
schema: schema(
z.object({
conversation: api.getModelRef('Conversation'),
})
),
},
})
export const getOrCreateConversationOperation: OperationFunc = (api) => ({
name: 'getOrCreateConversation',
description: 'Get or create a new [Conversation](#schema_conversation)',
method: 'post',
path: '/conversations/get-or-create',
parameters: authHeaders,
requestBody: {
description: 'Conversation data',
schema: z.object({
id: conversationIdSchema,
}),
},
section,
response: {
status: 201,
description: 'Returns a [Conversation](#schema_conversation)',
schema: schema(
z.object({
conversation: api.getModelRef('Conversation'),
})
),
},
})
export const deleteConversationOperation: OperationFunc = () => ({
name: 'deleteConversation',
description:
'Permanently deletes a [Conversation](#schema_conversation). It cannot be undone. Also immediately deletes corresponding [Messages](#schema_message).',
method: 'delete',
path: '/conversations/{id}',
parameters: {
...authHeaders,
id: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
},
section,
response: {
description: 'Returns the [Conversation](#schema_conversation) object that was deleted',
schema: z.object({}),
},
})
export const listConversationsOperation: OperationFunc = () => ({
name: 'listConversations',
description: 'Returns a list of [Conversation](#schema_conversation) objects',
method: 'get',
path: '/conversations',
parameters: {
...authHeaders,
...pagingParameters,
},
section,
response: {
description: 'Returns a list of [Conversation](#schema_conversation) objects',
schema: z
.object({
conversations: z.array(conversationSchema),
})
.extend({ meta: pagedResponseMeta }),
},
})
export const listenConversationOperation: OperationFunc = () => ({
name: 'listenConversation',
description: 'Creates a SSE stream to receive messages and events from a conversation',
method: 'get',
path: '/conversations/{id}/listen',
parameters: {
...authHeaders,
id: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
},
section,
response: {
description: 'Returns nothing but a stream',
schema: schema(z.object({})),
},
})
export const listMessagesOperation: OperationFunc = (api) => ({
name: 'listMessages',
description: "Retrieves the conversation's [Messages](#schema_message)",
method: 'get',
path: '/conversations/{conversationId}/messages',
parameters: {
...authHeaders,
...pagingParameters,
conversationId: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
},
section,
response: {
description: 'Returns a list of [Message](#schema_message) objects',
schema: z
.object({
messages: z.array(api.getModelRef('Message')),
})
.extend({ meta: pagedResponseMeta }),
},
})
export const addParticipantOperation: OperationFunc = (api) => ({
name: 'addParticipant',
description: 'Add a [Participant](#schema_user) to a [Conversation](#schema_conversation).',
method: 'post',
path: '/conversations/{conversationId}/participants',
parameters: {
...authHeaders,
conversationId: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
},
requestBody: {
description: 'Participant data',
schema: schema(
z.object({
userId: schema(z.string(), { description: 'User id' }),
})
),
},
section,
response: {
description: 'Returns the [Participant](#schema_user) object',
schema: schema(
z.object({
participant: api.getModelRef('User'),
})
),
},
})
export const removeParticipantOperation: OperationFunc = () => ({
name: 'removeParticipant',
description: 'Remove a [Participant](#schema_user) from a [Conversation](#schema_conversation).',
method: 'delete',
path: '/conversations/{conversationId}/participants/{userId}',
parameters: {
...authHeaders,
conversationId: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
userId: {
in: 'path',
type: 'string',
description: 'User id',
},
},
section,
response: {
description: 'Returns an empty object',
schema: z.object({}),
},
})
export const getParticipantOperation: OperationFunc = (api) => ({
name: 'getParticipant',
description: 'Retrieves a [Participant](#schema_user) from a [Conversation](#schema_conversation).',
method: 'get',
path: '/conversations/{conversationId}/participants/{userId}',
parameters: {
...authHeaders,
conversationId: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
userId: {
in: 'path',
type: 'string',
description: 'User id',
},
},
section,
response: {
description: 'Returns the [Participant](#schema_user) object',
schema: schema(
z.object({
participant: api.getModelRef('User'),
})
),
},
})
export const listParticipantsOperation: OperationFunc = (api) => ({
name: 'listParticipants',
description: 'Retrieves a list of [Participants](#schema_user) for a given [Conversation](#schema_conversation).',
method: 'get',
path: '/conversations/{conversationId}/participants',
parameters: {
...authHeaders,
...pagingParameters,
conversationId: {
in: 'path',
type: 'string',
description: 'Conversation id',
},
},
section,
response: {
description: 'Returns a list of [Participants](#schema_user) objects',
schema: z
.object({
participants: z.array(api.getModelRef('User')),
})
.extend({ meta: pagedResponseMeta }),
},
})
+60
View File
@@ -0,0 +1,60 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
import { eventPayloadSchema } from '../models/event'
import { authHeaders } from './auth'
import { OperationFunc } from './types'
const section = 'event' as const
export const getEventOperation: OperationFunc = (api) => ({
name: 'getEvent',
description: 'Retrieves the [Event](#schema_event) object for a valid identifier.',
method: 'get',
path: '/events/{id}',
parameters: {
...authHeaders,
id: {
in: 'path',
type: 'string',
description: 'Id of the Event',
},
},
section,
response: {
description: 'Returns an [Event](#schema_event) object if a valid identifier was provided',
schema: schema(
z.object({
event: api.getModelRef('Event'),
})
),
},
})
export const createEventOperation: OperationFunc = (api) => ({
name: 'createEvent',
description: 'Creates a custom [Event](#schema_event)',
method: 'post',
path: '/events',
parameters: authHeaders,
requestBody: {
description: 'Event data',
schema: schema(
z.object({
payload: eventPayloadSchema,
conversationId: schema(z.string(), {
description: 'ID of the [Conversation](#schema_conversation)',
}),
})
),
},
section,
response: {
description: 'Returns a [Event](#schema_event).',
status: 201,
schema: schema(
z.object({
event: api.getModelRef('Event'),
})
),
},
})
+19
View File
@@ -0,0 +1,19 @@
import _ from 'lodash'
import { ChatApi } from '../api'
import * as conversation from './conversation'
import * as event from './event'
import * as message from './message'
import * as user from './user'
export * as conversation from './conversation'
export * as message from './message'
export * as user from './user'
export * as event from './event'
type ValueOf<T> = T[keyof T]
export type OperationFunction = ValueOf<typeof conversation> | ValueOf<typeof message> | ValueOf<typeof user>
export type Operation = ReturnType<OperationFunction>
const operationFunctions = { ...conversation, ...message, ...user, ...event }
export const createOperations = (api: ChatApi) => _.mapValues(operationFunctions, (fn) => fn(api))
@@ -0,0 +1,83 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
import { messagePayloadSchema } from '../models/message'
import { authHeaders } from './auth'
import { OperationFunc } from './types'
const section = 'message' as const
export const getMessageOperation: OperationFunc = (api) => ({
name: 'getMessage',
description: 'Retrieves the [Message](#schema_message) object for a valid identifier.',
method: 'get',
path: '/messages/{id}',
parameters: {
...authHeaders,
id: {
in: 'path',
type: 'string',
description: 'Id of the Message',
},
},
section,
response: {
description: 'Returns a [Message](#schema_message) object if a valid identifier was provided',
schema: schema(
z.object({
message: api.getModelRef('Message'),
})
),
},
})
export const createMessageOperation: OperationFunc = (api) => ({
name: 'createMessage',
description: 'Creates a new [Message](#schema_message)',
method: 'post',
path: '/messages',
parameters: authHeaders,
requestBody: {
description: 'Message data',
schema: z.object({
payload: schema(messagePayloadSchema, {
description: 'Payload is the content type of the message.',
}),
conversationId: schema(z.string(), {
description: 'ID of the [Conversation](#schema_conversation)',
}),
metadata: schema(z.record(z.any()).optional(), {
description: 'Metadata of the message',
}),
}),
},
section,
response: {
description: 'Returns a [Message](#schema_message).',
status: 201,
schema: schema(
z.object({
message: api.getModelRef('Message'),
})
),
},
})
export const deleteMessageOperation: OperationFunc = () => ({
name: 'deleteMessage',
description: 'Permanently deletes a [Message](#schema_message). It cannot be undone.',
method: 'delete',
path: '/messages/{id}',
parameters: {
...authHeaders,
id: {
in: 'path',
type: 'string',
description: 'Message id',
},
},
section,
response: {
description: 'Returns the [Message](#schema_message) object that was deleted',
schema: z.object({}),
},
})
@@ -0,0 +1,21 @@
import type { ParametersMap } from '@bpinternal/opapi'
import { z } from 'zod'
export const pagingParameters: ParametersMap = {
nextToken: {
in: 'query',
description:
'Provide the `meta.nextToken` value provided in the last API response to retrieve the next page of results',
type: 'string',
required: false,
},
}
export const pagedResponseMeta = z.object({
nextToken: z
.string()
.describe(
'The token to use to retrieve the next page of results, passed as a query string parameter (value should be URL-encoded) to this API endpoint.'
)
.optional(),
})
@@ -0,0 +1,4 @@
import { ChatApi } from '../api'
export type Operation = Parameters<ChatApi['addOperation']>[0]
export type OperationFunc = (api: ChatApi) => Operation
+113
View File
@@ -0,0 +1,113 @@
import { schema } from '@bpinternal/opapi'
import z from 'zod'
import { userIdSchema } from '../models/user'
import { authHeaders } from './auth'
import { OperationFunc } from './types'
const section = 'user' as const
const userInput = schema(
z.object({
name: schema(z.string().optional(), {
description: 'Name of the [User](#schema_user) (not a unique identifier)',
}),
pictureUrl: schema(z.string().optional(), {
description: 'Picture url of the [User](#schema_user)',
}),
profile: schema(z.string().max(1000).optional(), {
description: 'Custom profile data of the [User](#schema_user) encoded as a string',
}),
})
)
export const getUserOperation: OperationFunc = (api) => ({
name: 'getUser',
description: 'Retrieves the [User](#schema_user) object for a valid identifier.',
method: 'get',
path: '/users/me',
parameters: authHeaders,
section,
response: {
description: 'Returns a [User](#schema_user) object if a valid identifier was provided',
schema: schema(
z.object({
user: api.getModelRef('User'),
})
),
},
})
export const createUserOperation: OperationFunc = (api) => ({
name: 'createUser',
description: "Creates a new [User](#schema_user). This operation can't be called when using manual authentication.",
method: 'post',
path: '/users',
requestBody: {
description: 'User data',
schema: userInput.extend({ id: userIdSchema.optional() }),
},
section,
response: {
description: 'Returns a [User](#schema_user)',
status: 201,
schema: z.object({
user: api.getModelRef('User'),
key: z.string(),
}),
},
})
export const getOrCreateUserOperation: OperationFunc = (api) => ({
name: 'getOrCreateUser',
description: 'Get or create a new [User](#schema_user)',
method: 'post',
path: '/users/get-or-create',
requestBody: {
description: 'User data',
schema: userInput,
},
parameters: {
...authHeaders,
},
section,
response: {
description: 'Returns a [User](#schema_user)',
status: 201,
schema: z.object({
user: api.getModelRef('User'),
}),
},
})
export const updateUserOperation: OperationFunc = (api) => ({
name: 'updateUser',
description: 'Update [User](#schema_user)',
method: 'put',
path: '/users/me',
parameters: authHeaders,
requestBody: {
description: 'User data',
schema: userInput,
},
section,
response: {
description: 'Returns a [User](#schema_user)',
status: 200,
schema: z.object({
user: api.getModelRef('User'),
}),
},
})
export const deleteUserOperation: OperationFunc = () => ({
name: 'deleteUser',
description: 'Permanently deletes a [User](#schema_user). It cannot be undone.',
method: 'delete',
path: '/users/me',
parameters: authHeaders,
section,
response: {
description: 'Returns the [User](#schema_user) object that was deleted',
schema: z.object({}),
},
})
+40
View File
@@ -0,0 +1,40 @@
import { z } from 'zod'
import { message, event } from './models'
export const signalSchemas = {
messageCreated: z.object({
type: z.literal('message_created'),
data: message.messageSchema.extend({
isBot: z.boolean().describe('Whether the message was created by the bot or not'),
}),
}),
eventCreated: z.object({
type: z.literal('event_created'),
data: event.eventSchema.omit({ id: true }).extend({
id: z.string().nullable(),
isBot: z.boolean().describe('Whether the event was created by the bot or not'),
}),
}),
participantAdded: z.object({
type: z.literal('participant_added'),
data: z.object({
conversationId: z.string(),
participantId: z.string(),
}),
}),
participantRemoved: z.object({
type: z.literal('participant_removed'),
data: z.object({
conversationId: z.string(),
participantId: z.string(),
}),
}),
messageDeleted: z.object({
type: z.literal('message_deleted'),
data: z.object({
id: z.string(),
conversationId: z.string(),
userId: z.string(),
}),
}),
}
+1
View File
@@ -0,0 +1 @@
export const apiVersion = '1.0.0' // do not bump, tied to a single ECS service