Home > Mobile >  How do I send a message to a topic?
How do I send a message to a topic?

Time:01-03

I want to get all the groups containing topics, and then I want to send a message to these topics using the SendMessageAsync method. But I can't do it since ForumTopic can't be cast to InputPeer.

Below is a fragment of the program:

var myself = await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats();
foreach (var (id, chat) in chats.chats)
switch (chat)
{
 case Channel group when group.IsGroup && group.flags.HasFlag(Channel.Flags.forum):
 Console.WriteLine($"Group {group.username}: {group.title}");
 var topics = await client.Channels_GetForumTopics(group, 0);
 foreach (ForumTopic topic in topics.topics)
 {
   Console.WriteLine($"Topic {topic.id}: {topic.title}");
   await client.SendMessageAsync(topic, myMessage); // error CS1503: ForumTopic cannot be cast to InputPeer
 }
 break;
}

CodePudding user response:

easy, you send a message to the group, with reply_to_msg_id: the topic ID, like this:

await client.SendMessageAsync(group, myMessage, reply_to_msg_id: topic.ID);
  • Related