【发布时间】:2019-02-14 03:34:42
【问题描述】:
我想在 Skype 频道上使用机器人框架发送 pdf 文件。类似于在电报频道上执行此操作的方式。 Bot Framework: send pdf file on Telegram。我真的很难找到有关将 Skype 频道与机器人框架一起使用的有用文档。 CardAttachments 不起作用,即使它们在两年前即将推出。像 Telegram 示例一样,我将 pdf 作为 base64 字符串。我不能使用链接,因为 pdf 是根据用户的输入生成的。
这就是我发送图像的方式。我认为它是类似的东西。
var cardAttachment = new Attachment()
{
ContentUrl = "https://my.url/file.png",
ContentType = "image/png",
Name = "filename.png",
};
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>() { cardAttachment };
reply.Text = "Some useful text to go along with the image.";
await turnContext.SendActivityAsync(reply, cancellationToken);
我试过了
var values = new Dictionary<string, string>();
...
var content = new FormUrlEncodedContent(values);
var response = await Client.PostAsync(@"https://my.url/report.php", content);
var report = await response.Content.ReadAsByteArrayAsync();
var cardAttachment = new Attachment()
{
ContentUrl = "data:application/pdf;base64," + Convert.ToBase64String(report),
ContentType = "application/pdf",
Name = $"{answers.Name}.pdf",
};
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>() { cardAttachment };
reply.Text = $"{answers.Name} here is your report.";
await turnContext.SendActivityAsync(reply, cancellationToken);
看起来很接近,但很正确。
更新:虽然 Skype 阻止您以任何形式(链接、本地文件或 Base64Strings)将 PDF 作为附件发送 您可以通过简单地嵌入链接将它们作为链接发送在你的文字中。看起来您可以将链接和本地文件发送到 WebChat。 Sending Bot Reply message with attachment using Bot Framework 有很多不同方法的例子。
【问题讨论】:
标签: pdf botframework skype