I was trying to write a bot that sends voice messages via inline. but selection handler is not working correctly. Also how can I implement reading voice messages from local directory. thx
import telebot
bot_token = 'token'
bot = telebot.TeleBot(bot_token)
@bot.inline_handler(lambda query: len(query.query) > 0)
def handle_inline_query(query):
try:
results = []
result = telebot.types.InlineQueryResultVoice(
id='1',
voice_url='url',
title='войс',
voice_duration=10
)
results.append(result)
bot.answer_inline_query(query.id, results)
except Exception as e:
print(e)
@bot.chosen_inline_handler(func=lambda chosen_inline_result: True)
def send_voice_message(chosen_inline_result):
try:
print('jjh')
if chosen_inline_result.result_id == '1':
voice_url = 'url'
bot.send_voice(chosen_inline_result.from_user.id, voice_url)
except Exception as e:
print(e)
bot.polling()