Set chatwoot custom inbox name

This commit is contained in:
Judson Cairo 2024-04-21 16:33:20 -03:00
parent e071f56767
commit 3bf975d90f
5 changed files with 12 additions and 5 deletions

View File

@ -65,6 +65,7 @@ export class InstanceController {
chatwoot_reopen_conversation,
chatwoot_conversation_pending,
chatwoot_import_contacts,
chatwoot_name_inbox,
chatwoot_import_messages,
chatwoot_days_limit_import_messages,
reject_call,
@ -513,7 +514,7 @@ export class InstanceController {
token: chatwoot_token,
url: chatwoot_url,
sign_msg: chatwoot_sign_msg || false,
name_inbox: instance.instanceName.split('-cwId-')[0],
name_inbox: chatwoot_name_inbox ?? instance.instanceName.split('-cwId-')[0],
number,
reopen_conversation: chatwoot_reopen_conversation || false,
conversation_pending: chatwoot_conversation_pending || false,
@ -577,7 +578,7 @@ export class InstanceController {
import_messages: chatwoot_import_messages ?? true,
days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
number,
name_inbox: instance.instanceName,
name_inbox: chatwoot_name_inbox ?? instance.instanceName,
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
},
};

View File

@ -30,6 +30,7 @@ export class InstanceDto {
chatwoot_import_contacts?: boolean;
chatwoot_import_messages?: boolean;
chatwoot_days_limit_import_messages?: number;
chatwoot_name_inbox?: string;
websocket_enabled?: boolean;
websocket_events?: string[];
rabbitmq_enabled?: boolean;

View File

@ -55,9 +55,12 @@ export class ChatwootController {
data.import_messages = false;
data.days_limit_import_messages = 0;
data.auto_create = false;
data.name_inbox = '';
}
data.name_inbox = instance.instanceName;
if (!data.name_inbox || data.name_inbox === '') {
data.name_inbox = instance.instanceName;
}
const result = await this.chatwootService.create(instance, data);

View File

@ -91,6 +91,7 @@ export class ChatwootService {
with_credentials: true,
credentials: 'include',
token: this.provider.token,
name_inbox: this.provider.name_inbox,
};
}
@ -110,7 +111,7 @@ export class ChatwootService {
await this.initInstanceChatwoot(
instance,
instance.instanceName.split('-cwId-')[0],
data.name_inbox ?? instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
true,
data.number,
@ -710,7 +711,7 @@ export class ChatwootService {
}
this.logger.verbose('find inbox by name');
const findByName = inbox.payload.find((inbox) => inbox.name === instance.instanceName.split('-cwId-')[0]);
const findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().name_inbox);
if (!findByName) {
this.logger.warn('inbox not found');

View File

@ -30,6 +30,7 @@ export const chatwootSchema: JSONSchema7 = {
url: { type: 'string' },
sign_msg: { type: 'boolean', enum: [true, false] },
sign_delimiter: { type: ['string', 'null'] },
name_inbox: { type: ['string', 'null'] },
reopen_conversation: { type: 'boolean', enum: [true, false] },
conversation_pending: { type: 'boolean', enum: [true, false] },
auto_create: { type: 'boolean', enum: [true, false] },