@@ -7,6 +7,9 @@ import { join } from 'path';
7
7
import { Auth , ConfigService , Database , DelInstance , HttpServer , Redis } from '../../config/env.config' ;
8
8
import { Logger } from '../../config/logger.config' ;
9
9
import { INSTANCE_DIR , STORE_DIR } from '../../config/path.config' ;
10
+ // inserido por francis inicio
11
+ import { NotFoundException } from '../../exceptions' ;
12
+ // inserido por francis fim
10
13
import { dbserver } from '../../libs/db.connect' ;
11
14
import { RedisCache } from '../../libs/redis.client' ;
12
15
import {
@@ -72,7 +75,7 @@ export class WAMonitoringService {
72
75
} , 1000 * 60 * time ) ;
73
76
}
74
77
}
75
-
78
+ /* ocultado por francis inicio
76
79
public async instanceInfo(instanceName?: string) {
77
80
this.logger.verbose('get instance info');
78
81
@@ -128,6 +131,96 @@ export class WAMonitoringService {
128
131
return instances;
129
132
}
130
133
134
+ ocultado por francis fim */
135
+
136
+ // inserido por francis inicio
137
+
138
+ public async instanceInfo ( instanceName ?: string ) {
139
+ this . logger . verbose ( 'get instance info' ) ;
140
+ if ( instanceName && ! this . waInstances [ instanceName ] ) {
141
+ throw new NotFoundException ( `Instance "${ instanceName } " not found` ) ;
142
+ }
143
+
144
+ const instances : any [ ] = [ ] ;
145
+
146
+ for await ( const [ key , value ] of Object . entries ( this . waInstances ) ) {
147
+ if ( value ) {
148
+ this . logger . verbose ( 'get instance info: ' + key ) ;
149
+ let chatwoot : any ;
150
+
151
+ const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
152
+
153
+ const findChatwoot = await this . waInstances [ key ] . findChatwoot ( ) ;
154
+
155
+ if ( findChatwoot && findChatwoot . enabled ) {
156
+ chatwoot = {
157
+ ...findChatwoot ,
158
+ webhook_url : `${ urlServer } /chatwoot/webhook/${ encodeURIComponent ( key ) } ` ,
159
+ } ;
160
+ }
161
+
162
+ if ( value . connectionStatus . state === 'open' ) {
163
+ this . logger . verbose ( 'instance: ' + key + ' - connectionStatus: open' ) ;
164
+
165
+ const instanceData = {
166
+ instance : {
167
+ instanceName : key ,
168
+ owner : value . wuid ,
169
+ profileName : ( await value . getProfileName ( ) ) || 'not loaded' ,
170
+ profilePictureUrl : value . profilePictureUrl ,
171
+ profileStatus : ( await value . getProfileStatus ( ) ) || '' ,
172
+ status : value . connectionStatus . state ,
173
+ } ,
174
+ } ;
175
+
176
+ if ( this . configService . get < Auth > ( 'AUTHENTICATION' ) . EXPOSE_IN_FETCH_INSTANCES ) {
177
+ instanceData . instance [ 'serverUrl' ] = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
178
+
179
+ instanceData . instance [ 'apikey' ] = ( await this . repository . auth . find ( key ) ) . apikey ;
180
+
181
+ instanceData . instance [ 'chatwoot' ] = chatwoot ;
182
+ }
183
+
184
+ instances . push ( instanceData ) ;
185
+ } else {
186
+ this . logger . verbose ( 'instance: ' + key + ' - connectionStatus: ' + value . connectionStatus . state ) ;
187
+
188
+ const instanceData = {
189
+ instance : {
190
+ instanceName : key ,
191
+ status : value . connectionStatus . state ,
192
+ } ,
193
+ } ;
194
+
195
+ if ( this . configService . get < Auth > ( 'AUTHENTICATION' ) . EXPOSE_IN_FETCH_INSTANCES ) {
196
+ instanceData . instance [ 'serverUrl' ] = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
197
+
198
+ instanceData . instance [ 'apikey' ] = ( await this . repository . auth . find ( key ) ) . apikey ;
199
+
200
+ instanceData . instance [ 'chatwoot' ] = chatwoot ;
201
+ }
202
+
203
+ instances . push ( instanceData ) ;
204
+ }
205
+ }
206
+ }
207
+
208
+ this . logger . verbose ( 'return instance info: ' + instances . length ) ;
209
+
210
+ return instances . find ( ( i ) => i . instance . instanceName === instanceName ) ?? instances ;
211
+ }
212
+
213
+
214
+
215
+ // inserido por francis fim
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
131
224
private delInstanceFiles ( ) {
132
225
this . logger . verbose ( 'cron to delete instance files started' ) ;
133
226
setInterval ( async ( ) => {
0 commit comments