我正在使用 Facebook Messenger Platform 和 Microsoft Bot Framework 创建一个发送富文本附件的机器人。
到目前为止,我已经尝试在我的意图文件中使用通用模板:
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)) })
我尝试将类型更改为文本、卡片和附件,但都没有奏效。什么是正确的使用类型以及如何声明它以便发送卡?