Merge pull request #566 from judsonjuniorr/feat/cw-inbox-name

Chatwoot inbox name
This commit is contained in:
Davidson Gomes 2024-04-27 13:13:06 -03:00 committed by GitHub
commit 720efcbcbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 6 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

@ -86,12 +86,13 @@ export class ChatwootService {
return client;
}
public getClientCwConfig(): ChatwootAPIConfig {
public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string } {
return {
basePath: this.provider.url,
with_credentials: true,
credentials: 'include',
token: this.provider.token,
name_inbox: this.provider.name_inbox,
};
}
@ -111,7 +112,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,
@ -711,7 +712,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] },