问题
I'm using Node.js and BotBuilder v3.1.1.
Previously, we had Session.sendMessage();
that we could use to send raw data to the channel we are connected with.
That proved useful for quick testing and using new features that aren't implemented on the library yet.
How can I do this on the current version v3, since the sendMessage method was removed?
回答1:
I think this is what your after, as I was looking for something similar myself. What's needed is sourceEvent which is replacing channelData. I'm aware this card can be made by the builder but for an example it works fine.
bot.dialog('/', [
function (session) {
var msg = new builder.Message(session).sourceEvent({
facebook: {
notification_type: "REGULAR",
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [{
title: "Some Title",
image_url: "http://docs.botframework.com/images/demo_bot_image.png",
subtitle: "Some amazing subtitle",
buttons: [{
type: "postback",
title: "GO",
payload: "demo"
}]
}]
}
}
}
});
session.send(msg);
}
]);
Works great for Facebook, at least in my tests. One thing I'm struggling with is how to handle the postback from the button in node.
Update: So I answered my own secondary question about the postback here.
Cheers,
来源:https://stackoverflow.com/questions/38490287/microsoft-botframework-how-to-send-raw-json-message-to-channels