Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link in telegram bot so the user can call a bot command

Tags:

bots

telegram

I'm writing a telegram bot but I have a question. For now my bot will search for an image based on user request, but if I the bat found more than one image I want to send to the user a list of image with a link for search that iamge. Eg.

/command mickey mouse .... image 1.... I found more than one image, please be more specific [link to image 2] [link to image 3]

If the user will click the link I need to autosend message with the command and the name of the new image.

Is possible? I tried to add an hyperlink to the telegram api but i will open in the browser and send me a json with call status of the api.

like image 606
Davide Martelli Avatar asked Sep 20 '17 10:09

Davide Martelli


People also ask

Can a telegram bot talk to another bot?

Bots talking to each other could potentially get stuck in unwelcome loops. To avoid this, we decided that bots will not be able to see messages from other bots regardless of mode.

How can I call a telegram bot?

If inline queries are enabled, users can call your bot by typing its username and a query in the text input field in any chat. The query is sent to your bot in an update. This way, people can request content from your bot in any of their chats, groups, or channels without sending any messages at all.

Can Telegram BOT call a user?

As I know, a bot can't call a telegram user.


1 Answers

For inline mode you can simply return a list of image results that will be displayed as kind of a popup on top of keyboard.

For conversation mode you have options:

1) Return images as inline keyboard attachment to a message with array of buttons each having callback_data parameter or switch_inline_query_current_chat or url parameter. Handle one of this to display the image.

2) Return message text as HTML with list of links in form of: <a href="https://t.me/YOUR_BOT?start=image-123456789">image name</a>

Then you can parse the start command and extract image ID. This has disadvantage that user would need to click the "START" button every time after he clicked the link.

You can use the 2nd approach with inline mode as well.

In my @DebtsTrackerBot I use both callbacks & switch_inline_query_current_chat for similar task.

like image 160
Alexander Trakhimenok Avatar answered Nov 02 '22 09:11

Alexander Trakhimenok