Skip to content

Commit 720efcb

Browse files
Merge pull request #566 from judsonjuniorr/feat/cw-inbox-name
Chatwoot inbox name
2 parents d95791c + 26ff0b6 commit 720efcb

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/api/controllers/instance.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class InstanceController {
6565
chatwoot_reopen_conversation,
6666
chatwoot_conversation_pending,
6767
chatwoot_import_contacts,
68+
chatwoot_name_inbox,
6869
chatwoot_import_messages,
6970
chatwoot_days_limit_import_messages,
7071
reject_call,
@@ -513,7 +514,7 @@ export class InstanceController {
513514
token: chatwoot_token,
514515
url: chatwoot_url,
515516
sign_msg: chatwoot_sign_msg || false,
516-
name_inbox: instance.instanceName.split('-cwId-')[0],
517+
name_inbox: chatwoot_name_inbox ?? instance.instanceName.split('-cwId-')[0],
517518
number,
518519
reopen_conversation: chatwoot_reopen_conversation || false,
519520
conversation_pending: chatwoot_conversation_pending || false,
@@ -577,7 +578,7 @@ export class InstanceController {
577578
import_messages: chatwoot_import_messages ?? true,
578579
days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
579580
number,
580-
name_inbox: instance.instanceName,
581+
name_inbox: chatwoot_name_inbox ?? instance.instanceName,
581582
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
582583
},
583584
};

src/api/dto/instance.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class InstanceDto {
3030
chatwoot_import_contacts?: boolean;
3131
chatwoot_import_messages?: boolean;
3232
chatwoot_days_limit_import_messages?: number;
33+
chatwoot_name_inbox?: string;
3334
websocket_enabled?: boolean;
3435
websocket_events?: string[];
3536
rabbitmq_enabled?: boolean;

src/api/integrations/chatwoot/controllers/chatwoot.controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ export class ChatwootController {
5555
data.import_messages = false;
5656
data.days_limit_import_messages = 0;
5757
data.auto_create = false;
58+
data.name_inbox = '';
5859
}
5960

60-
data.name_inbox = instance.instanceName;
61+
if (!data.name_inbox || data.name_inbox === '') {
62+
data.name_inbox = instance.instanceName;
63+
}
6164

6265
const result = await this.chatwootService.create(instance, data);
6366

src/api/integrations/chatwoot/services/chatwoot.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ export class ChatwootService {
8686
return client;
8787
}
8888

89-
public getClientCwConfig(): ChatwootAPIConfig {
89+
public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string } {
9090
return {
9191
basePath: this.provider.url,
9292
with_credentials: true,
9393
credentials: 'include',
9494
token: this.provider.token,
95+
name_inbox: this.provider.name_inbox,
9596
};
9697
}
9798

@@ -111,7 +112,7 @@ export class ChatwootService {
111112

112113
await this.initInstanceChatwoot(
113114
instance,
114-
instance.instanceName.split('-cwId-')[0],
115+
data.name_inbox ?? instance.instanceName.split('-cwId-')[0],
115116
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
116117
true,
117118
data.number,
@@ -711,7 +712,7 @@ export class ChatwootService {
711712
}
712713

713714
this.logger.verbose('find inbox by name');
714-
const findByName = inbox.payload.find((inbox) => inbox.name === instance.instanceName.split('-cwId-')[0]);
715+
const findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().name_inbox);
715716

716717
if (!findByName) {
717718
this.logger.warn('inbox not found');

src/api/integrations/chatwoot/validate/chatwoot.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const chatwootSchema: JSONSchema7 = {
3030
url: { type: 'string' },
3131
sign_msg: { type: 'boolean', enum: [true, false] },
3232
sign_delimiter: { type: ['string', 'null'] },
33+
name_inbox: { type: ['string', 'null'] },
3334
reopen_conversation: { type: 'boolean', enum: [true, false] },
3435
conversation_pending: { type: 'boolean', enum: [true, false] },
3536
auto_create: { type: 'boolean', enum: [true, false] },

0 commit comments

Comments
 (0)