WTelegramClientHelperCopyMessageAsync(Client, Message, Channel, Int32) Method
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<Message> CopyMessageAsync(
Client client,
Message msg,
Channel toChannel,
int topicId = 0
)
Public Shared Function CopyMessageAsync (
client As Client,
msg As Message,
toChannel As Channel,
Optional topicId As Integer = 0
) As Task(Of Message)
Dim client As Client
Dim msg As Message
Dim toChannel As Channel
Dim topicId As Integer
Dim returnValue As Task(Of Message)
returnValue = WTelegramClientHelper.CopyMessageAsync(client,
msg, toChannel, topicId)
public:
static Task<Message^>^ CopyMessageAsync(
Client^ client,
Message^ msg,
Channel^ toChannel,
int topicId = 0
)
static member CopyMessageAsync :
client : Client *
msg : Message *
toChannel : Channel *
?topicId : int
(* Defaults:
let _topicId = defaultArg topicId 0
*)
-> Task<Message>
No code example is currently available or this language may not be supported.
- client Client
-
The source Client object.
- msg Message
-
The source message to be copied.
- toChannel Channel
-
The destination channel where the copied message will be sent.
- topicId Int32 (Optional)
-
Optional. If toChannel is a group,
this value indicate the topic where the copied message will be sent.
Default value is zero.
TaskMessage
An asynchronous operation that returns a
Message representing the message sent.
This is a code example.
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 fromChat As TL.ChatBase =
(Await GetChannelsByTitleAsync(client, "From Channel Title", StringComparison.OrdinalIgnoreCase)
).Single()
Dim toChannel As TL.ChatBase =
(Await GetChannelsByTitleAsync(client, "To Channel Title", StringComparison.OrdinalIgnoreCase)
).Single()
Dim fromChatMessages As List(Of MessageData) =
Await GetChannelMessages(client, fromChat,
fromTopicId:=0, fromUserId:=0,
onlyMediaMessages:=False,
ascendingMessageOrder:=True)
Dim totalMsgCount As Integer = fromChatMessages.Count
Dim currentMsgCount As Integer
For Each msgData As MessageData In fromChatMessages
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("Forwarding message...")
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())
Try
Await CopyMessageAsync(client, msgData.Message, toChannel, topicId:=0)
Catch ex As RpcException
If ex.Message.Equals("CHAT_FORWARDS_RESTRICTED", StringComparison.OrdinalIgnoreCase) Then
' Ignore?
ElseIf ex.Message.Equals("FILE_REFERENCE_EXPIRED", StringComparison.OrdinalIgnoreCase) Then
' Ignore?
ElseIf ex.Message.Equals("WEBPAGE_NOT_FOUND", StringComparison.OrdinalIgnoreCase) Then
' Ignore?
ElseIf ex.Message.Equals("FLOOD_WAIT_X", StringComparison.OrdinalIgnoreCase) Then
Debug.WriteLine("ERROR: FLOOD_WAIT_X")
Debug.WriteLine($"Waiting {ex.X} seconds to continue with the operation...")
Thread.Sleep(ex.X * 1000)
Else
Throw
End If
Catch ex As Exception
Throw
Finally
' 3 seconds delay between each request to avoid flooding detection (error "FLOOD_WAIT_X").
Thread.Sleep(3000)
End Try
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.