0

I'm using whatsapp cloud api to build a chatbot, I configured webhook, and when the user sends an audio message I get the payload

{
  from: 'xxxxxxxxxx',
  id: 'wamid.HBgMOTcyNTI2MzY2NjU1FQIAEhgUM0E3QjE0M0MyMTY5QjM0OTNFNzMA',
  timestamp: '1658939005',
  type: 'audio',
  data: {
    mime_type: 'audio/ogg; codecs=opus',
    sha256: 'Lqg2WcBG7RY4NhzouRYGChsiem7BwyvaRKXrjsD/q/o=',
    id: '715960496164079',
    voice: true
  }
}

I'm trying to understand how can I get the URL of the record, and what to do with this data?

I want to build a bot to convert the record to text using API but I'm not sure how this payload helps me.

turivishal
  • 34,368
  • 7
  • 36
  • 59
Manspof
  • 598
  • 26
  • 81
  • 173

1 Answers1

4

If you want to access that media then you have to use get media URL cloud API,

  1. Get the media URL using Retrieve Media URL API
    • pass media id from data.id to MEDIA_ID
    • pass your access token to ACCESS_TOKEN
curl -X GET \
  'https://graph.facebook.com/v13.0/MEDIA_ID' \
  -H 'Authorization: Bearer ACCESS_TOKEN'
  1. You can't access media directly by its URL, you have to pass an access token to access the media, see the Download Media API
    • pass URL returned from above step to URL
    • pass your access token to ACCESS_TOKEN
curl -X GET 'URL' \
 -H 'Authorization: Bearer ACCESS_TOKEN' > media_file
turivishal
  • 34,368
  • 7
  • 36
  • 59
  • here is an example of a video performing this process: https://www.youtube.com/watch?v=vf0ivWEah38 – Mithsew Jan 16 '23 at 16:13