我正在使用 WTelegramClient 庫。
這是我發送訊息的方式:
var client = new WTelegram.Client(Config);
await client.LoginUserIfNeeded();
var contacts = await client.Contacts_ImportContacts(new[]
{
new InputPhoneContact { phone = " 998901234567" }
});
if (contacts.imported.Length > 0)
await client.SendMessageAsync(contacts.users[contacts.imported[0].user_id], "Hello, world!");
如何發送多個檔案?或至少一個檔案。
我需要從串列或檔案夾中發送檔案。我會很高興得到任何幫助。
List<byte[]> file = new List<byte[]>();
uj5u.com熱心網友回復:
來自官方檔案的示例
1.獲取上傳檔案夾路徑,像這樣。
const string Filepath = @"C:\...\photo.jpg";
2.使用客戶端和路徑上傳檔案
var inputFile = await client.UploadFileAsync(Filepath);
3.向對等方發送檔案(chats.chats[ChatId])
await client.SendMediaAsync(peer, "Here is the photo", inputFile);
示例代碼
const int ChatId = 1234567890; // the chat we want
const string Filepath = @"C:\...\photo.jpg";
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await client.LoginUserIfNeeded();
var chats = await client.Messages_GetAllChats(null);
InputPeer peer = chats.chats[ChatId];
var inputFile = await client.UploadFileAsync(Filepath);
await client.SendMediaAsync(peer, "Here is the photo", inputFile);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/414349.html
標籤:
