我想在Skype频道上使用bot-framework发送pdf文件。类似于在电报频道上完成此操作。 Bot Framework: send pdf file on Telegram。我真的很难找到有关使用带有bot-framework的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有很多各种方法的例子。
我知道截至去年这个时候,由于安全问题,Skype频道不支持向用户发送PDF附件 - 你可以看到有关这个问题的更多细节here。我无法找到任何与此相反的最新文档,也无法通过我的测试机器人向Skype发送PDF附件。我可以,发送一个PDF给模拟器和WebChat。不幸的是,我认为Skype频道仍然不支持发送PDF附件。
以下是我用于将PDF附件发送到模拟器和WebChat的示例代码:
var reply = turnContext.Activity.CreateReply();
// Create an attachment.
var attachment = new Attachment
{
ContentUrl = "<path_to_file>/<filename>.pdf",
ContentType = "application/pdf",
Name = "<filename>.pdf",
};
// Add the attachment to our reply.
reply.Attachments = new List<Attachment>() { attachment };
// Send the activity to the user.
await turnContext.SendActivityAsync(reply, cancellationToken);
对不起我无法提供更多帮助。
虽然Skype阻止您以任何形式(链接,本地文件或Base64Strings)发送PDF作为附件,但您只需在文本中嵌入链接即可将其作为链接发送。