Node.js 在NodeJS中使用Microsoft Bot Framework将Excel内容作为附件发送
我正在尝试将从API接收的Excel内容作为bot框架中的附件发送。内容经过编码后返回(附示例照片),内容类型为:“application/vnd.openxmlformats officedocument.spreadsheetml.sheet”Node.js 在NodeJS中使用Microsoft Bot Framework将Excel内容作为附件发送,node.js,botframework,mime-types,Node.js,Botframework,Mime Types,我正在尝试将从API接收的Excel内容作为bot框架中的附件发送。内容经过编码后返回(附示例照片),内容类型为:“application/vnd.openxmlformats officedocument.spreadsheetml.sheet” 我试着这样做: oMsg.addAttachment({ contentUrl: `data:${xlsx.headers['content-type']};base64,${Buffer.from(xlsx.data)
我试着这样做:
oMsg.addAttachment({
contentUrl: `data:${xlsx.headers['content-type']};base64,${Buffer.from(xlsx.data).toString('base64')}`,
contentType: xlsx.headers['content-type'],
name: 'Opportunities.xlsx'
});
我确实从机器人那里得到了一个带有附件作为链接的响应,但是点击它绝对没有任何作用。有没有办法解决这个问题
提前感谢。Botbuilder不向用户提供souch可下载文件。但是,您可以在
express
或restify
中构建额外的路由api,以提供下载功能
您可以尝试以下代码段:
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);
})
让主机URL=`http://localhost:3978`;
var bot=新的builder.UniversalBot(连接器[
(会议)=>{
session.send({
文本:'download file',
附件:[{
contentUrl:`${hostUrl}/xlsx`,
名称:“test.xlsx”
}]
})
}
]);
server.get('/xlsx',(req,res,next)=>{
const request=require('request');
获取(``)管道(res);
})
Botbuilder不向用户提供可下载的文件。但是,您可以在express
或restify
中构建额外的路由api,以提供下载功能
您可以尝试以下代码段:
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);
})
让主机URL=`http://localhost:3978`;
var bot=新的builder.UniversalBot(连接器[
(会议)=>{
session.send({
文本:'download file',
附件:[{
contentUrl:`${hostUrl}/xlsx`,
名称:“test.xlsx”
}]
})
}
]);
server.get('/xlsx',(req,res,next)=>{
const request=require('request');
获取(``)管道(res);
})
我也尝试过不使用base64编码。它也不起作用。我也尝试过不使用base64编码。它也不起作用。