From 7b5f8fd9577ffb26feeaa670a5bfca84281b20e8 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Sun, 1 Oct 2023 21:16:16 +0200 Subject: [PATCH] feat: meta add fileUrl image --- packages/provider/src/meta/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/provider/src/meta/index.js b/packages/provider/src/meta/index.js index f01c11d25..78356f136 100644 --- a/packages/provider/src/meta/index.js +++ b/packages/provider/src/meta/index.js @@ -97,12 +97,29 @@ class MetaProvider extends ProviderClass { sendImage = async (number, mediaInput = null) => { if (!mediaInput) throw new Error(`MEDIA_INPUT_NULL_: ${mediaInput}`) + + const formData = new FormData() + const mimeType = mime.lookup(mediaInput) + formData.append('file', createReadStream(mediaInput), { + contentType: mimeType, + }) + formData.append('messaging_product', 'whatsapp') + + const { + data: { id: mediaId }, + } = await axios.post(`${URL}/${this.version}/${this.numberId}/media`, formData, { + headers: { + Authorization: `Bearer ${this.jwtToken}`, + ...formData.getHeaders(), + }, + }) + const body = { messaging_product: 'whatsapp', to: number, type: 'image', image: { - link: mediaInput, + id: mediaId, }, } return this.sendMessageMeta(body)