简体   繁体   中英

Passing variables into Watson Dialog

In many situations, it may be helpful to pass known information (eg the user's name to present a personalized greeting) into a new Watson Dialog conversation so to avoid asking the user redundant or unnecessary questions. In looking at the API documentation, I don't see a way to do that. Is there a best practice method for passing variables into a Watson Dialog conversation?

In the Dialog service a variable is part of a profile that you create to store information that users provide during conversations.

The following code shows an example of a profile variable that saves the user's name.

<variables>
    <var_folder name="username">
        <var name="username" type="TEXT" description="The user's name."></var>
    </var_folder>
</variables>

In your scenario you will set this variable by calling:

PUT /v1/dialogs/{dialog_id}/profile

with:

{
  "client_id": 4435,
  "name_values": [
    {
      "name": "username",
      "value": "Bruce Wayne"
    }
  ]
}

Don't forget to replace {dialog_id} and {client_id} .


We have an API Explorer that let you try-out the APIs: Dialog API Explorer .
You can also read more about this in this tutorial .

It should also be noted that if you leave the client_id out then one is allocated for you. You can then pass this in to the start conversation call to make sure the that the profile is picked up. I found this useful where I have welcome messages which I want to imbed profile variables in to eg "Hello "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM