I am working with the Telegram Bot API and utilizing its sendVoice
method to send voice messages. Telegram Bot API supports GET and POST requests and allows specifying content types such as application/json
and multipart/form-data
. When using multipart/form-data
, we can specify voice bytes and also include key-value parameters.
Specifically, I have a question regarding the usage of the reply_parameters
parameter within multipart/form-data
. In the sendVoice
method, the reply_parameters
parameter is expected to be an object that specifies which message the voice message is replying to.
My question is: How can I correctly format and send a reply_parameters
parameter containing an object using multipart/form-data
given that the reply
parameter is not a primitive data type? I have been unable to find relevant documentation
you haven't mentioned any particular language you're working with. So, let's take it to basics and use cURL to send the voice.
curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/sendVoice" \
-F "chat_id=1726826785" \
-F "reply_parameters={\"message_id\":<MESSAGE_ID>}" \
-F "voice=@<FILE_NAME>;type=audio/mp3"
Make sure to replace:
Here's an example usage:
curl -X POST "https://api.telegram.org/botBOT_TOKEN/sendVoice" \
-F "chat_id=123456" \
-F "reply_parameters={\"message_id\":8313}" \
-F "voice=@audio.mp3;type=audio/mp3"
Key thing to remember is, reply_parameters
must be a JSON encoded String. The message_id
field is required, please refer to the official documentation to find other supported fields.
You can use cURL converter to convert the curl command to actual code, here's an example one.
Or if you mention the language/package you're using, I can try to adjust the code to match your preference.
Hope this helps!