Engine API
Session Management
The client applications maintain a session with the engine to allow the engine to remember details between requests by the users. The engine handles sessions as follows:
- When a request comes in that does not contain session details, a new session will be created on the server. The session ID will be included in the JSON response and as a cookie in the response header.
- If the response contains the header
X-Gateway-Session
then the next request must include the headerX-Teneo-Session
with the value 'JSESSIONID=session_ID' followed by ';' and the value received from the X-Gateway-Session header.
- To maintain a dialogue in the same session, the next request of the client should include the session ID received in the response, and in responses where the X-Gateway-Session header was present, the X-Teneo-Session header is required.
- The engine will expire the session, after 10 minutes of inactivity. All details stored in the session will be forgotten.
- If a request comes in with a session ID that is expired or unknown, the engine will create a new empty session and include the new session ID in the response.
When using the SDK's, session maintenance is usually not something you have to worry about, as it is handled by the SDK. If you don't make use of the SDK's, you should make sure the session cookie received from the engine is included in the request header. The way to do this depends on the language used. In Node.js, for example, this could be achieved as follows:
javascript
1https.get({
2 host: 'https://some.teneo',
3 path: 'engine-url/?viewtype=tieapi&userinput=What%20time%20is%20it%3F&usertimezone=CEST',
4 method: 'POST',
5 headers: {
6 'Cookie': 'JSESSIONID=31992FA776A35DABA3291A4EE1031B5F',
7 // If the response header X-Gateway-Session is set
8 'X-Teneo-Session': 'JSESSIONID=31992FA776A35DABA3291A4EE1031B5F' // Followed by ';' and the value of X-Gateway-Session
9 }
10}, function(response) {
11 // handle response
12});
13
Ending a session
The best practice is to end sessions when possible, e.g. by closing the bot's window in Teneo Web Chat. If the session is not ended, the engine will automatically expire sessions after 10 minutes of inactivity by default.
You can end session by appending endsession
to the engine URL. Make sure the session cookie and X-Teneo-Session header (when the X-Gateway-Session header is present in responses) is included in the request, as the engine won't know which session to end otherwise.
Example request
curl -X POST \
https://some.teneo/engine-url/endsession \
-H 'Content-Type: application/x-www-form-urlencoded'
Example response
json
1{
2 "status" : 1,
3 "message" : "logout"
4}
5