feat: pusher event integration

This commit is contained in:
Davidson Gomes
2024-10-11 07:01:38 -03:00
parent f38f3e5ba5
commit 29e2cfaf96
19 changed files with 540 additions and 29 deletions

View File

@@ -147,6 +147,36 @@ export type EventsWebhook = {
ERRORS_WEBHOOK: string;
};
export type EventsPusher = {
APPLICATION_STARTUP: boolean;
INSTANCE_CREATE: boolean;
INSTANCE_DELETE: boolean;
QRCODE_UPDATED: boolean;
MESSAGES_SET: boolean;
MESSAGES_UPSERT: boolean;
MESSAGES_EDITED: boolean;
MESSAGES_UPDATE: boolean;
MESSAGES_DELETE: boolean;
SEND_MESSAGE: boolean;
CONTACTS_SET: boolean;
CONTACTS_UPDATE: boolean;
CONTACTS_UPSERT: boolean;
PRESENCE_UPDATE: boolean;
CHATS_SET: boolean;
CHATS_UPDATE: boolean;
CHATS_DELETE: boolean;
CHATS_UPSERT: boolean;
CONNECTION_UPDATE: boolean;
LABELS_EDIT: boolean;
LABELS_ASSOCIATION: boolean;
GROUPS_UPSERT: boolean;
GROUP_UPDATE: boolean;
GROUP_PARTICIPANTS_UPDATE: boolean;
CALL: boolean;
TYPEBOT_START: boolean;
TYPEBOT_CHANGE_STATUS: boolean;
};
export type ApiKey = { KEY: string };
export type Auth = {
@@ -163,6 +193,16 @@ export type GlobalWebhook = {
ENABLED: boolean;
WEBHOOK_BY_EVENTS: boolean;
};
export type GlobalPusher = {
ENABLED: boolean;
APP_ID: string;
KEY: string;
SECRET: string;
CLUSTER: string;
USE_TLS: boolean;
};
export type CacheConfRedis = {
ENABLED: boolean;
URI: string;
@@ -176,6 +216,7 @@ export type CacheConfLocal = {
};
export type SslConf = { PRIVKEY: string; FULLCHAIN: string };
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
export type Pusher = { ENABLED: boolean; GLOBAL?: GlobalPusher; EVENTS: EventsPusher };
export type ConfigSessionPhone = { CLIENT: string; NAME: string; VERSION: string };
export type QrCode = { LIMIT: number; COLOR: string };
export type Typebot = { ENABLED: boolean; API_VERSION: string; SEND_MEDIA_BASE64: boolean };
@@ -225,6 +266,7 @@ export interface Env {
DEL_TEMP_INSTANCES: boolean;
LANGUAGE: Language;
WEBHOOK: Webhook;
PUSHER: Pusher;
CONFIG_SESSION_PHONE: ConfigSessionPhone;
QRCODE: QrCode;
TYPEBOT: Typebot;
@@ -270,7 +312,9 @@ export class ConfigService {
},
CORS: {
ORIGIN: process.env.CORS_ORIGIN?.split(',') || ['*'],
METHODS: (process.env.CORS_METHODS?.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'] as HttpMethods[],
METHODS:
(process.env.CORS_METHODS?.split(',') as HttpMethods[]) ||
(['POST', 'GET', 'PUT', 'DELETE'] as HttpMethods[]),
CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true',
},
SSL_CONF: {
@@ -347,6 +391,46 @@ export class ConfigService {
ENABLED: process.env?.WEBSOCKET_ENABLED === 'true',
GLOBAL_EVENTS: process.env?.WEBSOCKET_GLOBAL_EVENTS === 'true',
},
PUSHER: {
ENABLED: process.env?.PUSHER_ENABLED === 'true',
GLOBAL: {
ENABLED: process.env?.PUSHER_GLOBAL_ENABLED === 'true',
APP_ID: process.env?.PUSHER_GLOBAL_APP_ID || '',
KEY: process.env?.PUSHER_GLOBAL_KEY || '',
SECRET: process.env?.PUSHER_GLOBAL_SECRET || '',
CLUSTER: process.env?.PUSHER_GLOBAL_CLUSTER || '',
USE_TLS: process.env?.PUSHER_GLOBAL_USE_TLS === 'true',
},
EVENTS: {
APPLICATION_STARTUP: process.env?.PUSHER_EVENTS_APPLICATION_STARTUP === 'true',
INSTANCE_CREATE: process.env?.PUSHER_EVENTS_INSTANCE_CREATE === 'true',
INSTANCE_DELETE: process.env?.PUSHER_EVENTS_INSTANCE_DELETE === 'true',
QRCODE_UPDATED: process.env?.PUSHER_EVENTS_QRCODE_UPDATED === 'true',
MESSAGES_SET: process.env?.PUSHER_EVENTS_MESSAGES_SET === 'true',
MESSAGES_UPSERT: process.env?.PUSHER_EVENTS_MESSAGES_UPSERT === 'true',
MESSAGES_EDITED: process.env?.PUSHER_EVENTS_MESSAGES_EDITED === 'true',
MESSAGES_UPDATE: process.env?.PUSHER_EVENTS_MESSAGES_UPDATE === 'true',
MESSAGES_DELETE: process.env?.PUSHER_EVENTS_MESSAGES_DELETE === 'true',
SEND_MESSAGE: process.env?.PUSHER_EVENTS_SEND_MESSAGE === 'true',
CONTACTS_SET: process.env?.PUSHER_EVENTS_CONTACTS_SET === 'true',
CONTACTS_UPDATE: process.env?.PUSHER_EVENTS_CONTACTS_UPDATE === 'true',
CONTACTS_UPSERT: process.env?.PUSHER_EVENTS_CONTACTS_UPSERT === 'true',
PRESENCE_UPDATE: process.env?.PUSHER_EVENTS_PRESENCE_UPDATE === 'true',
CHATS_SET: process.env?.PUSHER_EVENTS_CHATS_SET === 'true',
CHATS_UPDATE: process.env?.PUSHER_EVENTS_CHATS_UPDATE === 'true',
CHATS_UPSERT: process.env?.PUSHER_EVENTS_CHATS_UPSERT === 'true',
CHATS_DELETE: process.env?.PUSHER_EVENTS_CHATS_DELETE === 'true',
CONNECTION_UPDATE: process.env?.PUSHER_EVENTS_CONNECTION_UPDATE === 'true',
LABELS_EDIT: process.env?.PUSHER_EVENTS_LABELS_EDIT === 'true',
LABELS_ASSOCIATION: process.env?.PUSHER_EVENTS_LABELS_ASSOCIATION === 'true',
GROUPS_UPSERT: process.env?.PUSHER_EVENTS_GROUPS_UPSERT === 'true',
GROUP_UPDATE: process.env?.PUSHER_EVENTS_GROUPS_UPDATE === 'true',
GROUP_PARTICIPANTS_UPDATE: process.env?.PUSHER_EVENTS_GROUP_PARTICIPANTS_UPDATE === 'true',
CALL: process.env?.PUSHER_EVENTS_CALL === 'true',
TYPEBOT_START: process.env?.PUSHER_EVENTS_TYPEBOT_START === 'true',
TYPEBOT_CHANGE_STATUS: process.env?.PUSHER_EVENTS_TYPEBOT_CHANGE_STATUS === 'true',
},
},
WA_BUSINESS: {
TOKEN_WEBHOOK: process.env.WA_BUSINESS_TOKEN_WEBHOOK || 'evolution',
URL: process.env.WA_BUSINESS_URL || 'https://graph.facebook.com',
@@ -354,17 +438,9 @@ export class ConfigService {
LANGUAGE: process.env.WA_BUSINESS_LANGUAGE || 'en',
},
LOG: {
LEVEL: (process.env?.LOG_LEVEL?.split(',') as LogLevel[]) || [
'ERROR',
'WARN',
'DEBUG',
'INFO',
'LOG',
'VERBOSE',
'DARK',
'WEBHOOKS',
'WEBSOCKET',
] as LogLevel[],
LEVEL:
(process.env?.LOG_LEVEL?.split(',') as LogLevel[]) ||
(['ERROR', 'WARN', 'DEBUG', 'INFO', 'LOG', 'VERBOSE', 'DARK', 'WEBHOOKS', 'WEBSOCKET'] as LogLevel[]),
COLOR: process.env?.LOG_COLOR === 'true',
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
},