skip to Main Content

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.

3

Answers


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

    Login or Signup to reply.
  2. The only way until now is as follows:

    1. Your bot be added to the channel by its administrator.
    2. You set the bot’s privacy to disabled.

    Step 1 helps your bot to join the channel so it see the messages.

    Step 2 makes your bot listening to all messages of the channel.

    Login or Signup to reply.
  3. 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
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search