@@ -83,6 +83,7 @@ import {
8383 SendTextDto ,
8484 SendPollDto ,
8585 SendLinkPreviewDto ,
86+ SendStickerDto ,
8687} from '../dto/sendMessage.dto' ;
8788import { arrayUnique , isBase64 , isURL } from 'class-validator' ;
8889import {
@@ -118,6 +119,8 @@ import { WebhookRaw } from '../models/webhook.model';
118119import { dbserver } from '../../db/db.connect' ;
119120import NodeCache from 'node-cache' ;
120121import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db' ;
122+ import { promisify } from 'util' ;
123+ import sharp from 'sharp' ;
121124
122125export class WAStartupService {
123126 constructor (
@@ -783,7 +786,6 @@ export class WAStartupService {
783786 } ,
784787
785788 'messages.update' : async ( args : WAMessageUpdate [ ] , database : Database ) => {
786- console . log ( 'messages.update args: ' , args ) ;
787789 const status : Record < number , wa . StatusMessage > = {
788790 0 : 'ERROR' ,
789791 1 : 'PENDING' ,
@@ -1050,7 +1052,12 @@ export class WAStartupService {
10501052 quoted,
10511053 } ;
10521054
1053- if ( ! message [ 'audio' ] && ! message [ 'poll' ] && ! message [ 'linkPreview' ] ) {
1055+ if (
1056+ ! message [ 'audio' ] &&
1057+ ! message [ 'poll' ] &&
1058+ ! message [ 'linkPreview' ] &&
1059+ ! message [ 'sticker' ]
1060+ ) {
10541061 if ( ! message [ 'audio' ] ) {
10551062 return await this . client . sendMessage (
10561063 sender ,
@@ -1195,6 +1202,41 @@ export class WAStartupService {
11951202 }
11961203 }
11971204
1205+ private async convertToWebP ( image : string ) {
1206+ try {
1207+ let imagePath : string ;
1208+ const outputPath = `${ join ( process . cwd ( ) , 'temp' , 'sticker.webp' ) } ` ;
1209+
1210+ if ( isBase64 ( image ) ) {
1211+ const base64Data = image . replace ( / ^ d a t a : i m a g e \/ ( j p e g | p n g | g i f ) ; b a s e 6 4 , / , '' ) ;
1212+ const imageBuffer = Buffer . from ( base64Data , 'base64' ) ;
1213+ imagePath = `${ join ( process . cwd ( ) , 'temp' , 'temp-sticker.png' ) } ` ;
1214+ await sharp ( imageBuffer ) . toFile ( imagePath ) ;
1215+ } else {
1216+ const response = await axios . get ( image , { responseType : 'arraybuffer' } ) ;
1217+ const imageBuffer = Buffer . from ( response . data , 'binary' ) ;
1218+ imagePath = `${ join ( process . cwd ( ) , 'temp' , 'temp-sticker.png' ) } ` ;
1219+ await sharp ( imageBuffer ) . toFile ( imagePath ) ;
1220+ }
1221+ await sharp ( imagePath ) . webp ( ) . toFile ( outputPath ) ;
1222+
1223+ return outputPath ;
1224+ } catch ( error ) {
1225+ console . error ( 'Erro ao converter a imagem para WebP:' , error ) ;
1226+ }
1227+ }
1228+
1229+ public async mediaSticker ( data : SendStickerDto ) {
1230+ const convert = await this . convertToWebP ( data . stickerMessage . image ) ;
1231+ return await this . sendMessageWithTyping (
1232+ data . number ,
1233+ {
1234+ sticker : { url : convert } ,
1235+ } ,
1236+ data ?. options ,
1237+ ) ;
1238+ }
1239+
11981240 public async mediaMessage ( data : SendMediaDto ) {
11991241 const generate = await this . prepareMediaMessage ( data . mediaMessage ) ;
12001242
0 commit comments