Is it possible to build a telegram bot that aggregates posts of multi telegram channel? - telegram-bot

Requirments:
1- Have a feed of posts that aggregate all posts of multi channels
2- have actions (bot command) on each post
3- When post of channel edited, correspondent post in the telegram bot edited too.
(If it is not possible, I want to know is it possible to edit a message that was sent to multiple recipients in one action or i have to change each of them by message id, chat id)
You can assume you are owner of all these channels and you set your bot as admin of all of them

Only creator/admins can add bots to channels and only as admins.
Bots (for now) can't read messages in channels.
Bots (for now) can't view any counters in channels.
So no such bot for now :(

Related

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.

How can a telegram bot broadcast a message to active chats / users

We are building an internal bot to monitor / control our software. It is NOT exposed to the public and will be used by other team members, either directly (as a direct chat) or through a few channels depending which side of the software is on topic.
The bot should do two things:
reply to commands; the reply should go to the user that originated it.
send notices to all users / channels it is involved in.
When a message arrives, I can get the channel id and the user id; while the user id is kind of guaranteed to exist for while, what is the situation with the channel?
Can I store the channel id and broadcast messages to all channels the bot is involved in? what happens if a channel is closed? do channel ids have lifetimes?
I can't really find anything online about the best practice regarding this scenario.
I have doubt Understand what you want but it seems better know these things :
ID's are unique in Telegram and even in all others applications so
they are lifetime
Channel ID , Groups ID , User ID have same behavior but their difference is on their integer. (User ID's are Positive but channels and groups are Negative. check example here)
Users can just send message in channels that they have admin permission in it right? Bots are same. so if your bot isn't admin anymore , the Telegram gives you error in response and you can check it and after facing that error delete that channel ID in your channels list.
I hope this information help you but if you have any other question feel free to leave a comment and I'll update the post and answer you immediately.

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)

How to have a telegram bot join a channel via link?

I would like to program a crawler bot which would surf channels and find the message with high view counts.
Is it possible to have a bot added to a channel via link?
Is it possible for a bot to read messages broadcast in a channel?
Is it possible for a bot to read view count value of a message in a channel?
If any of the above questions are possible, what is/are the solution(s)?
Only creator/admins can add bots to channels and only as admins.
Bots (for now) can't read messages in channels.
Bots (for now) can't view any counters in channels.
Finally, for now, bots can only post messages to channels and only if added to channel by creator or admin.