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
+9
View File
@@ -0,0 +1,9 @@
import * as sdk from '@botpress/sdk'
import chat from './bp_modules/chat'
export default new sdk.BotDefinition({
integrations: {},
states: {},
events: {},
recurringEvents: {},
}).addIntegration(chat, { enabled: true, configuration: {} })
+13
View File
@@ -0,0 +1,13 @@
import rootConfig from '../../eslint.config.mjs'
export default [
...rootConfig,
{
languageOptions: {
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
]
+19
View File
@@ -0,0 +1,19 @@
{
"name": "@bp-bots/echo",
"description": "Echo bot used by the chat-e2e test suite",
"main": "src/index.ts",
"scripts": {
"check:type": "tsc --noEmit",
"check:bplint": "bp lint",
"build": "bp add -y && bp build"
},
"private": true,
"devDependencies": {
"@botpress/cli": "workspace:*",
"@botpress/sdk": "workspace:*",
"@botpresshub/chat": "workspace:*"
},
"bpDependencies": {
"chat": "../../integrations/chat"
}
}
+33
View File
@@ -0,0 +1,33 @@
import * as bp from '.botpress'
type CreateMessageArgs = bp.ClientInputs['createMessage']
type RespondArgs = CreateMessageArgs['payload'] & {
type: CreateMessageArgs['type']
}
export type ApiProps = bp.MessageHandlerProps | bp.EventHandlerProps
export class Api {
public static from = (args: ApiProps): Api => new Api(args)
private constructor(private _args: ApiProps) {}
public async respond(resp: RespondArgs) {
const { type, ...payload } = resp
let conversationId: string
if ('message' in this._args) {
conversationId = this._args.message.conversationId
} else {
conversationId = this._args.event.payload.conversationId
}
await this._args.client.createMessage({
conversationId,
userId: this._args.ctx.botId,
tags: {},
type,
payload,
})
}
}
+5
View File
@@ -0,0 +1,5 @@
import * as bp from '.botpress'
export const bot = new bp.Bot({
actions: {},
})
+212
View File
@@ -0,0 +1,212 @@
import { Api } from './api'
import { bot } from './bot'
import { markdown } from './markdown'
const STEAK = 'https://upload.wikimedia.org/wikipedia/commons/9/91/T-bone-raw-MCB.jpg'
const LIZST = 'https://vmirror.imslp.org/files/imglnks/usimg/5/5c/IMSLP301563-PMLP02598-upload.mp3'
bot.on.event('*', async (args) => {
console.info('received event', {
conversationId: args.event.conversationId,
userId: args.event.userId,
})
if (args.event.type === 'chat:custom') {
console.info('custom event received', args.event.payload)
await args.client.callAction({
type: 'chat:sendEvent',
input: args.event.payload,
})
}
})
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
bot.on.message('*', async (args) => {
console.info('received message', args.message)
const api = Api.from(args)
if (args.message.type !== 'text') {
await api.respond({ type: 'text', text: 'I only understand text messages' })
return
}
const text = args.message.payload.text.toLowerCase()
switch (text) {
case 'text':
await api.respond({ type: 'text', text: 'Hello, world!' })
break
case 'markdown':
await api.respond({
type: 'markdown',
markdown,
})
break
case 'image':
await api.respond({
type: 'image',
imageUrl: STEAK,
})
break
case 'location':
await api.respond({
type: 'location',
latitude: 40.748817,
longitude: -73.985428,
})
break
case 'pdf':
await api.respond({
type: 'file',
fileUrl: 'https://cdn.botpress.dev/test.pdf',
})
break
case 'file':
await api.respond({
type: 'file',
fileUrl: 'https://spg-test-public-files.s3.amazonaws.com/cities.csv',
})
break
case 'video':
await api.respond({
type: 'video',
videoUrl: 'https://spg-test-public-files.s3.us-east-1.amazonaws.com/sample-mp4-file-small.mp4',
})
break
case 'audio':
await api.respond({
type: 'audio',
audioUrl: LIZST,
})
break
case 'choice':
await api.respond({
type: 'choice',
text: 'Choose an option',
options: [
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3', value: 'option3' },
],
})
break
case 'dropdown':
await api.respond({
type: 'dropdown',
text: 'Choose an option',
options: [
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3', value: 'option3' },
{ label: 'Option 4', value: 'option4' },
{ label: 'Option 5', value: 'option5' },
{ label: 'Option 6', value: 'option6' },
{ label: 'Option 7', value: 'option7' },
{ label: 'Option 8', value: 'option8' },
],
})
break
case 'card':
await api.respond({
type: 'card',
title: 'title',
subtitle: 'subtitle',
imageUrl: STEAK,
actions: [
{ action: 'url', label: 'label1', value: 'https://google.com' },
{ action: 'say', label: 'label2', value: 'text' },
],
})
break
case 'carousel':
await api.respond({
type: 'carousel',
items: [
{
title: 'title 1',
subtitle: 'subtitle 1',
actions: [
{
action: 'url',
label: 'label 1',
value: 'https://google.com',
},
],
imageUrl: STEAK,
},
{
title: 'title 2',
subtitle: 'subtitle 2',
actions: [
{
action: 'say',
label: 'label 2',
value: 'text 2',
},
],
imageUrl: 'https://miro.medium.com/v2/resize:fit:800/1*gGzjds6d329U8umqHI0nKQ.jpeg',
},
],
})
break
case 'link':
await api.respond({
type: 'text',
text: '[Click here](https://google.com) to go to Google',
})
break
case 'empty_choice':
await api.respond({
type: 'choice',
text: 'Choose an option',
options: [],
})
break
case 'empty_card':
await api.respond({
type: 'card',
title: 'title',
subtitle: 'subtitle',
actions: [],
})
break
case 'bloc':
await api.respond({
type: 'bloc',
items: [
{
type: 'text',
payload: { text: 'Hello, world!' },
},
{
type: 'image',
payload: { imageUrl: STEAK },
},
{
type: 'audio',
payload: { audioUrl: LIZST },
},
],
})
break
case 'loop':
for (let i = 0; i < 20; i++) {
await sleep(1000)
await api.respond({ type: 'text', text: `Message ${i}` })
}
break
case 'metadata':
const { payload } = args.message
const metadata = 'metadata' in payload ? payload.metadata : {}
await api.respond({ type: 'text', text: 'metadata', metadata })
break
default:
const { name } = args.user
const hiMsg = name ? `Hi, ${name}` : 'Hi'
await api.respond({ type: 'text', text: `${hiMsg}! You said: "${text}"` })
break
}
})
export default bot
+34
View File
@@ -0,0 +1,34 @@
export const markdown = `
# Title 1
## Title 2
### Title 3
#### Title 4
- unordered list item 1
- unordered list item 2
- unordered list item 3
1. ordered list item 1
2. ordered list item 2
3. ordered list item 3
this is **bold text**
this is ~~strikethrough text~~
this is _italic text_
this is [a link](https://www.google.com)
this is a code block
\`\`\`javascript
console.log('hello world')
\`\`\`
this is a table
| header 1 | header 2 |
|-----------|-----------|
| cell l1 | cell r1 |
| cell l2 | cell r2 |
| cell l3 | cell r3 |
`
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": { "*": ["./*"] },
"outDir": "dist"
},
"include": [".botpress/**/*", "src/**/*", "*.ts"]
}