Ashley
Ashley

Reputation: 432

Sending Excel Content as attachment using Microsoft Bot Framework in NodeJS

I am attempting to send Excel content that I receive from an API as an attachment in the bot framework. The content comes back encoded (sample photo attached) and is content-type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Encoded content photo

I tried doing this:

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

And I do get a response from the bot with an attachment as a link, but clicking it does absolutely nothing. Any ideas how I can fix this?

Thanks in advance.

Upvotes: 0

Views: 773

Answers (1)

Gary Liu
Gary Liu

Reputation: 13918

Botbuilder dosen't provide souch downloadable file to user. However, you can build an additional route api in express or restify to provied the download feature.

You can try the following code snippet:

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

Upvotes: 3

Related Questions