[英]C# how to send a file via Telegram API
我正在使用 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[]>();
來自官方文檔的示例
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.