K
K
Kir Mozor2021-09-25 18:25:52
Python
Kir Mozor, 2021-09-25 18:25:52

How to click on a button in a telegram bot using Pyrogram?

There is a telegram bot for downloading audio from Spotify (@spotify_down_bot)
I need to download audio from there, for this I send a link to the audio to the bot and after that the bot sends me messages with buttons. To start downloading audio, click on the Download this Song button!
I tried to click on this button using
client.request_callback_answer()
I did it like this

Client.request_callback_answer(chat_id= 1130976121, message_id = message.message_id, callback_data = "d_mp3_slow 1T18xjRxt5m22ZOwMPMRhc")

And nothing happens, most likely an error somewhere in the code. The code itself:

from pyrogram import Client
import config
import time

app = Client("cyberpunk", config.api_id, config.api_hash, config.phone_number)

@app.on_message()
def message(Client, message):
  if message.chat.username == "spotify_down_bot":
      print(message)

      log = open("log", "a")
      log.write(f"\n {message}")
      log.close()

      Client.request_callback_answer(
                   chat_id= 1130976121,
                   message_id = message.message_id,
                   callback_data = "d_mp3_slow 1T18xjRxt5m22ZOwMPMRhc"
      )


See info from message https://pastebin.com/brQxFsxN

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-09-25
@150_Kirill_150

Are there any errors in the console? The code should work, but I would replace callback_data with

message.reply_markup.inline_keyboard[1][0]['callback_data']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question