Liebertosan
Liebertosan

Reputation: 45

Telegram Bot Api / Python: Trying to send voice message via my telegram bot

so im playing a little bit around with my telegram bot, now im already able to send normal messages and pictures. But now i want to be able to send pre recorded voice messages as an answer. In the documentation it says to use send_voice for this matter and it recommends using the file_id of a file thats already on the telegram servers. So thats what i did i send a voice message to the @RawDataBot and he returned to me the file_id of the voice message.

Problem is: When i try to trigger it i get the following error: telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified

Any ideas here on what i might be doing wrong? Here is the relevant code:

import telebot

API_KEY = <MY_API_KEY>


bot = telebot.TeleBot(API_KEY)





#start
@bot.message_handler(commands=['start'])
def start (message):
  bot.send_message(message.chat.id,Textstart)


@bot.message_handler(commands=['pic'])
def start (photo):    
  bot.send_photo(photo.chat.id, "https://de.wikipedia.org/wiki/Zeus#/media/Datei:Zeus_Otricoli_Pio-Clementino_Inv257.jpg")

#here is the part where he is supposed to send the voice message if someone types in /audio
@bot.message_handler(commands=['audio'])
def start (voice):
  bot.send_voice(voice.chat.id,"AwACAgIAAxkBAAEWjl5i5bjyudWAM9IISKWhE1Gjs5ntQgACLx8AApcNKEv97pVasPhBoCkE",)




bot.polling()





Upvotes: 2

Views: 2194

Answers (1)

mo1ein
mo1ein

Reputation: 605

There are multiple reasons, but I think it is because of these:
file_id is unique for each individual bot and can't be transferred from one bot to another.
file_id uniquely identifies a file, but a file can have different valid file_ids even for the same bot.
See here.

Upvotes: 3

Related Questions