@@ -85,6 +85,7 @@ import {
8585 ArchiveChatDto ,
8686 DeleteMessage ,
8787 OnWhatsAppDto ,
88+ NumberBusiness ,
8889 PrivacySettingDto ,
8990 ReadMessageDto ,
9091 WhatsAppNumberDto ,
@@ -1437,23 +1438,66 @@ export class WAStartupService {
14371438 }
14381439 }
14391440
1440- public async profile ( instanceName : string ) {
1441- const jid = this . client ?. user ?. id ;
1442-
1441+ public async getStatus ( number : string ) {
1442+ const jid = this . createJid ( number ) ;
1443+
1444+ this . logger . verbose ( 'Getting profile status with jid:' + jid ) ;
1445+ try {
1446+ this . logger . verbose ( 'Getting status' ) ;
1447+ return {
1448+ wuid : jid ,
1449+ status : ( await this . client . fetchStatus ( jid ) ) ?. status ,
1450+ } ;
1451+ } catch ( error ) {
1452+ this . logger . verbose ( 'Status not found' ) ;
1453+ return {
1454+ wuid : jid ,
1455+ status : null ,
1456+ } ;
1457+ }
1458+ }
1459+
1460+ public async fetchProfile ( instanceName : string , number ?: string ) {
1461+ const jid = ( number )
1462+ ? this . createJid ( number )
1463+ : this . client ?. user ?. id ;
14431464 this . logger . verbose ( 'Getting profile with jid: ' + jid ) ;
14441465 try {
14451466 this . logger . verbose ( 'Getting profile info' ) ;
1446- const info = await waMonitor . instanceInfo ( instanceName ) ;
14471467 const business = await this . fetchBusinessProfile ( jid ) ;
14481468
1449- return {
1450- wuid : jid ,
1451- name : info ?. instance ?. profileName ,
1452- picture : info ?. instance ?. profilePictureUrl ,
1453- status : info ?. instance ?. profileStatus ,
1454- os : this . client ?. authState ?. creds ?. platform ,
1455- isBusiness : typeof business !== 'undefined' ,
1456- } ;
1469+ if ( number ) {
1470+ const info = ( await this . whatsappNumber ( { numbers : [ jid ] } ) ) ?. shift ( ) ;
1471+ const picture = await this . profilePicture ( jid ) ;
1472+ const status = await this . getStatus ( jid ) ;
1473+
1474+ return {
1475+ wuid : jid ,
1476+ name : info ?. name ,
1477+ numberExists : info ?. exists ,
1478+ picture : picture ?. profilePictureUrl ,
1479+ status : status ?. status ,
1480+ isBusiness : business . isBusiness ,
1481+ email : business ?. email ,
1482+ description : business ?. description ,
1483+ website : business ?. website ?. shift ( ) ,
1484+ } ;
1485+ } else {
1486+ const info = await waMonitor . instanceInfo ( instanceName ) ;
1487+
1488+ return {
1489+ wuid : jid ,
1490+ name : info ?. instance ?. profileName ,
1491+ numberExists : true ,
1492+ picture : info ?. instance ?. profilePictureUrl ,
1493+ status : info ?. instance ?. profileStatus ,
1494+ isBusiness : business . isBusiness ,
1495+ email : business ?. email ,
1496+ description : business ?. description ,
1497+ website : business ?. website ?. shift ( ) ,
1498+ } ;
1499+ }
1500+
14571501 } catch ( error ) {
14581502 this . logger . verbose ( 'Profile not found' ) ;
14591503 return {
@@ -2463,29 +2507,31 @@ export class WAStartupService {
24632507 }
24642508 }
24652509
2466- public async fetchBusinessProfile ( number : string ) {
2510+ public async fetchBusinessProfile ( number : string ) : Promise < NumberBusiness > {
24672511 this . logger . verbose ( 'Fetching business profile' ) ;
24682512 try {
2469- let jid ;
2470-
2471- if ( ! number ) {
2472- jid = this . instance . wuid ;
2473- } else {
2474- jid = this . createJid ( number ) ;
2475- }
2513+ const jid = ( number )
2514+ ? this . createJid ( number )
2515+ : this . instance . wuid ;
24762516
24772517 const profile = await this . client . getBusinessProfile ( jid ) ;
24782518 this . logger . verbose ( 'Trying to get business profile' ) ;
24792519
24802520 if ( ! profile ) {
2521+ const info = await this . whatsappNumber ( { numbers : [ jid ] } ) ;
2522+
24812523 return {
2482- exists : false ,
2483- message : 'Business profile not found' ,
2524+ isBusiness : false ,
2525+ message : 'Not is business profile' ,
2526+ ...info ?. shift ( )
24842527 } ;
24852528 }
24862529
24872530 this . logger . verbose ( 'Business profile fetched' ) ;
2488- return profile ;
2531+ return {
2532+ isBusiness : true ,
2533+ ...profile
2534+ } ;
24892535 } catch ( error ) {
24902536 throw new InternalServerErrorException (
24912537 'Error updating profile name' ,
0 commit comments