我想使用C#或VB.Net代码将大文件发送给特定的电报用户。 现在我正在使用TLSharp,它非常适合发送短信。但是当我想发送图像或文件时,它会在第一行返回错误,如下所示:
“未找到类型'TelegramClient'上的公共成员'UploadFile'。”
这是我的代码:
Private Async Sub btnSendImage_Click(sender As Object, e As EventArgs) Handles btnSendImage.Click
Dim fileResult = CType(Await client.UploadFile(fileName, New StreamReader(filePath)), TLInputFileBig)
Await client.ConnectAsync()
Dim result = Await client.GetContactsAsync()
For Each item In result.users
If (item.phone = phoneNumber) Then
Await client.SendUploadedDocument(New TLInputPeerUser() With {.UserId = item.id}, fileResult, "some pics", "application/png", New TLVector(Of TLAbsDocumentAttribute)()) 'mime-type - caption
End If
Next
End Sub
此库中似乎没有UploadFile方法。
还有其他方法可以上传文件并获取file_id吗?
*我使用了c#和VB.Net标签,因为C#或VB.Net代码对我来说没有区别。我可以使用两者,但我的样本是在VB.Net。
答案 0 :(得分:0)
答案 1 :(得分:0)
我自己找到了答案。我把它放在这里帮助别人。
首先,我们需要添加一个Imports:
Imports TLSharp.Core.Utils.UploadHelper
然后按如下方式更改代码:
Private Async Sub btnSendImage_Click(sender As Object, e As EventArgs) Handles btnSendImage.Click
Await client.ConnectAsync()
Dim fileResult As TLAbsInputFile = Await UploadFile(client, fileName, New StreamReader(filePath))
Dim result = Await client.GetContactsAsync()
For Each item In result.users
If (item.phone = phoneNumber) Then
Await client.SendUploadedDocument(New TLInputPeerUser() With {.UserId = item.id}, fileResult, "some pics", "application/png", New TLVector(Of TLAbsDocumentAttribute)()) 'mime-type - caption
End If
Next
End Sub