I'm trying to get the context variables that I made in Watson Conversation Dialogs in my Unity project. I am able to get the whole JSON dialog to show up in Unity, get the intents, entities and output text from the json file. So instead of getting the output:{ text[] out of the json file, I'm trying to get the context:{ variable:value out of the JSON file but I can't get my head around how.
This is the JSON file for the welcome dialog node where i want to read the destination_city variable out of to set it equal to an Unity variable/string.
{
"context": {
"date": null,
"time": null,
"hotel": null,
"DateEnd": null,
"DateBegin": null,
"PeriodDate": null,
"numberKids": null,
"roomsHotel": null,
"PeriodNumber": null,
"numberAdults": 0,
"departure_city": null,
"transportation": null,
"destination_city": "London",
"kidDiscountRepeat": null
},
"output": {
"text": {
"values": [
"Hello, this is the Watson Travel agency."
],
"selection_policy": "sequential"
}
}
}
And this is part of the code I have in Unity to get a response from Watson conversation and show the whole JSON file for that dialog node:
void HandleMessageCallback (object resp, Dictionary customData)
{ object _tempContext = null; (resp as Dictionary ).TryGetValue("context", out _tempContext);
if (_tempContext != null)
conversationContext = _tempContext as Dictionary<string, object>;
Dictionary<string, object> dict = Json.Deserialize(customData["json"].ToString()) as Dictionary<string, object>;
// load output --> text;answer from Json node
Dictionary <string, object> output = dict["output"] as Dictionary<string, object>;
List<object> text = output["text"] as List<object>;
string answer = text[0].ToString();
Debug.Log("WATSON | Conversation output: \n" + answer);
//======== Load $ context variable attempts =============================
Debug.Log("JSON INFO: " + customData["json"].ToString());
//=====================================
if (conversationOutputField != null)
{
conversationOutputField.text = answer;
}