Reputation: 343
I want to interact with a bot which takes chat id and message id and replies based on the message of that chat id.
Usually I interact with the bot in a group chat using KeyboardButtonUrl
having link (e.g. here is that url behind KeyboardButtonUrl, https://t.me/SomeBot?start=-1001234567890_654321
) to the bot with data. I click on the button which directly opens the chat with bot & clicking on Start button, sends the command to the bot (I think bot fetches the message from the passed data having chat id and message id) .
Sending message '-1001234567890_654321' using send_message
function doesn't work as expected.
How can I achieve this using telethon ?
Also After searching in telethon docs, I could not find any function which returns a particular message after taking message id and chat id. get_messages
& iter_messages
returns specified no. of last msgs only.
Upvotes: 1
Views: 6264
Reputation: 41
I could not find any function which returns a particular message after taking message id and chat id
client get_messages
method gives an ids
argument that specify message id or list of ids.
message = await client.get_messages(chat_id, ids=message_id)
return message object if given id exists or return None
ids = [message_id_1, message_id_2, message_id_3, ...]
messages = await client.get_messages(chat_id, ids=ids)
return total list of message objects with given id list. list item will be None
if id does not exists.
see the get_messages documentation here
Upvotes: 0
Reputation: 7141
You can use @oleskii's approach, but you can also just send a message like so:
client.send_message('bot username', '/start params_string')
Upvotes: 2
Reputation: 366
it looks like you want to start a bot with parameters.
Please refer to the following: https://tl.telethon.dev/methods/messages/start_bot.html
You can make it work tunning this example to your needs:
from telethon.tl.functions.messages import StartBotRequest
request = StartBotRequest("bot_username_bot", "bot_username_bot", "params_string")
result = await client(request)
The request will work the same way like the following link would work:
https://t.me/bot_username_bot?start=params_string
Hope that helps! Good luck!
Upvotes: 2