【问题标题】:Why are quick replies that I set in wit.ai, not showing when I used Facebook messenger to converse with the bot?为什么我在 wit.ai 中设置的快速回复在我使用 Facebook Messenger 与机器人交谈时没有显示?
【发布时间】:2017-12-29 22:48:46
【问题描述】:

我一直在尝试使用 Node.js 编写聊天机器人,并将应用程序集成到 Facebook。我遇到了 wit.ai,并意识到将它用作 node.js 应用程序的集成会更容易。

我下载了 Node.js wit.ai SDK 并使用 ngrok 运行它运行良好,机器人正在回复,但问题是我在 wit.ai 中设置的快速回复没有显示(快速回复是选择按钮,例如是或没有)。

我用过这个:https://github.com/wit-ai/node-wit

【问题讨论】:

    标签: javascript node.js facebook facebook-messenger wit.ai


    【解决方案1】:

    您可以使用以下代码向 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;
                });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 2017-04-15
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多