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
Related
I want to know if it possible to send message to my telegram bot as a user.
Maybe I should send a request with my credentials? Or I am completely missing something?
UPD:
Ok I see it is not clear. I want to send message using program.
Open your Telegram App, search for your bot and open the chat with it. Then type a message and hit send.
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.
I have problems with telegram's api in c#. I search any solutions how to recevie message from Telegram using API. I found only library for Telegram BOT(send message etc.), but I need only recevie message from one user. There is option "Get.Message" in Telegram Api, but I can't find simply library to use this option.
using the telegram client api you can get updates automatically from telegram when a message is received. You simply need to handle the response once the session is created and a connection is made
Just in case you don't want realtime updates, you can use messages.GetHistory and supply the number of messages you'd like to retrieve. You need to provide the chat ID and access hash which you can get from contactsResolveUsername
enter link description here
I have subscribed to a telegram bot (I am not the owner/admin of that bot) which sends messages in a particular format. I need to do is to parse the incoming messages and used the parsed information as parameters to a trading API.
Hence, I need a daemon sort of thing which runs on my laptop and keeps listening for any new messages from that bot, and when it receives one, then parse it.
Can the Telegram Bot API handle this? In other words if I create a bot will it be able to read the messages sent to me by the other bot
Did you try to search on official documentation API or FAQ?
https://core.telegram.org/bots/faq#why-doesn-39t-my-bot-see-messages-from-other-bots
You can do it using python and python-telegram-bot package.
When you create a bot in your python code using the following code:
bot = telegram.Bot("Your bot's token")
you are able to get the new messages sent to your bot using bot.get_updates() and there's a feature to check if the sent message is from a bot or not. You can write a function that returns a boolean telling whether is the message sender bot or not:
def is_bot(update=dict()): #"update" is one of the messages which got returned from get_updates()
message = update["message"].to_dict()
return message["from"]["is_bot"]
for update in bot.get_updates():
print(is_bot(update))
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.