'How to send message followed by start to a bot by link using telethon?
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.
Solution 1:[1]
You can use @oleskii's approach, but you can also just send a message like so:
client.send_message('bot username', '/start params_string')
Solution 2:[2]
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!
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Lonami |
Solution 2 | oleskii |
Solution 3 | SayeMarg |