Reputation: 129
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.
Upvotes: 12
Views: 14894
Reputation: 623
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
}
}
Upvotes: 1
Reputation: 847
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.
Upvotes: 0
Reputation: 2764
unfortunately it's not possible yet.(they may come up with something in future) as admin you can just send messages to channel.
Upvotes: 2