c# - 如何从电报机器人中的多个文件发送特定文件
问题描述
我用 C# 编写了一个电报机器人,它从用户那里下载文件,例如 .docx 文件并将这个文件转换为 PDF。我想在将文件转换为 PDF 后,在 word 文件和 PDF 文件之间将此文件(PDF 文件)返回给用户。
此代码将 word 文件返回给用户。
// Download File
Telegram.Bot.Types.File file = await bot.GetFileAsync(message.Document.FileId);
string fileName = file.FileId + "." + file.FilePath.Split('.').Last();
using (FileStream saveFileStream = File.Open(fileName, FileMode.Create))
{
await bot.DownloadFileAsync(file.FilePath, saveFileStream);
}
await bot.SendTextMessageAsync(chatId, "File Saved");
// Convert Document to PDF
Spire.Doc.Document document = new Spire.Doc.Document();
document.LoadFromFile(fileName);
document.SaveToFile(fileName + ".pdf", Spire.Doc.FileFormat.PDF);
// Send PDF File
using (var sendFileStream = File.Open(fileName, FileMode.Open))
{
await bot.SendDocumentAsync(chatId, new Telegram.Bot.Types.InputFiles.InputOnlineFile(sendFileStream, fileName));
}
await bot.SendTextMessageAsync(chatId, "Your pdf file");
解决方案
推荐阅读
- python - 如何使用 tkinter 按钮将信息发送到定义
- highcharts - 使用 highcharts-ng 指令,Highcharts 向下钻取功能无法以角度方式工作
- asp.net-core - 与 DbQuery 的关系
- jenkins - Jenkins - IBM UrbanCode - AWS 和 Azure 云
- angular - 标记表单字段 #myFormField 与 #myFormField="ngModel"
- android - 从第二个活动返回时,在 AsyncTask 调用后保存 RecyclerView 状态
- wso2sp - WSO2 流处理器指标
- ruby-on-rails - 依赖破坏不起作用会给出外键异常
- javascript - 向包含新消息的父级添加粗体类
- laravel - Kubernetes 上的 snipeit 未运行