How to add DF Messenger based custom payload in the ResponseMessage using Node.Js CX library?

273 views
Skip to first unread message

Alok Gupta

unread,
Oct 12, 2021, 5:31:03 PM10/12/21
to Dialogflow CX Edition users
Hi,

I am trying to create a page in a Flow using PagesClient.createPage() API (node.js client library "@google-cloud/dialogflow-cx") - https://googleapis.dev/nodejs/dialogflow-cx/latest/google.cloud.dialogflow.cx.v3beta1.Pages.html#createPage2

Is there an example that showcases how to add a payload in the ResponseMessage?

Thanks.

Alok Gupta

unread,
Oct 13, 2021, 1:51:54 PM10/13/21
to Dialogflow CX Edition users
Here is the page request. Can you let me know how to set the ResponseMessage payload in the createPageRequest?

    var createPageRequest = {
      parent: flowId,
      page: {
        displayName: 'Arbitration Clause Page',
        entryFulfillment: {
          messages: [
            {
              text: {
                  text: [
                      'Do you have to sign an arbitration agreement?'
                  ]
              }
            },
            {
              payload: {
                "richContent": [
                    [
                        {
                            "type": "chips",
                            "options": [
                                {
                                    "text": "Yes"
                                },
                                {
                                    "text": "No"
                                }
                            ]
                        }
                    ]
                ]
              }
            }
          ]
        }
      }
    };


Alok Gupta

unread,
Oct 14, 2021, 6:04:01 PM10/14/21
to Dialogflow CX Edition users
Here is the way to convert a JSON into google.protobuf.IStruct.

const {struct} = require('pb-util');
const structValue = struct.encode({
    "richContent": [
        ....
    ]
});
var createPageRequest = {
      parent: flowId,
      page: {
        displayName: 'Arbitration Clause Page',
        entryFulfillment: {
          messages: [
            {
              text: {
                  text: [
                      'Do you have to sign an arbitration agreement?'
                  ]
              }
            },
            {
              payload: structValue
            }
          ]
        }
      }
    };
}); 

Efim Muratov

unread,
Oct 15, 2021, 12:16:42 PM10/15/21
to Dialogflow CX Edition users
Kindly note that according to the group description its aim is to address general questions.

Since this question is of a technical nature, please refer to web forums such as Stack Overflow. If you have support plan with GCP, you may open a case via Google Cloud support console.
Reply all
Reply to author
Forward
0 new messages