Skip to content

Commit 7a24f52

Browse files
committed
feat: added auto_create to the chatwoot set to create the inbox automatically or not
1 parent 324d461 commit 7a24f52

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

src/config/error.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function onUnexpectedError() {
88
stderr: process.stderr.fd,
99
error,
1010
});
11-
// process.exit(1);
1211
});
1312

1413
process.on('unhandledRejection', (error, origin) => {
@@ -18,6 +17,5 @@ export function onUnexpectedError() {
1817
stderr: process.stderr.fd,
1918
error,
2019
});
21-
// process.exit(1);
2220
});
2321
}

src/validate/validate.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ export const chatwootSchema: JSONSchema7 = {
891891
sign_msg: { type: 'boolean', enum: [true, false] },
892892
reopen_conversation: { type: 'boolean', enum: [true, false] },
893893
conversation_pending: { type: 'boolean', enum: [true, false] },
894+
auto_create: { type: 'boolean', enum: [true, false] },
894895
},
895896
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'],
896897
...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'),

src/whatsapp/controllers/chatwoot.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class ChatwootController {
4242
data.sign_msg = false;
4343
data.reopen_conversation = false;
4444
data.conversation_pending = false;
45+
data.auto_create = false;
4546
}
4647

4748
data.name_inbox = instance.instanceName;

src/whatsapp/controllers/instance.controller.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,8 @@ export class InstanceController {
446446
number,
447447
reopen_conversation: chatwoot_reopen_conversation || false,
448448
conversation_pending: chatwoot_conversation_pending || false,
449+
auto_create: true,
449450
});
450-
451-
this.chatwootService.initInstanceChatwoot(
452-
instance,
453-
instance.instanceName.split('-cwId-')[0],
454-
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
455-
qrcode,
456-
number,
457-
);
458451
} catch (error) {
459452
this.logger.log(error);
460453
}

src/whatsapp/dto/chatwoot.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export class ChatwootDto {
88
number?: string;
99
reopen_conversation?: boolean;
1010
conversation_pending?: boolean;
11+
auto_create?: boolean;
1112
}

src/whatsapp/services/chatwoot.service.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Jimp from 'jimp';
66
import mimeTypes from 'mime-types';
77
import path from 'path';
88

9-
import { ConfigService } from '../../config/env.config';
9+
import { ConfigService, HttpServer } from '../../config/env.config';
1010
import { Logger } from '../../config/logger.config';
1111
import { ROOT_DIR } from '../../config/path.config';
1212
import { ChatwootDto } from '../dto/chatwoot.dto';
@@ -99,9 +99,22 @@ export class ChatwootService {
9999

100100
public create(instance: InstanceDto, data: ChatwootDto) {
101101
this.logger.verbose('create chatwoot: ' + instance.instanceName);
102+
102103
this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
103104

104105
this.logger.verbose('chatwoot created');
106+
107+
if (data.auto_create) {
108+
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
109+
110+
this.initInstanceChatwoot(
111+
instance,
112+
instance.instanceName.split('-cwId-')[0],
113+
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
114+
true,
115+
data.number,
116+
);
117+
}
105118
return data;
106119
}
107120

0 commit comments

Comments
 (0)