How delete all message in telegram chat? (python, telegram.ext) - python

I encountered the problem of deleting all messages (including messages from the bot itself) in the telegram chat. How i can do this? I use the telegram.ext library.

Telegram Bot API doesn't have methods to delete multiple messages. You have to know message_id to delete it.
python-telegram-bot library has support to only Bot API. You can make use of telethon library which supports Telegram API.
There is a delete_message method in the bot object, as described in the python-telegram-bot Documentation
Example:
bot.delete_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Remember that there are some limitations:
A message can only be deleted if it was sent less than 48 hours ago.
Bots can delete outgoing messages in groups and supergroups.
If the
bot is an administrator of a group, it can delete any message there
If the bot has can_delete_messages permission in a supergroup or a
the channel, it can delete any message there.

Related

Grant access to telegram bot in chats

I have a slightly different question about telegram bot using botfather. Is it possible to grant access to the bot in some private chat on my telegram? For example: I am on a telegram channel, and I would like the bot to have access to these messages without having to put the bot on the channel.
I'm currently using Python 3.10x and I'm using the telegram API via requests (I'm not using any libraries).
I thought that since there is the /getUpdates endpoint that makes the bot read messages where it has access, maybe it can also have access to some private chat of any user (as long as the user obviously allows it somehow)

is there a way to make a telepot bot read messages from other bots?

I am developing a telegram bot using the telepot library for python and needed to have two bots communicate with each other in a group.
for some reason, neither bot cannot read messages sent by bots.
can someone tell me how i could do ?
here are the bots settings:
Privacy mode = OFF
Group privacy = OFF
Allow groups = ON
Thank you.
you'll never be able to let two bots communicate on the same group.
though, they can communicate -not on a group- using a different approach which is a channel.
bots can read all channel's messages, hence you can make both of your bots read each other's messages by sending it on the same channel.
for more information, check this out what messages will my bot get

How can i get someone telegram chat id with python?

Hi everyone i want to create a new telegram bot similar to #usinifobot.
this is how it works:
you just send someone username to this bot and it will give you back his/her chat id.
i want to do same thing but i dont khow how to do it with python-telegram-bot.
python-telegram-bot can't help with this, because telegram bot api can't provide ids of unrelated entities to the bot - only ones with which bot iteracts
you need telegram client api for this and to hold a real account (not a bot) online to make checks by another library
and with bot library like python-telegram-bot you could only get ids of users who write to bot, channels and groups bot is in and reposted messages from other users
I created similar bot #username_to_id_bot for getting ids of any entity and faced all these moments

Is it possible to create a telegram bot which forwards messages from another bot to telegram group or channel?

I want to create a telegram bot which would immediately forward message from another bot, that regularly posts some info. I've tried to find some ready templates, but alas... I would be grateful for any useful info. Thanks!
I don't think this is possible. As far as I know, bots can't communicate with other bots.
But you can add bots to groups

How to delete message on channel telegram?

I need telegram bot which can delete message in group channel
i googled it but did not find a solution
Could you tell the library and the method for this, if you know, thank you in advance?
To delete ANY messages you would need the full Telegram API, as you cannot do this from the Bot API.
The required method in Telegram API is:
channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector<int> = messages.AffectedMessages;
Telegram bot API doesn't support delete any message at this time, even in group or private chat.
I think you can try telegram-cli, a third-party unofficial Telegram client, and use it's delete_msg method.
In the bot API 3.0 the method used is "deleteMessage" with parameters chat_id and message_id
Not yet officially announced
You may delete messages only with telegram api, not bot api. With telethon (python client for telegram API) you can do it this way:
client.invoke(DeleteMessagesRequest(chat, [msg.id]))

Categories

Resources