如何在 C# 的电报机器人中使用 SendDocumentAsync?

How can use SendDocumentAsync in telegram bot in c#?

我是电报机器人的新手,我已经阅读了this tutorial

但是我不能在我的代码中使用那个例子,我的服务器上有 html 文件,想用电报机器人发送它,我该怎么做?

我假设您已经成功设置了您的机器人客户端。然后你可以像这样发送一个 SendDocumentAsync 的 (HTML-) 文档:

private async void BotClientOnMessage(object sender, MessageEventArgs e)
{
    // Create a web request to download the html file from your server
    WebRequest req = WebRequest.Create("http://google.com");
    req.Method = "GET";

    using (var response = await req.GetResponseAsync())
    using (var stream = response.GetResponseStream())
    {
        await BotClient.SendDocumentAsync(e.Message.Chat.Id, new FileToSend("file.html", stream));
    }
}

传递给FileToSend的流是文件的内容。

但是文件没有显示为网页: