问题
The V2 APIs for IBM Watson Assistant ask that you get a session_id and then use it in subsequent calls to the Assistant in order for global context values to be preserved across calls. Looking at the Preview link webpage we associated with our Assistant, it appears the request contains both a value object containing all the expected parts of the payload for a Skill, and a session_id.
I would like to access this session_id in my skill to pass it along to cloud functions that may want to leverage the V2 API's for Skills in their URI's. Is this possible? In other words, what would one reference in the Skills JSON content to gain access to the session_id value?
I am assuming the Preview link results in use of V2 API's to the Assistant (it appears there is an intermediary serving the Preview Link webpage and making requests to the actual Assistant) and I'm further assuming that setting context.global values in my Skill will cause them to be echoed back by the Assistant since the Preview Link should reuse the session_id?
How can a Skill provide feedback to the Assistant that the session_id can be deleted (e.g., the conversation has ended) forcing the Preview link webpage to gain access to a new session_id?
回答1:
You can access context variables using either context[variableName]
or $variableName
. See the documentation on expressions for accessing objects in IBM Watson Assistant.
The session_id, if present (this depends on the interface), is part of the system variables (context.system.session_id
). I just tried accessing and printing it in the preview by adding the following response text:
My session ID: <? $system.session_id ?>
The <? ?>
is used to evaluate the expression within in the text.
I tested it with the V2 API in my conversation tool and the session ID is nicely printed as response.
来源:https://stackoverflow.com/questions/55601154/ibm-watson-assistant-how-can-skill-gain-access-to-session-id-using-v2-of-wa-api