Microsoft BotFramework: How to send raw JSON message to channels?

隐身守侯 提交于 2019-12-11 04:54:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!