简体   繁体   English

为什么我在wit.ai中设置的快速回复却没有显示,当我使用Facebook Messenger与该聊天程序进行交谈时?

[英]Why are quick replies that I set in wit.ai, not showing when I used Facebook messenger to converse with the bot?

I have been trying to code a chat bot using Node.js, and integrate the app to Facebook. 我一直在尝试使用Node.js编写一个聊天机器人,并将该应用程序集成到Facebook。 I ran into wit.ai and realized it would be easier to use it as a integration to node.js app. 我遇到了wit.ai,并意识到将其用作与node.js应用程序的集成会更容易。

I downloaded Node.js wit.ai SDK and ran it using ngrok it worked well the bot is replying but the thing is the quick replies I set in wit.ai are not showing (quick replies are the choices buttons like yes or no). 我下载了Node.js wit.ai SDK,并使用ngrok运行了该程序,该程序在机器人答复方面表现良好,但问题是我在wit.ai中设置的快速答复没有显示(快速答复是选择按钮,例如yes或no)。

I used this: https://github.com/wit-ai/node-wit 我用了这个: https : //github.com/wit-ai/node-wit

You can use the below code for sending quick replies to fb. 您可以使用以下代码向fb发送快速回复。

var replyfunc = function()
{
    var quick_replies = ['a', 'b', 'c'];
            var qrArray = [];
            var text = "your text";
            for (var count in quick_replies) {
                var obj = {};
                obj.content_type = "text",
                    obj.title = quick_replies[count],
                    obj.payload = "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_" + quick_replies[count]

                qrArray.push(obj);
            }
            var body = JSON.stringify({
                recipient: { id },
                // message: { text },
                "message": {
                    "text": text,
                    "quick_replies": qrArray

                }
            });
sendResponse(body);
}
    var sendResponse = function (body) {

               const qs = 'access_token=' + encodeURIComponent(YOUR_FB_PAGE_TOKEN);
        return fetch('https://graph.facebook.com/me/messages?' + qs, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body,
        })
            .then(rsp => rsp.json())
            .then(json => {
                if (json.error && json.error.message) {
                    throw new Error(json.error.message);
                }
                return json;
            });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM