WTelegramClientHelperGetChannelMessages Method
Asynchronously retrieves messages from the specified channel.
Namespace: DevCase.ThirdParty.WTelegramClientAssembly: DevCase.net48.ThirdParty.WTelegramClient (in DevCase.net48.ThirdParty.WTelegramClient.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
public static Task<List<MessageData>> GetChannelMessages(
Client client,
Channel fromChannel,
int fromTopicId,
long fromUserId,
bool onlyMediaMessages,
bool ascendingMessageOrder,
Action<int, MessageData> progressCallBack = null
)
Public Shared Function GetChannelMessages (
client As Client,
fromChannel As Channel,
fromTopicId As Integer,
fromUserId As Long,
onlyMediaMessages As Boolean,
ascendingMessageOrder As Boolean,
Optional progressCallBack As Action(Of Integer, MessageData) = Nothing
) As Task(Of List(Of MessageData))
Dim client As Client
Dim fromChannel As Channel
Dim fromTopicId As Integer
Dim fromUserId As Long
Dim onlyMediaMessages As Boolean
Dim ascendingMessageOrder As Boolean
Dim progressCallBack As Action(Of Integer, MessageData)
Dim returnValue As Task(Of List(Of MessageData))
returnValue = WTelegramClientHelper.GetChannelMessages(client,
fromChannel, fromTopicId, fromUserId,
onlyMediaMessages, ascendingMessageOrder,
progressCallBack)
public:
static Task<List<MessageData^>^>^ GetChannelMessages(
Client^ client,
Channel^ fromChannel,
int fromTopicId,
long long fromUserId,
bool onlyMediaMessages,
bool ascendingMessageOrder,
Action<int, MessageData^>^ progressCallBack = nullptr
)
static member GetChannelMessages :
client : Client *
fromChannel : Channel *
fromTopicId : int *
fromUserId : int64 *
onlyMediaMessages : bool *
ascendingMessageOrder : bool *
?progressCallBack : Action<int, MessageData>
(* Defaults:
let _progressCallBack = defaultArg progressCallBack null
*)
-> Task<List<MessageData>>
No code example is currently available or this language may not be supported.
- client Client
-
The source Client object.
- fromChannel Channel
-
The channel from which to retrieve messages.
- fromTopicId Int32
-
If fromChannel is a group, this value indicates
the identifier of the topic from which to retrieve messages.
If this value is null and fromChannel is a group, all messages from all topics will be retrieved.
- fromUserId Int64
-
The identifier of the user for which to retrieve their messages in the provided channel.
If this value is null (zero), all messages from all users will be retrieved.
- onlyMediaMessages Boolean
-
If True, only retrieves messages containing media (such as direct download files, urls, photos, etc);
If False, it also retrieves plain text messages.
- ascendingMessageOrder Boolean
-
Determines whether the messages should be ordered in ascending order (oldest message = first).
- progressCallBack ActionInt32, MessageData (Optional)
-
Optional. An action callback for progress updates,
providing the number of fetched messages and the associated topic-message data.
TaskListMessageData
An asynchronous operation that yields a
ListT
containing the retrieved messages from the provided channel.
This is a code example that demonstrates how to fetch all messages from chat or channel.
No code example is currently available or this language may not be supported.
Private Async Sub Test()
Dim clientConfig As New TelegramClientConfig With {
.ApiId = "###",
.ApiHash = "###",
.FirstName = "###",
.LastName = "###",
.Password = "###",
.PhoneNumber = "+34###",
.VerificationCode = "###"
}
Dim client As WTelegram.Client = CreateClient(clientConfig)
Dim myUser As TL.User = Await client.LoginUserIfNeeded()
Dim myUserId As Long = DirectCast(myUser, UserBase).ID
Debug.WriteLine($"We are logged-in as user: {myUser.MainUsername}, id: {myUserId}")
Dim channelTitle As String = "Channel Title"
Dim channel As TL.Channel =
(Await WTelegramClientHelper.GetChannelsByTitleAsync(client, channelTitle)
).Single()
Dim channelMessages As List(Of MessageData) =
Await WTelegramClientHelper.GetChannelMessages(client, channel,
fromTopicId:=0, fromUserId:=0,
onlyMediaMessages:=False,
ascendingMessageOrder:=True)
Dim totalMsgCount As Integer = channelMessages.Count
Dim currentMsgCount As Integer
For Each msgData As MessageData In channelMessages
Dim flags As TL.Message.Flags = MessageExtensions.GetFlags(msgData.Message)
Dim hasUsername As Boolean = flags.HasFlag(flags.has_post_author)
Dim username As String = If(hasUsername, msgData.PeerInfo.MainUsername, "null")
Dim sb As New StringBuilder()
sb.AppendLine($"Message Count: #{Interlocked.Increment(currentMsgCount)} of #{totalMsgCount}")
sb.AppendLine($"Message Date.: {DirectCast(msgData.Message, MessageBase).Date:dd/MMMM/yyyy, HH:mm:ss}")
sb.AppendLine($"User Name/Id.: {username}/{msgData.PeerInfo.ID}")
sb.AppendLine($"Message......: {msgData.Message.message}")
Debug.WriteLine(sb.ToString())
Next
End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.