Added webhook to send errors

This commit is contained in:
Davidson Gomes
2023-08-25 09:31:13 -03:00
parent 9b72b3e332
commit 54cfa67d52
5 changed files with 7 additions and 2 deletions

View File

@@ -96,6 +96,7 @@ export type EventsWebhook = {
TYPEBOT_CHANGE_STATUS: boolean;
CHAMA_AI_ACTION: boolean;
ERRORS: boolean;
ERRORS_WEBHOOK: string;
};
export type ApiKey = { KEY: string };
@@ -272,6 +273,7 @@ export class ConfigService {
TYPEBOT_CHANGE_STATUS: process.env?.WEBHOOK_EVENTS_TYPEBOT_CHANGE_STATUS === 'true',
CHAMA_AI_ACTION: process.env?.WEBHOOK_EVENTS_CHAMA_AI_ACTION === 'true',
ERRORS: process.env?.WEBHOOK_EVENTS_ERRORS === 'true',
ERRORS_WEBHOOK: process.env?.WEBHOOK_EVENTS_ERRORS_WEBHOOK || '',
},
},
CONFIG_SESSION_PHONE: {

View File

@@ -127,6 +127,7 @@ WEBHOOK:
CHAMA_AI_ACTION: false
# This event is used to send errors to the webhook
ERRORS: false
ERRORS_WEBHOOK: <url>
CONFIG_SESSION_PHONE:
# Name that will be displayed on smartphone connection

View File

@@ -57,7 +57,7 @@ function bootstrap() {
if (err) {
const webhook = configService.get<Webhook>('WEBHOOK');
if (webhook.GLOBAL.ENABLED && webhook.EVENTS.ERRORS) {
if (webhook.EVENTS.ERRORS_WEBHOOK && webhook.EVENTS.ERRORS_WEBHOOK != '' && webhook.EVENTS.ERRORS) {
const tzoffset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds
const localISOTime = new Date(Date.now() - tzoffset).toISOString();
const now = localISOTime;
@@ -77,7 +77,7 @@ function bootstrap() {
logger.error(errorData);
const baseURL = configService.get<Webhook>('WEBHOOK').GLOBAL.URL;
const baseURL = webhook.EVENTS.ERRORS_WEBHOOK;
const httpService = axios.create({ baseURL });
httpService.post('', errorData);