DialogFlow CX - Data stores with custom payload

Hi I am new to DialogFlow CX. I am trying to develop a chatbot based on a data store from Search & Conversation.

The chatbot works fine and sends me a text and a rich context as the response. However, I need to define a custom payload for my use case.

I know the text can be accessed using $request.knowledge.answers[0]. However, I am not sure how to access the information inside the richcontext. (actionLink, title, etc.).

Here is a simplified version of my custom payload.

{
  "blocks": [
    {
      "type": "section"
      "text": {
        "type": "plain_text",
        "text": "$request.knowledge.answers[0]"
      },
    },
    {
      "type": "section",
      "text": {
        "type": "plain_text"
        "text": "link: ??? ",
      }
    }
  ]
}

Thank you in advance for your help! :slightly_smiling_face:

3 Likes

that is a great question, I will tag here @alessiasacchi just in case she knows the answer.

Best,

Xavi

1 Like

@xavidop Thanks for your reply.

As an update, I found out one can retrieve the data using $request.knowledge.sources[0]. This returns a JSON file as follows. However, I can not access the lower levels.
For example,
$request.knowledge.sources[0].uri returns nothing. Am I accessing it wrongly, or is it a bug?

This issue makes this kind of useless since I still can not use this variable directly in my custom payload and must somehow process the text in an additional step.

{
  "uri":
    "https://storage.cloud.google.com/XYZ File name.pdf#page\\u003d13",
  "snippet":
    "The text.",
  "title":
    "File name"
}
1 Like

Hi @hamidma did you try to access this from a webhook?

I would suggest to debug this in a webhook so you can see what is in the payload, create your custom payload and return it.

Keep me posted please! I am curious!

Best,

Xavi

Interesting – it’s worth noting that you can access these fields from within a generator attached to a data store. In the generator prompt, I have the instructions then "The response to be reworded is: $request " – when I do that, I get prompted in the dialog to map $request to something. “$request.knowledge.answers[0]” works as expected. But, as you noted, “$request.knowledge.sources[0].uri” or any variation on it does not work.

Hi @xavidop

Thanks for the suggestion.
Actually, I defined a cloud function to reformat the payload before sending it to Slack, and it works! However, due to this extra intermediate step, the bot is a bit slower now, and the usage cost is higher due to the cloud function.

So, I see it as a workaround and not the final solution, and I still believe it would be nice to be able to retrieve the data stores response through a variable (e.g., $request.knowledge.sources[0].uri) and use it directly in a custom payload.

Regards

I totally agree with you!

I would highly encourage you to open a support ticket to ask this. Please keep me posted!

Xavi

that is a great question, I will tag here @alessiasacchi just in case she knows the answer.

Best,

Xavi

Solution:

Google Cloud support suggested I use system functions to retrieve the fields:

https://cloud.google.com/dialogflow/cx/docs/reference/system-functions#func-get

After a bit of investigation, I found out that the URI and title fields could be extracted from request.knowledge.sources using the following:

$sys.func.GET_FIELD($sys.func.GET($request.knowledge.sources[0], 0), “uri”)

$sys.func.GET_FIELD($sys.func.GET($request.knowledge.sources[0], 0), “title”)

Thank you, @xavidop and @harlanh , for your input on this issue.

Regards,

Hamid

2 Likes

wow! this is huge! thanks for sharing!

2 Likes

Were you able to put these together as an embedded link?

1 Like

Yes, if you keep it simple. However, you can’t do complicated data validation and extraction, so I ended up using a cloud function to do the whole thing for me.

1 Like

Hi hamidma, can you please share the cloud function and the steps for webhook and custom payload. I am new to DialogFlow CX and unable to show Data Store with the response on Df-messenger in UI