Search code examples
phpcurlibm-cloudwatson-conversationwatson-assistant

Watson Assistant CURL API: How to send follow up message?


I'm trying out IBM Watson Assistant. Ultimate goal is to integrate it with my custom PHP backend, via it's Watson Assistant's cURL API Endpoints (because there's no complete PHP SDK yet).

Let me tell what I did so far:

  1. Imported a sample Workspace from a Training Data Set.
  2. Then I tried this, and it works fine.

enter image description here

  1. Then I tried that exact same thing via cURL API, I got a response like this: (The json output format beautified)

.

{
  "intents": [
    {
      "intent": "locate_amenity",
      "confidence": 0.999901008605957
    }
  ],
  "entities": [
    {
      "entity": "amenity",
      "location": [
        7,
        10
      ],
      "value": "gas",
      "confidence": 1
    }
  ],
  "input": {
    "text": "i need some gas"
  },
  "output": {
    "text": [
      "Hi. It looks like a nice drive today. What would you like me to do?  "
    ],
    "nodes_visited": [
      "Start And Initialize Context"
    ],
    "log_messages": []
  },
  "context": {
    "conversation_id": "153c18ee-1015-4b6a-ae04-789e29bf4a05",
    "system": {
      "dialog_stack": [
        {
          "dialog_node": "root"
        }
      ],
      "dialog_turn_counter": 1,
      "dialog_request_counter": 1,
      "_node_output_map": {
        "Start And Initialize Context": [
          0,
          0
        ]
      },
      "branch_exited": true,
      "branch_exited_reason": "completed"
    },
    "AConoff": "off",
    "lightonoff": "off",
    "musiconoff": "off",
    "appl_action": "",
    "heateronoff": "off",
    "volumeonoff": "off",
    "wipersonoff": "off",
    "default_counter": 0,
    "previous_cuisine": "",
    "previous_restaurant_date": "",
    "previous_restaurant_time": ""
  }
}

Now please let me understand 2 things here.

Question (1)

At this point, I was expecting the API to return with a message:

"There are gas stations nearby. Which one would you like to drive to?"

But why it doesn't. If then, how do I achieve it?

Question (2)

How do I properly reply back with "Go to number 5." so that the API understands I'm referring to the previous Call? (aka) How to I continue the dialog flow? (Note: I tried sending back with the previous "contexts", "entities", "intents", but it is somehow still recognised as a new message.)

Please share me an example of cURL call to follow up the previous message.


Since there's no complete PHP SDK yet, it is very hard for me to understand just by the cURL API calls. API Documentation does not explain to that details too. Please help.

Thank you all.


Solution

  • The message API for Watson Assistant is stateless. Everything that is needed to process a request is submitted as parameters. This includes the message itself, but also the context. The context holds the state about where in the dialog tree the conversation is. It could also hold information that is transferred from WA to the app, e.g., to process a client-side action. Or from the app to WA, e.g., with a record from a database.

    Coming to your request:

    • Your dialog probably sends out that reponse when a new conversation is started. I see it is the same as in the "Try it out".
    • You would need to send a "Hi" or empty message first, wait for the reponse from WA, then send your "I need gas" together with the context data you received from WA. WHen you look into the details, you see the dialog stack, turn counter and more. The conversation ID is the identifier for that current chat.
    • With the above, WA's next response should be exactly like in the "Try it out" because you went down in the dialog tree.