Prakash J
Prakash J

Reputation: 3

dialogflow quick reply for Facebook client

When I'm trying to send a response from Node app to Dialogflow using webhook for Facebook messenger client.

Trying to send a quick reply to the Facebook client, however, it is not working and getting the bellow error.

Error: Reply string required by Suggestion constructor

Any help will be appreciated.

const {Suggestion} = require('dialogflow-fulfillment');
agent.add(new Suggestion().setReply('test reply from NodeApp'));

Upvotes: 0

Views: 772

Answers (1)

Jyothish G
Jyothish G

Reputation: 26

First, you need to update the version of dialogflow-fulfillment package in the package.json file in the inline editor to ^0.6.1 which is the latest one.

Then, I think you can just send quick replies using the statement:

agent.add(new Suggestion(`sample reply`));

Please remember there should have a text response before the replies for Facebook to accept the response object.

Below is a snippet that may help you better.

const {Suggestion} = require('dialogflow-fulfillment');
agent.add(`This is quick reply.`);
agent.add(new Suggestion(`option 1`));
agent.add(new Suggestion(`option 2`));

The above way will work if you are using the Dialogflow Inline Editor as the fulfillment.

If not (i.e, opt to have your own deployment/development environment), you have to send the quick replies as custom payloads within the fulfillment code. (Here also, you have to upgrade the dialogflow-fulfillment package first)

Here is a sample code snippet:

const {Payload} = require("dialogflow-fulfillment")
var payload = {
  "facebook": {
    "text": "Welcome to my agent!",
    "quick_replies": [
      {
        "content_type": "text",
        "payload": "reply1",
        "title": "reply 1"
      }
    ]
  }
}
agent.add(new Payload(agent.UNSPECIFIED, payload, {rawPayload: true, sendAsMessage: true}))

Hope these will work for you.

Upvotes: 1

Related Questions