|
|
|
@ -7,7 +7,13 @@ declare global {
|
|
|
|
|
var Bun: typeof import('bun');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PORT = 3007;
|
|
|
|
|
const REQUIRED_ENV = [
|
|
|
|
|
'EVOLUTION_API_URL',
|
|
|
|
|
'EVOLUTION_API_KEY',
|
|
|
|
|
'EVOLUTION_API_INSTANCE',
|
|
|
|
|
'WHATSAPP_COMMUNITY_ID',
|
|
|
|
|
'CHATBOT_PHONE_NUMBER'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
type WebhookPayload = {
|
|
|
|
|
event: string;
|
|
|
|
@ -96,14 +102,16 @@ export class WebhookServer {
|
|
|
|
|
static start() {
|
|
|
|
|
this.validateEnv();
|
|
|
|
|
|
|
|
|
|
const PORT = process.env.PORT || 3007;
|
|
|
|
|
const PORT = process.env.PORT || '3007';
|
|
|
|
|
console.log('✅ Environment variables validated');
|
|
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
|
return Bun.serve({
|
|
|
|
|
port: PORT,
|
|
|
|
|
const server = Bun.serve({
|
|
|
|
|
port: parseInt(PORT),
|
|
|
|
|
fetch: WebhookServer.handleRequest
|
|
|
|
|
});
|
|
|
|
|
console.log(`Server running on port ${PORT}`);
|
|
|
|
|
return server;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|