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.
unfortunately it's not possible yet.(they may come up with something in future) as admin you can just send messages to channel.
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
}
}
The only way until now is as follows:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.