2

i try to send custom payload in Dialogflow from fulfillment(nodejs)

My motive is send link and its text as response to web page.

my sample code for reference:

  const response = {
      messages: [
        {
          payload: {
            messages: [
              {
                speech: 'here are some quick links for your convenience.',
                linkmessage: [{
                  message: 'google',
                  link: 'www.google.com'
                }, {
                  message: 'yahoo',
                  link: 'www.yahoo.co.in'
                }],
                button: [{
                  buttonname: 'more page'
                }]
              }
            ]
          }
        }
      ]
    };
    agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));

Here i get the response as:

{
    "fulfillment": {
      "speech": "",
      "messages": [
        {
          "lang": "en",
          "type": 0,
          "speech": ""
        }
      ],
      "data": {
        "null": {
          "messages": [
            {
              "payload": {
                "messages": [
                  {
                    "speech": "here are some quick links for your convenience.",
                    "linkmessage": [{
                      "message": "google",
                      "link": "www.google.com"
                    }, {
                      "message": "yahoo",
                      "link": "www.yahoo.co.in"
                    }],
                    "button": [{
                      "buttonname": "more page"
                    }]
                  }
                ]
              }
            }
          ]
        }
      }
    }

Here you can see in response i am getting "null" object is appended inside the data object in the response.

can any one help me out to remove that null object from dialogflow response, and any other option for sending custom payload from fulfillment nodejs.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Can you clarify where you're seeing this response? It doesn't look like either a [WebhookResponse](https://cloud.google.com/dialogflow/docs/reference/rpc/google.cloud.dialogflow.v2#webhookresponse) or any part of a [DetectIntentResponse](https://cloud.google.com/dialogflow/docs/reference/rest/v2/DetectIntentResponse). I think we can explain what's going on, but want to make sure I'm talking about the right thing. – Prisoner Apr 24 '20 at 11:57
  • Actually i am writing custom web chatbot on my own using Angular. There in my web page i am getting this response. @Prisoner – Elangovan Eaaswaramurty Apr 24 '20 at 12:43
  • So this is being delivered from a call to DetectIntent? Or does this come from something else? (Can you show the code that is making the call that gets this result?) – Prisoner Apr 24 '20 at 14:45
  • I am writing a custom payload from node in fulfillment part, that showed in reference code in the question part. @Prisoner – Elangovan Eaaswaramurty Apr 27 '20 at 03:50
  • How are you calling Dialogflow and where are you seeing this response? Can you show the code that is making the call to Dialogflow and show the code that is showing you this response? – Prisoner Apr 27 '20 at 09:24
  • Bro actually got the solution on this. digging more information on surfing. Thanks @Prisoner for your wonderful time to help me solving this issue – Elangovan Eaaswaramurty Apr 27 '20 at 09:43
  • Great! StackOverflow encourages you to add an **answer** yourself so others with a similar problem can learn. – Prisoner Apr 27 '20 at 09:57
  • Updated my answer, thanks a lot @Prisoner – Elangovan Eaaswaramurty Apr 28 '20 at 05:55

1 Answers1

3
function update() {
const response = {
      messages: [
        {
          payload: {
            messages: [
              {
                speech: 'here are some quick links for your convenience.',
                linkmessage: [{
                  message: 'google',
                  link: 'www.google.com'
                }, {
                  message: 'yahoo',
                  link: 'www.yahoo.co.in'
                }],
                button: [{
                  buttonname: 'more page'
                }]
              }
            ]
          }
        }
      ]
    };
    agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
}

In this function need to add parameter as agent so that you can get non 'null' object

Reference code need to be updated.

function update(agent) {
const response = {
      messages: [
        {
          payload: {
            messages: [
              {
                speech: 'here are some quick links for your convenience.',
                linkmessage: [{
                  message: 'google',
                  link: 'www.google.com'
                }, {
                  message: 'yahoo',
                  link: 'www.yahoo.co.in'
                }],
                button: [{
                  buttonname: 'more page'
                }]
              }
            ]
          }
        }
      ]
    };
    agent.add(new Payload(agent.UNSPECIFIED, response, { rawPayload: true, sendAsMessage: true}));
}