@@ -13,7 +13,6 @@ import { SendAudioDto } from '../dto/sendMessage.dto';
1313import { SendMediaDto } from '../dto/sendMessage.dto' ;
1414import { ROOT_DIR } from '../../config/path.config' ;
1515import { ConfigService , HttpServer } from '../../config/env.config' ;
16- import { delay } from '@whiskeysockets/baileys' ;
1716
1817export class ChatwootService {
1918 private messageCacheFile : string ;
@@ -1017,7 +1016,7 @@ export class ChatwootService {
10171016 await waInstance ?. client ?. ws ?. close ( ) ;
10181017 }
10191018
1020- if ( command . includes ( '#inbox_whatsapp ' ) ) {
1019+ if ( command . includes ( 'new_instance ' ) ) {
10211020 const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
10221021 const apiKey = this . configService . get ( 'AUTHENTICATION' ) . API_KEY . KEY ;
10231022
@@ -1030,6 +1029,10 @@ export class ChatwootService {
10301029 chatwoot_sign_msg : this . provider . sign_msg ,
10311030 } ;
10321031
1032+ if ( command . split ( ':' ) [ 2 ] ) {
1033+ data [ 'number' ] = command . split ( ':' ) [ 2 ] ;
1034+ }
1035+
10331036 const config = {
10341037 method : 'post' ,
10351038 maxBodyLength : Infinity ,
@@ -1585,4 +1588,53 @@ export class ChatwootService {
15851588 this . logger . error ( error ) ;
15861589 }
15871590 }
1591+
1592+ public async newInstance ( data : any ) {
1593+ try {
1594+ const instanceName = data . instanceName ;
1595+ const qrcode = true ;
1596+ const number = data . number ;
1597+ const accountId = data . accountId ;
1598+ const chatwootToken = data . token ;
1599+ const chatwootUrl = data . url ;
1600+ const signMsg = true ;
1601+ const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
1602+ const apiKey = this . configService . get ( 'AUTHENTICATION' ) . API_KEY . KEY ;
1603+
1604+ console . log ( 'data: ' , data ) ;
1605+
1606+ const requestData = {
1607+ instanceName,
1608+ qrcode,
1609+ chatwoot_account_id : accountId ,
1610+ chatwoot_token : chatwootToken ,
1611+ chatwoot_url : chatwootUrl ,
1612+ chatwoot_sign_msg : signMsg ,
1613+ } ;
1614+
1615+ if ( number ) {
1616+ requestData [ 'number' ] = number ;
1617+ }
1618+
1619+ console . log ( 'requestData: ' , requestData ) ;
1620+
1621+ const config = {
1622+ method : 'post' ,
1623+ maxBodyLength : Infinity ,
1624+ url : `${ urlServer } /instance/create` ,
1625+ headers : {
1626+ 'Content-Type' : 'application/json' ,
1627+ apikey : apiKey ,
1628+ } ,
1629+ data : requestData ,
1630+ } ;
1631+
1632+ // await axios.request(config);
1633+
1634+ return true ;
1635+ } catch ( error ) {
1636+ this . logger . error ( error ) ;
1637+ return null ;
1638+ }
1639+ }
15881640}
0 commit comments