如何在 Skype 频道上使用 bot 框架发送 pdf 文件?

How do you send a pdf file using bot framework on a Skype channel?

我想在 Skype 频道上使用 bot-framework 发送 pdf 文件。这类似于在电报频道上完成的方式。 Bot Framework: send pdf file on Telegram。我真的很难找到有关将 Skype 频道与 bot-framework 一起使用的有用文档。 CardAttachments 不起作用,即使它们在两年前就已推出。与 Telegram 示例一样,我将 pdf 作为 base64 字符串。我不能使用 link,因为 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 阻止您以任何形式(links、本地文件或 Base64Strings)发送 PDF 作为附件,但您可以发送通过简单地将 link 嵌入到您的文本中,将它们作为 links。看起来您可以将 link 和本地文件发送到 WebChat。 Sending Bot Reply message with attachment using Bot Framework 有很多不同方法的例子。

我知道截至去年这个时候,出于安全考虑,Skype 频道不支持向用户发送 PDF 附件 - 您可以查看有关此问题的更多详细信息 here。我没能找到任何与此相反的最新文档,也无法通过我的测试机器人将 PDF 附件发送到 Skype。但是,我可以将 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 阻止您以任何形式(links、本地文件或 Base64String)将 PDF 作为 附件 发送,但您可以将它们作为 发送links 只需在您的文本中嵌入 link。