【问题标题】:Sending Excel Content as attachment using Microsoft Bot Framework in NodeJS在 NodeJS 中使用 Microsoft Bot Framework 将 Excel 内容作为附件发送
【发布时间】:2018-08-22 16:45:27
【问题描述】:

我正在尝试将我从 API 收到的 Excel 内容作为附件发送到机器人框架中。内容返回编码(附上示例照片)并且是内容类型:“application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”

我试过这样做:

oMsg.addAttachment({
            contentUrl:  `data:${xlsx.headers['content-type']};base64,${Buffer.from(xlsx.data).toString('base64')}`,
            contentType: xlsx.headers['content-type'],
            name: 'Opportunities.xlsx'
        });

我确实收到了来自机器人的回复,其中包含一个附件作为链接,但单击它绝对没有任何作用。有什么想法可以解决这个问题吗?

提前致谢。

【问题讨论】:

  • 我也尝试过不使用 base64 编码。它也不起作用。

标签: node.js botframework mime-types


【解决方案1】:

Botbuilder 不向用户提供此类可下载文件。但是,您可以在expressrestify 中构建一个额外的路由api 来提供下载功能。

你可以试试下面的代码sn-p:

let hostUrl = `http://localhost:3978`;
var bot = new builder.UniversalBot(connector, [
    (session) => {
        session.send({
            text:'downliad file',
            attachments: [{
                contentUrl: `${hostUrl}/xlsx`,
                name: 'test.xlsx'
            }]
        })
    }
]);


server.get('/xlsx', (req, res, next) => {
    const request = require('request');
    request.get(`<the excel api you get from>`).pipe(res);
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 2016-08-30
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2016-07-29
    相关资源
    最近更新 更多