First, put the script to a common location e.g. /usr/local/bin/vm-post.py
Then, point your Asterisk mail command to this script to invoke it when a voice mail is received.
For example, in FreePBX:

The script will decode the text message (as configured from Asterisk) and the voice message (stored with wav encoding).
Since Telegram only accepts the .ogg
format as voice message, the script also performs wav -> ogg
conversion with ffmpeg
.
Finally, change the telegram bot token and chat id in the tg_post_voicemail()
function.
To test, dial an extension with voicemail enabled and leave a voice message. You should be able to receive it from your telegram chat window.
If it doesn't work for you, you can inspect the log from /tmp/vm_bot.log
.
The script tries to keep things simple and avoids introducing the telegram bot python package.
The problem is that you are sending a message in a format that Telegram does not support.
Comment out the
parse_mode
parameter in thetg_post_voicemail()
functionor send the text in the correct format.
Or use my variant: