@areumtecnologia/wasockets 2.3.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -288,22 +288,37 @@ await ctx.unstar();
|
|
|
288
288
|
```
|
|
289
289
|
|
|
290
290
|
#### Utilitários de Mídia (`MediaObject`):
|
|
291
|
-
Se a mensagem contiver imagem, vídeo, áudio ou documento, `ctx.media`
|
|
291
|
+
Se a mensagem contiver imagem, vídeo, áudio, figurinha ou documento, `ctx.media` centraliza todos os metadados e métodos de manipulação em uma única instância:
|
|
292
292
|
|
|
293
|
+
##### Propriedades de `ctx.media`:
|
|
294
|
+
- `ctx.media.mimetype`: Tipo MIME real (ex: `'image/jpeg'`, `'audio/ogg; codecs=opus'`).
|
|
295
|
+
- `ctx.media.extension`: Extensão inferida do arquivo (ex: `'jpg'`, `'ogg'`, `'pdf'`, `'mp4'`).
|
|
296
|
+
- `ctx.media.fileLength`: Tamanho do arquivo em bytes.
|
|
297
|
+
- `ctx.media.fileName`: Nome original do arquivo (se enviado como documento).
|
|
298
|
+
- `ctx.media.caption`: Legenda de texto anexada à mídia.
|
|
299
|
+
- `ctx.media.seconds` / `duration`: Duração em segundos (para áudios e vídeos).
|
|
300
|
+
- `ctx.media.isVoice` / `isPtt`: Booleano se é áudio gravado no WhatsApp (Push-To-Talk).
|
|
301
|
+
- `ctx.media.isGif`: Booleano se é vídeo reproduzido como GIF animado.
|
|
302
|
+
- `ctx.media.isViewOnce`: Booleano se é mídia de visualização única.
|
|
303
|
+
|
|
304
|
+
##### Métodos de `ctx.media`:
|
|
293
305
|
```javascript
|
|
294
306
|
if (ctx.media) {
|
|
295
|
-
// 1. Salva diretamente em disco
|
|
307
|
+
// 1. Salva diretamente em disco (cria diretórios se não existirem)
|
|
296
308
|
await ctx.media.save('./pasta/comprovante.pdf');
|
|
297
309
|
|
|
298
|
-
// 2.
|
|
299
|
-
const
|
|
300
|
-
|
|
310
|
+
// 2. Obtém como Buffer em memória (com cache automático)
|
|
311
|
+
const buffer = await ctx.media.toBuffer();
|
|
312
|
+
|
|
313
|
+
// 3. Converte para Base64 (ideal para LLMs como Gemini / OpenAI)
|
|
314
|
+
const base64 = await ctx.media.toBase64();
|
|
315
|
+
const dataUri = await ctx.media.toDataUri(); // 'data:image/jpeg;base64,...'
|
|
301
316
|
|
|
302
|
-
//
|
|
303
|
-
const stream = ctx.media.toStream();
|
|
317
|
+
// 4. Obtém como Stream legível (Node Readable)
|
|
318
|
+
const stream = await ctx.media.toStream();
|
|
304
319
|
|
|
305
|
-
//
|
|
306
|
-
const sharpInstance = ctx.media.toSharp();
|
|
320
|
+
// 5. Integração nativa com Sharp (se instalado) para recorte/redimensionamento
|
|
321
|
+
const sharpInstance = await ctx.media.toSharp();
|
|
307
322
|
}
|
|
308
323
|
```
|
|
309
324
|
|