Skip to content

Commit

Permalink
Merge pull request #992 from jhonlcp1997/main
Browse files Browse the repository at this point in the history
fix: agregado el metodo senFile que faltaba en Meta provider
  • Loading branch information
leifermendez authored Feb 22, 2024
2 parents 0dccfca + c47601c commit ca7c380
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/docs/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default component$(() => {
{
title: 'Comunidad',
list: [
{ name: 'Colabores', link: '/docs/contributing' },
{ name: 'Colaboradores', link: '/docs/contributing' },
{ name: 'Unirme al proyecto', link: '/docs/join' },
],
},
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/src/routes/docs/database/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Los conectores disponibles hasta el momento son los siguientes:

`require('@bot-whatsapp/database/json')`

`require('@bot-whatsapp/database/postgres')`

---

<Navigation
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/src/routes/docs/essential/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Los conectores disponibles hasta el momento son los siguientes:

`require('@bot-whatsapp/database/json')`

`require('@bot-whatsapp/database/postgres')`

---

<Navigation
Expand Down
41 changes: 41 additions & 0 deletions packages/provider/src/meta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { convertAudio } = require('../utils/convertAudio')
const MetaWebHookServer = require('./server')
const URL = `https://graph.facebook.com`
const Queue = require('queue-promise')
const path = require('path')

/**
* ⚙️MetaProvider: Es un provedor que te ofrece enviar
Expand Down Expand Up @@ -180,6 +181,46 @@ class MetaProvider extends ProviderClass {
return this.sendMessageMeta(body)
}

/**
*
* @param {*} number
* @param {*} _
* @param {*} pathDocument
* @returns
*/
sendFile = async (number, pathFile = null) => {
if (!pathFile) throw new Error(`MEDIA_INPUT_NULL_: ${pathFile}`)

const formData = new FormData()
const mimeType = mime.lookup(pathFile)
formData.append('file', createReadStream(pathFile), {
contentType: mimeType,
})
formData.append('messaging_product', 'whatsapp')

const nameOriginal = path.basename(pathFile) || 'Doc'

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: 'document',
document: {
id: mediaId,
filename: nameOriginal,
},
}
return this.sendMessageMeta(body)
}

/**
* @alpha
* @param {string} number
Expand Down

0 comments on commit ca7c380

Please sign in to comment.