如何使用Telegram.Bot库将本地文件发送到一个ChatId?

时间:2019-11-09 16:33:10

标签: c# telegram-bot

我想发送一个文件,该文件托管在私有服务器中(我的意思是没有公共URL)。 我认为我必须在Telegram.Bot库中使用SendDocumentAsync()。 问题是我不知道在发送文件之前是否已上传文件。 我已经尝试了下一个代码,但是没有用。

using (FileStream fs = System.IO.File.OpenRead("c:\test.txt"))
            {
                Telegram.Bot.Types.InputFiles.InputOnlineFile inputOnlineFile = new Telegram.Bot.
                             Types.InputFiles.InputOnlineFile(fs, "FileName.txt");
                Bot.SendDocumentAsync(
                     chatId: new Telegram.Bot.Types.ChatId(12345),
                     document: inputOnlineFile,
                     caption: "User manual",
                     parseMode: ParseMode.Markdown);
            }

0 个答案:

没有答案