I'm making a Telegram bot using python-telegram-bot
, and I need some way to receive voice messages. For that, I need to download them, and to do that, I have to get their file_id
s. However, the MessageHandler
handles... well, messages, and Handler
gives me a NotImplementedError
. Is there a way to get the file_id
?
I know this question is old but I was facing a problem with this in the latest version (12+)
So it appears that the bot- pass_user_data in the callback function is deprecated and from now on you should use context based callbacks.
CallbackContext is an object that contains all the extra context information regarding an Update, error or Job.
to the new style using CallbackContext:
def voice_handler(update: Update, context: CallbackContext):
file = context.bot.getFile(update.message.audio.file_id)
file.download('./voice.ogg')
You can read more in the Transition-guide-to-Version-12.0