@@ -85,6 +85,7 @@ import {
8585 ArchiveChatDto ,
8686 DeleteMessage ,
8787 OnWhatsAppDto ,
88+ NumberBusiness ,
8889 PrivacySettingDto ,
8990 ReadMessageDto ,
9091 WhatsAppNumberDto ,
@@ -1443,6 +1444,79 @@ export class WAStartupService {
14431444 } ;
14441445 }
14451446 }
1447+
1448+ public async getStatus ( number : string ) {
1449+ const jid = this . createJid ( number ) ;
1450+
1451+ this . logger . verbose ( 'Getting profile status with jid:' + jid ) ;
1452+ try {
1453+ this . logger . verbose ( 'Getting status' ) ;
1454+ return {
1455+ wuid : jid ,
1456+ status : ( await this . client . fetchStatus ( jid ) ) ?. status ,
1457+ } ;
1458+ } catch ( error ) {
1459+ this . logger . verbose ( 'Status not found' ) ;
1460+ return {
1461+ wuid : jid ,
1462+ status : null ,
1463+ } ;
1464+ }
1465+ }
1466+
1467+ public async fetchProfile ( instanceName : string , number ?: string ) {
1468+ const jid = ( number )
1469+ ? this . createJid ( number )
1470+ : this . client ?. user ?. id ;
1471+ this . logger . verbose ( 'Getting profile with jid: ' + jid ) ;
1472+ try {
1473+ this . logger . verbose ( 'Getting profile info' ) ;
1474+ const business = await this . fetchBusinessProfile ( jid ) ;
1475+
1476+ if ( number ) {
1477+ const info = ( await this . whatsappNumber ( { numbers : [ jid ] } ) ) ?. shift ( ) ;
1478+ const picture = await this . profilePicture ( jid ) ;
1479+ const status = await this . getStatus ( jid ) ;
1480+
1481+ return {
1482+ wuid : jid ,
1483+ name : info ?. name ,
1484+ numberExists : info ?. exists ,
1485+ picture : picture ?. profilePictureUrl ,
1486+ status : status ?. status ,
1487+ isBusiness : business . isBusiness ,
1488+ email : business ?. email ,
1489+ description : business ?. description ,
1490+ website : business ?. website ?. shift ( ) ,
1491+ } ;
1492+ } else {
1493+ const info = await waMonitor . instanceInfo ( instanceName ) ;
1494+
1495+ return {
1496+ wuid : jid ,
1497+ name : info ?. instance ?. profileName ,
1498+ numberExists : true ,
1499+ picture : info ?. instance ?. profilePictureUrl ,
1500+ status : info ?. instance ?. profileStatus ,
1501+ isBusiness : business . isBusiness ,
1502+ email : business ?. email ,
1503+ description : business ?. description ,
1504+ website : business ?. website ?. shift ( ) ,
1505+ } ;
1506+ }
1507+
1508+ } catch ( error ) {
1509+ this . logger . verbose ( 'Profile not found' ) ;
1510+ return {
1511+ wuid : jid ,
1512+ name : null ,
1513+ picture : null ,
1514+ status : null ,
1515+ os : null ,
1516+ isBusiness : false ,
1517+ } ;
1518+ }
1519+ }
14461520
14471521 private async sendMessageWithTyping < T = proto . IMessage > (
14481522 number : string ,
@@ -2460,29 +2534,31 @@ export class WAStartupService {
24602534 }
24612535 }
24622536
2463- public async fetchBusinessProfile ( number : string ) {
2537+ public async fetchBusinessProfile ( number : string ) : Promise < NumberBusiness > {
24642538 this . logger . verbose ( 'Fetching business profile' ) ;
24652539 try {
2466- let jid ;
2467-
2468- if ( ! number ) {
2469- jid = this . instance . wuid ;
2470- } else {
2471- jid = this . createJid ( number ) ;
2472- }
2540+ const jid = ( number )
2541+ ? this . createJid ( number )
2542+ : this . instance . wuid ;
24732543
24742544 const profile = await this . client . getBusinessProfile ( jid ) ;
24752545 this . logger . verbose ( 'Trying to get business profile' ) ;
24762546
24772547 if ( ! profile ) {
2548+ const info = await this . whatsappNumber ( { numbers : [ jid ] } ) ;
2549+
24782550 return {
2479- exists : false ,
2480- message : 'Business profile not found' ,
2551+ isBusiness : false ,
2552+ message : 'Not is business profile' ,
2553+ ...info ?. shift ( )
24812554 } ;
24822555 }
24832556
24842557 this . logger . verbose ( 'Business profile fetched' ) ;
2485- return profile ;
2558+ return {
2559+ isBusiness : true ,
2560+ ...profile
2561+ } ;
24862562 } catch ( error ) {
24872563 throw new InternalServerErrorException (
24882564 'Error updating profile name' ,
0 commit comments