Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get messages from a Telegram channel with the Telegram API

How can I access to a Telegram channel messages with a bot registered as channel admin?

I am trying to get all the messages from Telegram channel and display them in an ASP.NET webpage (c#)

I am able to get updates when new message sent directly to the bot:

var json = wc.DownloadString(" https://api.telegram.org/bot<token>/getUpdates");

but its not working for the channel.

like image 940
Tamoochin Avatar asked Dec 30 '15 08:12

Tamoochin


People also ask

Can Telegram BOT read channel messages?

The FAQ reads: All bots, regardless of settings, will receive: All service messages. All messages from private chats with users.

How can I get Telegram channel data?

c) On the desktop app's homescreen, click on the three horizontal lines on the top left corner to open the app menu. Once the menu pops up, select "Settings". d) On the screen that shows the 'Settings' options, scroll down to the 'Privacy and Security' option, then select 'Export Telegram Data'.

How can I get Telegram Channel users with Telegram Bot API?

To use MTProto, you need to login to https://my.telegram.org/ with your existing Telegram account and get credentials: api_id and api_hash . Here is a working example of how to use Telethon python library to get list of Telegram channel/group users. It is easy to search channels/users by name/phone/URL with client.

How do I interact with API in Telegram?

Creating a client Before you can start interacting with the Telegram API, you need to create a client object with your api_id and api_hash and authenticate it with your phone number. This is similar to logging in to Telegram on a new device; you can imagine this client as just another Telegram app.


2 Answers

unfortunately it's not possible yet.(they may come up with something in future) as admin you can just send messages to channel.

like image 63
Mohammad Avatar answered Sep 23 '22 09:09

Mohammad


You can receive channel posts and channel post editing.

But you won't receive it in OnMessage event, you can receive it from OnUpdate as Message object like code below:

Note: The bot must be an administrator in the channel.

private static readonly TelegramBotClient Bot = new TelegramBotClient("my-real-token");

public static void Main(string[] args)
{
    Bot.StartReceive(UpdateType.ChannelPost, UpdateType.EditedChannelPost);
    Bot.OnUpdate += Bot_OnUpdate;
}
    
public static void OnUpdate(UpdateEventArgs e)
{
    if (e.Update.Type == UpdateType.ChannelPost)
    {
        Message post = e.Update.ChannelPost;
        //TODO: Store channel post
    }
    else if (e.Update.Type == UpdateType.EditedChannelPost)
    {
        Message editedPost = e.Update.EditedChannelPost;
        //TODO: Store edited channel post
    }
}
like image 31
Muaath Avatar answered Sep 22 '22 09:09

Muaath