代码之家  ›  专栏  ›  技术社区  ›  Ashley

在NodeJS中使用Microsoft Bot框架将Excel内容作为附件发送

  •  0
  • Ashley  · 技术社区  · 8 年前


    Encoded content photo

    我试过这样做:

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

    我确实从机器人那里得到了一个回复,附件是一个链接,但是点击它什么也做不了。有什么办法可以解决这个问题吗?

    提前谢谢。

    1 回复  |  直到 8 年前
        1
  •  3
  •   Gary Liu    8 年前

    Botbuilder不向用户提供souch可下载文件。但是,您可以在 express 或 restify

    您可以尝试以下代码段:

    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);
    })
    
    推荐文章