如何处理从Facebook sourceEvent botframework节点的回发 [英] How to handle postback from Facebook sourceEvent botframework node

查看:132
本文介绍了如何处理从Facebook sourceEvent botframework节点的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以如标题中提到的,我需要弄清楚如何处理用户点击/点击facebook信使中的按钮的回发。我知道这张卡可以使用机器人制造商卡处理,但还有一些其他要测试的元素。请参阅以下代码:

So as mentioned in the title I need to figure out how to handle a postback from the user tapping/clicking a button in facebook messenger. I'm aware this card can be handled with a bot builder card but there are some other elements I want to test too. Please see the following code:

bot.dialog('/', [
function (session) {
    var msg = new builder.Message(session).sourceEvent({
            facebook: {
                    notification_type: "REGULAR",
                    attachment: {
                        type: "template",
                        payload: {
                            template_type: "generic",
                            elements: [{
                                title: "Title here",
                                image_url: "http://docs.botframework.com/images/demo_bot_image.png",
                                subtitle: "Subtitle here",
                                buttons: [{
                                    type: "postback",
                                    title: "GO",
                                    payload: "dosomething"
                                }]
                            }]
                        }
                    }
                }
        });
    session.send(msg);
},
function(session, results){
    session.send(JSON.stringify(results));
    session.send(JSON.stringify(session));
}
]);

所以基本上一旦用户点击GO按钮,我想在节点中执行另一个对话框,卡片工作,但我只是不知道如何处理它。我认为它可能与瀑布工作,但显示的代码没有返回任何东西。

So basically once the user clicks the 'GO' button I want to action another dialog in node, the card works but I just don't know how to handle it. I thought it might work with the waterfall but the shown code didn't return anything.

非常感谢,

推荐答案

所以我把我的头从云里解开了,回答了我自己的问题。线索是按钮类型: type:postback

So I've pulled my head out of the clouds and answered my own question. The clue was in the button type: type: "postback".

请参阅以下内容:

bot.dialog('/', [
    function (session) {
        var msg = new builder.Message(session).sourceEvent({
                facebook: {
                        notification_type: "REGULAR",
                        attachment: {
                            type: "template",
                            payload: {
                                template_type: "generic",
                                elements: [{
                                    title: "Great title",
                                    image_url: "http://docs.botframework.com/images/demo_bot_image.png",
                                    subtitle: "Even better subtitle",
                                    buttons: [{
                                        type: "postback",
                                        title: "GO",
                                        payload: "action?stacktest"
                                    }]
                                }]
                            }
                        }
                    }
            });
        session.send(msg);
    }
]);

所以我所做的一切都是发回了stacktest操作,并使用以下内容处理它:

So all I've done is posted back the action 'stacktest' and handled it with the following:

bot.beginDialogAction('stacktest', '/stacktest');
bot.dialog('/stacktest', function(session){
    session.send("Woot, stacktest worked a treat.");
});

希望这有助于某人。

干杯。

这篇关于如何处理从Facebook sourceEvent botframework节点的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆