0

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?

data_henrik
  • 16,724
  • 2
  • 28
  • 49
wnm3
  • 381
  • 3
  • 17

1 Answers1

2

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.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
  • I tried adding context:{ "session_id":" $system.session_id ?>" } but this results in null when using the Try it. The other settings in the json work so I believe the session_id is not in the context.system. Looking at what is returned to the Preview webpage does show the session_id as a peer to output but we don't have access to it. Not sure how to debug what is happening between the Assistant (Agent) and the Skill. – wnm3 Apr 11 '19 at 22:15
  • The session_id is only present if the interface is using the V2 API. The "Try it" is old and IMHO based on V1. The new preview and other integrations seem to be based on V2 API and hence have it. – data_henrik Apr 12 '19 at 05:24