Skip to content

Commit

Permalink
next-release
Browse files Browse the repository at this point in the history
next-release
  • Loading branch information
leifermendez committed Oct 1, 2023
2 parents 44307f6 + 26a0b50 commit 843a6c2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/provider/src/meta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 843a6c2

Please sign in to comment.