0

I have been trying to code a chat bot using Node.js, and integrate the app to Facebook. I ran into wit.ai and realized it would be easier to use it as a integration to node.js app.

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).

I used this: https://github.com/wit-ai/node-wit

halfer
  • 19,824
  • 17
  • 99
  • 186
eden1999
  • 11
  • 5

1 Answers1

0

You can use the below code for sending quick replies to 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;
            });
}
Nithin A
  • 374
  • 1
  • 2
  • 18