Telegram Bot Webhook doesn't track channel post deletion - telegram

I need to synchronize telegram channel posts with my site. So, I created a bot, a channel, added my bot to this channel(with admin rights, it has access to messages) and binded my bot's webhook to the specified server url. Everything goes well, post creation updates are correctly sent to the server url. The only problem is that the update of channel post deletion from telegram is not tracked, so admin has manually delete posts from the server database. Any idea, how to set up bot or webhook in order to track post deletion?

This is not possible using Bot API since Telegram doesn't send most of the events to Bot accounts.
You should instead use MTRPOTO to connect to a number on Telegram as a normal user (not a bot) that is the admin or subscriber of that channel and receive all of the events from Telegram.
I'd suggest you use Telethon (A Python MTPROTO library).
Upon a message deletion, you will receive MessageDeleted event.
There's an example on Telethon's document website:
from telethon import events
#client.on(events.MessageDeleted)
async def handler(event):
# Log all deleted message IDs
for msg_id in event.deleted_ids:
print('Message', msg_id, 'was deleted in', event.chat_id)
But if you insist on doing this with bot API, there's a spaghetti solution. You can forward channel posts to another chat with their Ids, if you get a message doesn't exist error, that means the message was deleted.

Related

How to check if message was deleted?

How I can check using telegram bot api if message of user (not bot) was deleted.
There aren't any methods mentioned in Telegram Bot API docs for your purpose.
But as a workaround you can store message ids sent by user in a database and then try to forward them to another chat. If forward was successful then that means the message is not deleted, else, the message is deleted.
Check forwardMessage

How to make my Telegram Bot to add me back to a private channel?

I have a Telegram Bot and I HAD a Private channel. I added my bot to this channel as an Administrator so it can send messages on this channel using the API. It's ok, everything's working fine.
But now, I accidentally deleted the channel from my chat list. My bot is still an administrator and is not failing on sending the messages to the channel.
I guess the channel still exists, and the bot is the only administrator on it.
I want to know how can I make my bot add me back to the channel, as I can't do it by myself, because the channel is private. I made the bot backend using C#, I have the ChatID and the Bot Token.
Thanks!
Ok, I found by myself. Just make a post request to:
https://api.telegram.org/bot[Token]/exportChatInviteLink
Passing the chat_id parameter, and it'll return the invite link.
But there's a catch: When I added the bot to the channel, I did not allowed it to invite others... So now I'm locked out for sure.

Send message to Telegram contact or list of contacts using API

I have a Telegram account and Now I wants to import list of contacts into my Account using Telegram API.
Is This possible to send Message to my imported contacts using Telegram API, just like normal user can send message to other user in his contacts list?
I tried Telegram bots but Telegram bot can't send message to other users, unless they started any chat with Bot. So this is not that useful.
You can act as a normal user by using the Telegram MTProto API. There are many libraries that interact with that, like Python telethon or PHP MadelineProto.

How can i trigger a Telegram Bot via an API user

i've set up a working telegram bot that get's triggered on a /mission command. I want to use the bot within groups to enable a fast response feedback system for my organization. the flow is like follows:
1) a API client (no bot, just pure api) sends a message to a group, triggering the bot using /mission .
2) the bot responds to the command and the feedback process starts..
As a normal user, I can trigger the bot whereas the api user won't even reach my bot using webhooks.
Is there any known limitation on what APIs can trigger?
thanks!
Telegram MTProto API has same limits and same benefits of a normal Telegram user. So, you can trigger all bots you want, but be careful with FLOOD_WAIT error: an user sends too much messages in one second or in one minute, Telegram blocks the user for x seconds.
If you don't want to setup tg-cli, and other stuff to run MTProto client on your server and control it, I suggest you to use PWRTelegram APIs, so logging in as user.

telegram bot api - get all messages in a group

I'm working on Telegram bot api in my java application. I have created a super group and add my bot to this as an administrator. I want to get all messages in that super group(not deleted messages) via bot. Is there any useful method for doing that?
Yes. first, you should "disable" privacy of your bot so it can access to all messages in groups. second, use getUpdates to see recent updates and user messages will be there.

Resources