fix(whatsapp.gblib): Fixed audio with IBM Watson.
This commit is contained in:
parent
f5a383dd1a
commit
4010fca0cf
1 changed files with 7 additions and 8 deletions
|
@ -1503,9 +1503,8 @@ private async sendButtonList(to: string, buttons: string[]) {
|
||||||
// Extract the audio ID from the request body
|
// Extract the audio ID from the request body
|
||||||
const audioId = req.body.entry[0].changes[0].value.messages[0].audio.id;
|
const audioId = req.body.entry[0].changes[0].value.messages[0].audio.id;
|
||||||
|
|
||||||
// User access token from min.whatsappServiceKey
|
// User access token from min.whatsappServiceKey
|
||||||
const userAccessToken = GBServer.globals.minBoot.instance.whatsappServiceKey;
|
const userAccessToken = GBServer.globals.minBoot.instance.whatsappServiceKey;
|
||||||
|
|
||||||
|
|
||||||
// Meta WhatsApp Business API endpoint for downloading media
|
// Meta WhatsApp Business API endpoint for downloading media
|
||||||
const metaApiUrl = `https://graph.facebook.com/v20.0/${audioId}`;
|
const metaApiUrl = `https://graph.facebook.com/v20.0/${audioId}`;
|
||||||
|
@ -1528,17 +1527,17 @@ private async sendButtonList(to: string, buttons: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the audio file
|
// Download the audio file
|
||||||
const audioResponse = await fetch(mediaUrl, {
|
const res = await fetch(mediaUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${userAccessToken}`,
|
Authorization: `Bearer ${userAccessToken}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!audioResponse.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`Failed to download audio: ${audioResponse.statusText}`);
|
throw new Error(`Failed to download audio: ${res.statusText}`);
|
||||||
}
|
}
|
||||||
|
let buf: any = Buffer.from(await res.arrayBuffer());
|
||||||
return audioResponse.body;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue