@@ -79,30 +79,30 @@ export class InstanceController {
7979
8080 this . logger . verbose ( 'hash: ' + hash + ' generated' ) ;
8181
82+ let getEvents : string [ ] ;
83+
84+ if ( webhook ) {
85+ this . logger . verbose ( 'creating webhook' ) ;
86+ try {
87+ this . webhookService . create ( instance , {
88+ enabled : true ,
89+ url : webhook ,
90+ events,
91+ webhook_by_events,
92+ } ) ;
93+
94+ getEvents = ( await this . webhookService . find ( instance ) ) . events ;
95+ } catch ( error ) {
96+ this . logger . log ( error ) ;
97+ }
98+ }
99+
82100 if (
83101 ! chatwoot_account_id ||
84102 ! chatwoot_token ||
85103 ! chatwoot_url ||
86104 ! chatwoot_sign_msg
87105 ) {
88- let getEvents : string [ ] ;
89-
90- if ( webhook ) {
91- this . logger . verbose ( 'creating webhook' ) ;
92- try {
93- this . webhookService . create ( instance , {
94- enabled : true ,
95- url : webhook ,
96- events,
97- webhook_by_events,
98- } ) ;
99-
100- getEvents = ( await this . webhookService . find ( instance ) ) . events ;
101- } catch ( error ) {
102- this . logger . log ( error ) ;
103- }
104- }
105-
106106 this . logger . verbose ( 'instance created' ) ;
107107 this . logger . verbose ( {
108108 instance : {
@@ -141,6 +141,8 @@ export class InstanceController {
141141 throw new BadRequestException ( 'sign_msg is required' ) ;
142142 }
143143
144+ const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
145+
144146 try {
145147 this . chatwootService . create ( instance , {
146148 enabled : true ,
@@ -150,12 +152,17 @@ export class InstanceController {
150152 sign_msg : chatwoot_sign_msg ,
151153 name_inbox : instance . instanceName ,
152154 } ) ;
155+
156+ this . chatwootService . initInstanceChatwoot (
157+ instance ,
158+ instance . instanceName ,
159+ `${ urlServer } /chatwoot/webhook/${ instance . instanceName } ` ,
160+ qrcode ,
161+ ) ;
153162 } catch ( error ) {
154163 this . logger . log ( error ) ;
155164 }
156165
157- const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
158-
159166 return {
160167 instance : {
161168 instanceName : instance . instanceName ,
@@ -202,30 +209,30 @@ export class InstanceController {
202209
203210 this . logger . verbose ( 'hash: ' + hash + ' generated' ) ;
204211
212+ let getEvents : string [ ] ;
213+
214+ if ( webhook ) {
215+ this . logger . verbose ( 'creating webhook' ) ;
216+ try {
217+ this . webhookService . create ( instance , {
218+ enabled : true ,
219+ url : webhook ,
220+ events,
221+ webhook_by_events,
222+ } ) ;
223+
224+ getEvents = ( await this . webhookService . find ( instance ) ) . events ;
225+ } catch ( error ) {
226+ this . logger . log ( error ) ;
227+ }
228+ }
229+
205230 if (
206231 ! chatwoot_account_id ||
207232 ! chatwoot_token ||
208233 ! chatwoot_url ||
209234 ! chatwoot_sign_msg
210235 ) {
211- let getEvents : string [ ] ;
212-
213- if ( webhook ) {
214- this . logger . verbose ( 'creating webhook' ) ;
215- try {
216- this . webhookService . create ( instance , {
217- enabled : true ,
218- url : webhook ,
219- events,
220- webhook_by_events,
221- } ) ;
222-
223- getEvents = ( await this . webhookService . find ( instance ) ) . events ;
224- } catch ( error ) {
225- this . logger . log ( error ) ;
226- }
227- }
228-
229236 let getQrcode : wa . QrCode ;
230237
231238 if ( qrcode ) {
@@ -277,6 +284,8 @@ export class InstanceController {
277284 throw new BadRequestException ( 'sign_msg is required' ) ;
278285 }
279286
287+ const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
288+
280289 try {
281290 this . chatwootService . create ( instance , {
282291 enabled : true ,
@@ -286,18 +295,26 @@ export class InstanceController {
286295 sign_msg : chatwoot_sign_msg ,
287296 name_inbox : instance . instanceName ,
288297 } ) ;
298+
299+ this . chatwootService . initInstanceChatwoot (
300+ instance ,
301+ instance . instanceName ,
302+ `${ urlServer } /chatwoot/webhook/${ instance . instanceName } ` ,
303+ qrcode ,
304+ ) ;
289305 } catch ( error ) {
290306 this . logger . log ( error ) ;
291307 }
292308
293- const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
294-
295309 return {
296310 instance : {
297311 instanceName : instance . instanceName ,
298312 status : 'created' ,
299313 } ,
300314 hash,
315+ webhook,
316+ webhook_by_events,
317+ events : getEvents ,
301318 chatwoot : {
302319 enabled : true ,
303320 account_id : chatwoot_account_id ,
0 commit comments