diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c164e29..021449e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Feature * Added AWS SQS Integration +* Added compatibility with typebot v2 ### Fixed diff --git a/Docker/.env.example b/Docker/.env.example index 88be79fe..b170ac28 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -51,6 +51,12 @@ RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672 WEBSOCKET_ENABLED=false +SQS_ENABLED=false +SQS_ACCESS_KEY_ID= +SQS_SECRET_ACCESS_KEY= +SQS_ACCOUNT_ID= +SQS_REGION= + # Global Webhook Settings # Each instance's Webhook URL and events will be requested at the time it is created ## Define a global webhook that will listen for enabled events from all instances @@ -99,6 +105,8 @@ CONFIG_SESSION_PHONE_NAME=Chrome QRCODE_LIMIT=30 QRCODE_COLOR=#198754 +TYPEBOT_API_VERSION=v1 + # Defines an authentication type for the api # We recommend using the apikey because it will allow you to use a custom token, # if you use jwt, a random token will be generated and may be expired and you will have to generate a new token diff --git a/Dockerfile b/Dockerfile index 8e610d12..0195a249 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,6 +56,12 @@ ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672 ENV WEBSOCKET_ENABLED=false +ENV SQS_ENABLED=false +ENV SQS_ACCESS_KEY_ID= +ENV SQS_SECRET_ACCESS_KEY= +ENV SQS_ACCOUNT_ID= +ENV SQS_REGION= + ENV WEBHOOK_GLOBAL_URL= ENV WEBHOOK_GLOBAL_ENABLED=false @@ -98,6 +104,8 @@ ENV CONFIG_SESSION_PHONE_NAME=Chrome ENV QRCODE_LIMIT=30 ENV QRCODE_COLOR=#198754 +ENV TYPEBOT_API_VERSION=v1 + ENV AUTHENTICATION_TYPE=apikey ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976 diff --git a/src/config/env.config.ts b/src/config/env.config.ts index 118836b7..dcb90fbc 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -132,6 +132,7 @@ export type SslConf = { PRIVKEY: string; FULLCHAIN: string }; export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook }; export type ConfigSessionPhone = { CLIENT: string; NAME: string }; export type QrCode = { LIMIT: number; COLOR: string }; +export type Typebot = { API_VERSION: string }; export type Production = boolean; export interface Env { @@ -150,6 +151,7 @@ export interface Env { WEBHOOK: Webhook; CONFIG_SESSION_PHONE: ConfigSessionPhone; QRCODE: QrCode; + TYPEBOT: Typebot; AUTHENTICATION: Auth; PRODUCTION?: Production; CHATWOOT?: Chatwoot; @@ -305,6 +307,9 @@ export class ConfigService { LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30, COLOR: process.env.QRCODE_COLOR || '#198754', }, + TYPEBOT: { + API_VERSION: process.env?.TYPEBOT_API_VERSION || 'v1', + }, AUTHENTICATION: { TYPE: process.env.AUTHENTICATION_TYPE as 'apikey', API_KEY: { diff --git a/src/dev-env.yml b/src/dev-env.yml index 7af78d40..b2a2e521 100644 --- a/src/dev-env.yml +++ b/src/dev-env.yml @@ -83,6 +83,13 @@ RABBITMQ: ENABLED: false URI: "amqp://guest:guest@localhost:5672" +SQS: + ENABLED: true + ACCESS_KEY_ID: "" + SECRET_ACCESS_KEY: "" + ACCOUNT_ID: "" + REGION: "us-east-1" + WEBSOCKET: ENABLED: false @@ -139,6 +146,9 @@ QRCODE: LIMIT: 30 COLOR: "#198754" +TYPEBOT: + API_VERSION: 'v1' # v1 | v2 + # Defines an authentication type for the api # We recommend using the apikey because it will allow you to use a custom token, # if you use jwt, a random token will be generated and may be expired and you will have to generate a new token diff --git a/src/whatsapp/services/typebot.service.ts b/src/whatsapp/services/typebot.service.ts index fd7b16fb..4ed9b04b 100644 --- a/src/whatsapp/services/typebot.service.ts +++ b/src/whatsapp/services/typebot.service.ts @@ -1,5 +1,6 @@ import axios from 'axios'; +import { ConfigService, Typebot } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; import { InstanceDto } from '../dto/instance.dto'; import { Session, TypebotDto } from '../dto/typebot.dto'; @@ -8,7 +9,7 @@ import { Events } from '../types/wa.types'; import { WAMonitoringService } from './monitor.service'; export class TypebotService { - constructor(private readonly waMonitor: WAMonitoringService) {} + constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {} private readonly logger = new Logger(TypebotService.name); @@ -162,7 +163,8 @@ export class TypebotService { }; try { - const request = await axios.post(data.url + '/api/v1/sendMessage', reqData); + const version = this.configService.get('TYPEBOT').API_VERSION; + const request = await axios.post(`${data.url}/api/${version}/sendMessage`, reqData); await this.sendWAMessage( instance, @@ -251,7 +253,8 @@ export class TypebotService { }; try { - const request = await axios.post(data.url + '/api/v1/sendMessage', reqData); + const version = this.configService.get('TYPEBOT').API_VERSION; + const request = await axios.post(`${data.url}/api/${version}/sendMessage`, reqData); if (request?.data?.sessionId) { data.sessions.push({ @@ -554,7 +557,8 @@ export class TypebotService { }; try { - const request = await axios.post(url + '/api/v1/sendMessage', reqData); + const version = this.configService.get('TYPEBOT').API_VERSION; + const request = await axios.post(`${data.url}/api/${version}/sendMessage`, reqData); await this.sendWAMessage( instance, @@ -640,7 +644,9 @@ export class TypebotService { let request: any; try { - request = await axios.post(url + '/api/v1/sendMessage', reqData); + const version = this.configService.get('TYPEBOT').API_VERSION; + request = await axios.post(`${data.url}/api/${version}/sendMessage`, reqData); + await this.sendWAMessage( instance, remoteJid, @@ -719,7 +725,8 @@ export class TypebotService { sessionId: session.sessionId.split('-')[1], }; - const request = await axios.post(url + '/api/v1/sendMessage', reqData); + const version = this.configService.get('TYPEBOT').API_VERSION; + const request = await axios.post(`${url}/api/${version}/sendMessage`, reqData); await this.sendWAMessage( instance, diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 03d092b1..6002a3e4 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -166,7 +166,7 @@ export class WAStartupService { private chatwootService = new ChatwootService(waMonitor, this.configService); - private typebotService = new TypebotService(waMonitor); + private typebotService = new TypebotService(waMonitor, this.configService); private chamaaiService = new ChamaaiService(waMonitor, this.configService); diff --git a/src/whatsapp/whatsapp.module.ts b/src/whatsapp/whatsapp.module.ts index 7211f8e6..e116cc9c 100644 --- a/src/whatsapp/whatsapp.module.ts +++ b/src/whatsapp/whatsapp.module.ts @@ -102,7 +102,7 @@ export const waMonitor = new WAMonitoringService(eventEmitter, configService, re const authService = new AuthService(configService, waMonitor, repository); -const typebotService = new TypebotService(waMonitor); +const typebotService = new TypebotService(waMonitor, configService); export const typebotController = new TypebotController(typebotService);