feat: added auto_create to the chatwoot set to create the inbox automatically or not

This commit is contained in:
Davidson Gomes 2023-12-11 17:32:07 -03:00
parent 324d46120b
commit 7a24f52782
6 changed files with 18 additions and 11 deletions

View File

@ -8,7 +8,6 @@ export function onUnexpectedError() {
stderr: process.stderr.fd, stderr: process.stderr.fd,
error, error,
}); });
// process.exit(1);
}); });
process.on('unhandledRejection', (error, origin) => { process.on('unhandledRejection', (error, origin) => {
@ -18,6 +17,5 @@ export function onUnexpectedError() {
stderr: process.stderr.fd, stderr: process.stderr.fd,
error, error,
}); });
// process.exit(1);
}); });
} }

View File

@ -891,6 +891,7 @@ export const chatwootSchema: JSONSchema7 = {
sign_msg: { type: 'boolean', enum: [true, false] }, sign_msg: { type: 'boolean', enum: [true, false] },
reopen_conversation: { type: 'boolean', enum: [true, false] }, reopen_conversation: { type: 'boolean', enum: [true, false] },
conversation_pending: { type: 'boolean', enum: [true, false] }, conversation_pending: { type: 'boolean', enum: [true, false] },
auto_create: { type: 'boolean', enum: [true, false] },
}, },
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'], required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'],
...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'), ...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'),

View File

@ -42,6 +42,7 @@ export class ChatwootController {
data.sign_msg = false; data.sign_msg = false;
data.reopen_conversation = false; data.reopen_conversation = false;
data.conversation_pending = false; data.conversation_pending = false;
data.auto_create = false;
} }
data.name_inbox = instance.instanceName; data.name_inbox = instance.instanceName;

View File

@ -446,15 +446,8 @@ export class InstanceController {
number, number,
reopen_conversation: chatwoot_reopen_conversation || false, reopen_conversation: chatwoot_reopen_conversation || false,
conversation_pending: chatwoot_conversation_pending || false, conversation_pending: chatwoot_conversation_pending || false,
auto_create: true,
}); });
this.chatwootService.initInstanceChatwoot(
instance,
instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
qrcode,
number,
);
} catch (error) { } catch (error) {
this.logger.log(error); this.logger.log(error);
} }

View File

@ -8,4 +8,5 @@ export class ChatwootDto {
number?: string; number?: string;
reopen_conversation?: boolean; reopen_conversation?: boolean;
conversation_pending?: boolean; conversation_pending?: boolean;
auto_create?: boolean;
} }

View File

@ -6,7 +6,7 @@ import Jimp from 'jimp';
import mimeTypes from 'mime-types'; import mimeTypes from 'mime-types';
import path from 'path'; import path from 'path';
import { ConfigService } from '../../config/env.config'; import { ConfigService, HttpServer } from '../../config/env.config';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
import { ROOT_DIR } from '../../config/path.config'; import { ROOT_DIR } from '../../config/path.config';
import { ChatwootDto } from '../dto/chatwoot.dto'; import { ChatwootDto } from '../dto/chatwoot.dto';
@ -99,9 +99,22 @@ export class ChatwootService {
public create(instance: InstanceDto, data: ChatwootDto) { public create(instance: InstanceDto, data: ChatwootDto) {
this.logger.verbose('create chatwoot: ' + instance.instanceName); this.logger.verbose('create chatwoot: ' + instance.instanceName);
this.waMonitor.waInstances[instance.instanceName].setChatwoot(data); this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
this.logger.verbose('chatwoot created'); this.logger.verbose('chatwoot created');
if (data.auto_create) {
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
this.initInstanceChatwoot(
instance,
instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
true,
data.number,
);
}
return data; return data;
} }