@@ -1247,6 +1247,74 @@ export class WAStartupService {
12471247 }
12481248 }
12491249
1250+ public async reloadConnection ( ) : Promise < WASocket > {
1251+ try {
1252+ this . instance . authState = await this . defineAuthState ( ) ;
1253+
1254+ const { version } = await fetchLatestBaileysVersion ( ) ;
1255+ const session = this . configService . get < ConfigSessionPhone > ( 'CONFIG_SESSION_PHONE' ) ;
1256+ const browser : WABrowserDescription = [ session . CLIENT , session . NAME , release ( ) ] ;
1257+
1258+ let options ;
1259+
1260+ if ( this . localProxy . enabled ) {
1261+ this . logger . verbose ( 'Proxy enabled' ) ;
1262+ options = {
1263+ agent : new ProxyAgent ( this . localProxy . proxy as any ) ,
1264+ fetchAgent : new ProxyAgent ( this . localProxy . proxy as any ) ,
1265+ } ;
1266+ }
1267+
1268+ const socketConfig : UserFacingSocketConfig = {
1269+ ...options ,
1270+ auth : {
1271+ creds : this . instance . authState . state . creds ,
1272+ keys : makeCacheableSignalKeyStore ( this . instance . authState . state . keys , P ( { level : 'error' } ) ) ,
1273+ } ,
1274+ logger : P ( { level : this . logBaileys } ) ,
1275+ printQRInTerminal : false ,
1276+ browser,
1277+ version,
1278+ markOnlineOnConnect : this . localSettings . always_online ,
1279+ connectTimeoutMs : 60_000 ,
1280+ qrTimeout : 40_000 ,
1281+ defaultQueryTimeoutMs : undefined ,
1282+ emitOwnEvents : false ,
1283+ msgRetryCounterCache : this . msgRetryCounterCache ,
1284+ getMessage : async ( key ) => ( await this . getMessage ( key ) ) as Promise < proto . IMessage > ,
1285+ generateHighQualityLinkPreview : true ,
1286+ syncFullHistory : true ,
1287+ userDevicesCache : this . userDevicesCache ,
1288+ transactionOpts : { maxCommitRetries : 1 , delayBetweenTriesMs : 10 } ,
1289+ patchMessageBeforeSending : ( message ) => {
1290+ const requiresPatch = ! ! ( message . buttonsMessage || message . listMessage || message . templateMessage ) ;
1291+ if ( requiresPatch ) {
1292+ message = {
1293+ viewOnceMessageV2 : {
1294+ message : {
1295+ messageContextInfo : {
1296+ deviceListMetadataVersion : 2 ,
1297+ deviceListMetadata : { } ,
1298+ } ,
1299+ ...message ,
1300+ } ,
1301+ } ,
1302+ } ;
1303+ }
1304+
1305+ return message ;
1306+ } ,
1307+ } ;
1308+
1309+ this . client = makeWASocket ( socketConfig ) ;
1310+
1311+ return this . client ;
1312+ } catch ( error ) {
1313+ this . logger . error ( error ) ;
1314+ throw new InternalServerErrorException ( error ?. toString ( ) ) ;
1315+ }
1316+ }
1317+
12501318 private readonly chatHandle = {
12511319 'chats.upsert' : async ( chats : Chat [ ] , database : Database ) => {
12521320 this . logger . verbose ( 'Event received: chats.upsert' ) ;
0 commit comments