我想将 csv 文件附件发送给 bot 中的用户。我正在使用 Microsoft bot 框架 C# bot builder SDK,使用网络聊天 channel 。我通过以下方式向用户发送 csv 文件:
var csvPath = "D://ProjecteFile/Results.csv";
//Attachment attachment = new Attachment();
//attachment.ContentType = "text/csv";
//attachment.ContentUrl = csvPath;
//attachment.Name = "click this link to get server report";
//return attachment;
我也试过用英雄卡
var heroCard = new HeroCard {
Title = "Click to download Report",
Buttons = new List < CardAction > {
new CardAction(ActionTypes.OpenUrl, "Get Started", value: "file://L-156222101/ProjectFile)")
};
return heroCard.ToAttachment();
}
我的机器人可以通过网络聊天向用户发送 csv 文件吗?
最佳答案
您可以使用英雄卡来实现这一目标。你的代码的问题是你没有指定文件名和位置,即如果你的文件名是 ProjectFile 那么按钮中的值必须包含 ProjectFile.csv
最好的方法是将文件添加到项目中的文件夹中,并在按钮中的 Card Action 值中添加引用。
例如:
Attachment attachment = new HeroCard
{
Title = "Click to download Report",
Buttons = new List<CardAction>()
{
new CardAction()
{
Title = "Get Started",
Type = ActionTypes.OpenUrl,
Value = "D:\\ProjecteFile\\Results.csv"
}
}
}.ToAttachment();
var reply = context.MakeMessage();
reply.Attachments.Add(attachment);
await context.PostAsync(reply);
关于c# - 如何使用 C# 在 Web 嵌入式 bot 中的 bot 框架中发送附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49489927/