【问题标题】:How do you send a pdf file using bot framework on a Skype channel?如何在 Skype 频道上使用机器人框架发送 pdf 文件?
【发布时间】: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


【解决方案1】:

我知道截至去年这个时候,出于安全考虑,Skype 频道不支持向用户发送 PDF 附件 - 您可以查看有关此问题的更多详细信息 here。我找不到任何与此相反的最新文档,也无法通过我的测试机器人将 PDF 附件发送到 Skype。但是,我可以将 PDF 发送到 Emulator 和 WebChat。不幸的是,我认为 Skype 频道仍然不支持发送 PDF 附件。

这是我用来向模拟器和 WebChat 发送 PDF 附件的示例代码:

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);

很抱歉,我无法提供更多帮助。

【讨论】:

  • 请张贴您用来发送到 WebChat 的代码。
  • 我刚刚添加了将 pdf 发送到网络聊天的代码。它与您上面的代码 sn-p 非常相似。
【解决方案2】:

虽然 Skype 阻止您以任何形式(链接、本地文件或 Base64Strings)将 PDF 作为 附件 发送,但您只需将链接嵌入到您的文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2020-04-02
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    相关资源
    最近更新 更多