Telegram bots - how can we detect that a user has started typing? - telegram-bot

We can get Telegram messages when they are complete and sent via long polling or webhooks, but is there a way to understand when the user has started typing?
I guess this is not a normal case for bots and I dont think there is a straight away method but could we fall back on the Telegram API for messaging apps for that?

Well, actually I found a solution in the current Bot API; inline queries. While they are not intended for this, inline queries send what the user types in to the bot in real-time, so you are alerted as soon as the first characters are typed in.

There is a way in Telegram Core API, named: updateUserTyping.
But there is not any way in Telegram Bot API yet (until today: 2016-10-17).
If you type or send a file to the bot during these processes you do not get any message from Telegram in your webhook, but it's possible they'll add a new feature to detect user typing in future Bot API updates.

Related

How to implement Telegram bot as a widget on your website?

I'm trying to create some sort of live chat widget, but with a Telegram bot instead of a real person on the other side. I don't know if it is possible, but ideally, there is a chat window that can be implemented on a website, and establishes a new connection with a telegram bot once you click on it. The end-user should NOT have a Telegram account. I already tried to implement Intergram but it's not exactly what I'm looking for, as it merely forwards the message to a human using webhooks, and the bot is only used as a message broker. I have heard that some customization is possible using tdlib but I'm not sure if it can help me achieve the desired result.
How should I start implementing a chat window with my bot on a website?

Google chat auto-reply bot

Is there any way to configure Google Chat so It will automatically reply when another user sends me a message? Similar to the way vacation reply works for GMAIL.
The trigger will be the message coming from a user. not calling any bot.
Sorry, unfortunately there is no way to do that
You can set your status as "Out of Office" and that will be reflected in chat.
https://support.google.com/mail/answer/25922?co=GENIE.Platform%3DDesktop&hl=en
The API is designed for bots so there is no way via API either.
You can always make a feature request, if you like.

Telegram Bots: Can I now start a chat or not?

https://core.telegram.org/bots clearly says:
Bots can't initiate conversations with users. A user must either add them to a group or send them a message first.
But if I visit https://telegram.org/blog/login it says
Telegram bots are a powerful communication tool, but until today they couldn't start a conversation. Even if you wanted them to reach out to you, you had to chat them up first.
With the new login widget, moving from interacting with a website to a conversation on Telegram becomes completely frictionless.
So it is somehow possible to start a conversation via the login widget. But how do I do it?
I get a user id. Is there an api endpoint to initiate a chat with the user?
The only way to begin conversing with a Telegram bot is to start the conversation with them yourself. There's no way for the bot to start a conversation with a user themselves.
As you said, telegram clearly says there is no way for bot to start a conversation, the only thing bots can do is sending messages to an old conversation (I mean a user have to start the conversation).

Is there any way to transfer Telegram file IDs between different bots?

Many different media types on Telegram have a file_id and file_unique_id property, such as Stickers, Audio, and Document.
The file_id property is unique to each Telegram bot, so one Telegram bot will not report the same file_id as another Telegram bot will, even if it's the same piece of media.
I want to have two Telegram bots communicate with each other, but they are currently unable to do so because the file_id property is meaningless when one bot tries to talk to the other.
The file_unique_id property is consistent between the bots, but it does not seem like you can do much of anything with that identifier.
Is there any way to pass a reference to a file stored on Telegram's servers from one bot to another, without having to re-upload the file on both bots?
Bot can't interact with each other. But there's a workaround,
we can use channels as a medium (with only BotAPI)
Steps,
Add two bots as admin in channel
Broadcast the messages from Bot A to channel
Now, the Bot B will get these as channel posts and your new fileid
for the same file which will be unique for Bot B (obviously)
You have officially transferred all fileid to Bot B
There aren't any official methods to share fileIds between bots. In fact, you can't even get 2 bots talk to each other, also you won't get bot updates in groups. So bot to bot communication is not possible at all at this moment.
But what you can do is to use Mtproto api and sign-in to telegram as a normal user (with phone number). And follow these steps using the logged in account:
Start both of your bots.
Forward messages you receive from bot 1 to bot 2.
This way you'll be able to access any files in bot 1 in bot 2.
You can use Telethon to write a script that does the job for you, listening to updates coming from bot 1 & forwarding them to bot 2.
Also using normal bot api you should forward received messages to your logged-in account.
The only way is to use a shared channel. Both bots have admin access. However, you may encounter error 429 while transferring the file.
The solution is to send the files to the channel at longer intervals.

Telegram bot receiving commands from other bot

in the documentation of the telegram bot API I found:
Bots with privacy mode enabled will receive:
Commands explicitly meant for them (e.g., /command#this_bot).
General commands from users (e.g. /start) if the bot was the last bot
to send a message to the group.
So I created two bots - invited both in a group and had "firstbot" to fire /cmd#otherbot something commands. The "otherbot" echos everything it reads.
I (in the client) I can write - "otherbot" doesn't see it - which is correct due to privacy settings.
I i write /cmd#otherbot - "otherbot" receives and echos this - also correct.
BUT - when I let "firstbot" emit /cmd#otherbot in the group "otherbot" doesn't see it.
Am I doing something wrong - or am I miss-leaded by the documentation?
I use C# with Telegram.Bot by roundrobin.
Bots can't see messages meant for other bots, regardless of privacy modes.
Why doesn't my bot see messages from other bots?
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.
Recently I came across with this problem, that one bot can't read messages from another bot.
But I've found a solution: instead of using the Telegram Bot API, you can use TDLib (Telegram Database library) to read the messages.
I am using python, so with this short piece of code I am able to read messages from a bot:
from telegram.client import Telegram
tg = Telegram(
api_id=123456,
api_hash='api_hash',
phone='+555555555',
database_encryption_key='changehere' )
tg.login()
def new_message_handler(update):
message_content = update['message']['content']
message_text = message_content.get('text', {}).get('text', '').lower()
print(message_text)
# do what you want with the message
tg.add_message_handler(new_message_handler)
tg.idle()
I guess that the same can be extended for other languages.
With this approach combined with Bot Telegram API, you are able to:
read messages from a bot (with Telegram Database library)
send that message with another bot (with Telegram Bot API)