Node.js 如何使用Microsoft Bot Framework和Facebook Messenger发送富文本卡?

Node.js 如何使用Microsoft Bot Framework和Facebook Messenger发送富文本卡?,node.js,botframework,facebook-messenger,botconnector,Node.js,Botframework,Facebook Messenger,Botconnector,我正在使用Facebook Messenger平台和Microsoft Bot Framework创建一个发送富文本附件的Bot 到目前为止,我已尝试在我的意图文件中使用通用模板: messageData = { "attachment": { "type": "template", "payload": { "template_type

我正在使用Facebook Messenger平台和Microsoft Bot Framework创建一个发送富文本附件的Bot

到目前为止,我已尝试在我的意图文件中使用通用模板:

messageData = {
                "attachment": {
                    "type": "template",
                    "payload": {
                        "template_type": "generic",
                        "elements": [{
                            "title": "First card",
                            "subtitle": "Element #1 of an hscroll",
                            "image_url":     "http://messengerdemo.parseapp.com/img/rift.png",
                            "buttons": [{
                                "type": "web_url",
                                "url": "https://www.messenger.com",
                                "title": "web url"
                            }, {
                                "type": "postback",
                                "title": "Postback",
                                "payload": "Payload for first element in a generic bubble",
                            }],
                        }, {
                            "title": "Second card",
                            "subtitle": "Element #2 of an hscroll",  
                            "buttons": [{
                                "type": "postback",
                                "title": "Postback",
                            }],
                        }]
                    }
                }
            }
            return resolve([toCard(messageData)])
        }
    })
})
}


const toText = message => {return {type: 'text', content: message }}
const toCard = message => {return {type: 'attachment', content: message}}
我的index.js中还有一个sendMessageByType函数,它应该根据从各种意图收到的响应类型发送消息

 const sendMessageByType = {
     text: (session, elem) => session.send(elem.content),
     attachment: (session, elem) => session.send(elem.content)
 }
调用上述函数,如下所示:

 .then(res => { res.forEach( (message) => sendMessageByType[message.type](session, message)) })

我尝试过将类型更改为文本、卡片和附件,但都不起作用。正确的类型是什么?如何声明它以便发送卡?

因此,经过大量的尝试和错误,并阅读了这里的文档:,我找到了如何实现这一点的方法。本质上,使用的类型是附件,发送富卡的正确方式如下:

attachment: (session, elem) => session.send(new builder.Message(session).sourceEvent(elem.content))

因此,经过大量的尝试和错误,并阅读了这里的文档:,我想出了如何使这项工作。本质上,使用的类型是附件,发送富卡的正确方式如下:

attachment: (session, elem) => session.send(new builder.Message(session).sourceEvent(elem.content))

谢谢你回答你自己的问题,巴德:)这也帮了我的忙!谢谢你回答你自己的问题,巴德:)这也帮了我的忙!