mirror of
https://github.com/marcogll/builderbot-openai-assistants.git
synced 2026-01-13 13:25:18 +00:00
fix: stuff
This commit is contained in:
79
README.md
79
README.md
@@ -1,44 +1,73 @@
|
|||||||
|
# WhatsApp AI Assistant Bot
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://builderbot.vercel.app/">
|
|
||||||
<picture>
|
|
||||||
<img src="https://builderbot.vercel.app/assets/thumbnail-vector.png" height="80">
|
<img src="https://builderbot.vercel.app/assets/thumbnail-vector.png" height="80">
|
||||||
</picture>
|
|
||||||
<h2 align="center">BuilderBot</h2>
|
|
||||||
</a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
This project creates a WhatsApp bot that integrates with an AI assistant using BuilderBot technology. It allows for automated conversations and intelligent responses powered by OpenAI's assistant API.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
<p align="center">
|
- Automated conversation flows for WhatsApp
|
||||||
<a aria-label="NPM version" href="https://www.npmjs.com/package/@builderbot/bot">
|
- Integration with OpenAI's assistant API
|
||||||
<img alt="" src="https://img.shields.io/npm/v/@builderbot/bot?color=%2300c200&label=%40bot-whatsapp">
|
- Agnostic to WhatsApp provider
|
||||||
</a>
|
- Automated responses to frequently asked questions
|
||||||
<a aria-label="Join the community on GitHub" href="https://link.codigoencasa.com/DISCORD">
|
- Real-time message receiving and responding
|
||||||
<img alt="" src="https://img.shields.io/discord/915193197645402142?logo=discord">
|
- Interaction tracking with customers
|
||||||
</a>
|
- Expandable functionality through triggers
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
With this library, you can build automated conversation flows agnostic to the WhatsApp provider, set up automated responses for frequently asked questions, receive and respond to messages automatically, and track interactions with customers. Additionally, you can easily set up triggers to expand functionalities limitlessly.
|
1. Clone this repository
|
||||||
|
2. Install dependencies:
|
||||||
|
```
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
3. Set up your environment variables in a `.env` file:
|
||||||
|
```
|
||||||
|
PORT=3008
|
||||||
|
ASSISTANT_ID=your_openai_assistant_id
|
||||||
|
```
|
||||||
|
4. Run the development server:
|
||||||
|
```
|
||||||
|
pnpm run dev
|
||||||
|
```
|
||||||
|
|
||||||
```
|
### Using Docker (Recommended)
|
||||||
npm create builderbot@latest
|
|
||||||
```
|
|
||||||
|
|
||||||
|
This project includes a Dockerfile for easy deployment and consistent environments. To use Docker:
|
||||||
|
|
||||||
|
1. Build the Docker image:
|
||||||
|
```
|
||||||
|
docker build -t whatsapp-ai-assistant .
|
||||||
|
```
|
||||||
|
2. Run the container:
|
||||||
|
```
|
||||||
|
docker run -p 3008:3008 --env-file .env whatsapp-ai-assistant
|
||||||
|
```
|
||||||
|
|
||||||
|
This method ensures that the application runs in a consistent environment across different systems.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
The bot is configured in the `src/app.ts` file. It uses the BuilderBot library to create flows and handle messages. The main welcome flow integrates with the OpenAI assistant to generate responses.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Visit [builderbot](https://builderbot.vercel.app/) to view the full documentation.
|
For more detailed information on how to use and extend this bot, please refer to the [BuilderBot documentation](https://builderbot.vercel.app/).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
## Official Course
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||||
|
|
||||||
If you want to discover all the functions and features offered by the library you can take the course.
|
## License
|
||||||
[View Course](https://app.codigoencasa.com/courses/builderbot?refCode=LEIFER)
|
|
||||||
|
|
||||||
|
This project is open-source and available under the [MIT License](LICENSE).
|
||||||
|
|
||||||
## Contact Us
|
## Contact
|
||||||
- [💻 Discord](https://link.codigoencasa.com/DISCORD)
|
|
||||||
- [👌 𝕏 (Twitter)](https://twitter.com/leifermendez)
|
For questions and support, join our [Discord community](https://link.codigoencasa.com/DISCORD) or follow us on [Twitter](https://twitter.com/leifermendez).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Built with [BuilderBot](https://www.builderbot.app/en) - Empowering conversational AI for WhatsApp
|
||||||
|
|||||||
17
package.json
17
package.json
@@ -5,16 +5,17 @@
|
|||||||
"main": "dist/app.js",
|
"main": "dist/app.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./dist/app.js",
|
"start": "pnpm run build && node ./dist/app.js",
|
||||||
"lint": "eslint . --no-ignore",
|
"lint": "eslint . --no-ignore",
|
||||||
"dev": "npm run lint && nodemon ./src/app.ts",
|
"dev": "pnpm run lint && nodemon ./src/app.ts",
|
||||||
"build": "npx rollup -c"
|
"build": "pnpm run rollup -c",
|
||||||
|
"preinstall": "npx only-allow pnpm"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@builderbot-plugins/openai-assistants": "^0.0.2",
|
"@builderbot-plugins/openai-assistants": "^0.0.2",
|
||||||
"@builderbot/bot": "1.1.4-alpha.2",
|
"@builderbot/bot": "1.2.1",
|
||||||
"@builderbot/provider-baileys": "1.1.4-alpha.2",
|
"@builderbot/provider-baileys": "1.2.1",
|
||||||
"dotenv": "^16.4.5"
|
"dotenv": "^16.4.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -31,5 +32,9 @@
|
|||||||
"typescript": "^5.4.3"
|
"typescript": "^5.4.3"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC"
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20",
|
||||||
|
"pnpm": ">=8"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
4064
pnpm-lock.yaml
generated
4064
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
55
src/app.ts
55
src/app.ts
@@ -1,29 +1,60 @@
|
|||||||
import "dotenv/config"
|
import "dotenv/config"
|
||||||
|
|
||||||
import { createBot, createProvider, createFlow, addKeyword, EVENTS } from '@builderbot/bot'
|
import { createBot, createProvider, createFlow, addKeyword, EVENTS } from '@builderbot/bot'
|
||||||
import { MemoryDB as Database } from '@builderbot/bot'
|
import { MemoryDB } from '@builderbot/bot'
|
||||||
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
|
import { BaileysProvider } from '@builderbot/provider-baileys'
|
||||||
import { toAsk, httpInject } from "@builderbot-plugins/openai-assistants"
|
import { toAsk, httpInject } from "@builderbot-plugins/openai-assistants"
|
||||||
import { typing } from "./utils/presence"
|
import { typing } from "./utils/presence"
|
||||||
|
|
||||||
const PORT = process.env?.PORT ?? 3008
|
/** Puerto en el que se ejecutará el servidor */
|
||||||
const ASSISTANT_ID = process.env?.ASSISTANT_ID ?? ''
|
const PORT = process.env.PORT ?? 3008
|
||||||
|
/** ID del asistente de OpenAI */
|
||||||
|
const ASSISTANT_ID = process.env.ASSISTANT_ID ?? ''
|
||||||
|
|
||||||
const welcomeFlow = addKeyword<Provider, Database>(EVENTS.WELCOME)
|
/**
|
||||||
|
* Flujo de bienvenida que maneja las respuestas del asistente de IA
|
||||||
|
* @type {import('@builderbot/bot').Flow<BaileysProvider, MemoryDB>}
|
||||||
|
*/
|
||||||
|
const welcomeFlow = addKeyword<BaileysProvider, MemoryDB>(EVENTS.WELCOME)
|
||||||
.addAction(async (ctx, { flowDynamic, state, provider }) => {
|
.addAction(async (ctx, { flowDynamic, state, provider }) => {
|
||||||
await typing(ctx, provider)
|
await typing(ctx, provider)
|
||||||
const response = await toAsk(ASSISTANT_ID, ctx.body, state)
|
const response = await toAsk(ASSISTANT_ID, ctx.body, state)
|
||||||
const chunks = response.split(/\n\n+/);
|
|
||||||
for (const chunk of chunks) {
|
// Dividir la respuesta en chunks y enviarlos secuencialmente
|
||||||
await flowDynamic([{ body: chunk.trim() }]);
|
const chunks = response.split(/\n\n+/)
|
||||||
}
|
for (const chunk of chunks) {
|
||||||
|
const cleanedChunk = chunk.trim().replace(/【.*?】/g, "");
|
||||||
|
await flowDynamic([{ body: cleanedChunk }])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Función principal que configura y inicia el bot
|
||||||
|
* @async
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
/**
|
||||||
|
* Flujo del bot
|
||||||
|
* @type {import('@builderbot/bot').Flow<BaileysProvider, MemoryDB>}
|
||||||
|
*/
|
||||||
const adapterFlow = createFlow([welcomeFlow])
|
const adapterFlow = createFlow([welcomeFlow])
|
||||||
const adapterProvider = createProvider(Provider)
|
|
||||||
const adapterDB = new Database()
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proveedor de servicios de mensajería
|
||||||
|
* @type {BaileysProvider}
|
||||||
|
*/
|
||||||
|
const adapterProvider = createProvider(BaileysProvider)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base de datos en memoria para el bot
|
||||||
|
* @type {MemoryDB}
|
||||||
|
*/
|
||||||
|
const adapterDB = new MemoryDB()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuración y creación del bot
|
||||||
|
* @type {import('@builderbot/bot').Bot<BaileysProvider, MemoryDB>}
|
||||||
|
*/
|
||||||
const { httpServer } = await createBot({
|
const { httpServer } = await createBot({
|
||||||
flow: adapterFlow,
|
flow: adapterFlow,
|
||||||
provider: adapterProvider,
|
provider: adapterProvider,
|
||||||
|
|||||||
Reference in New Issue
Block a user