Search…
Conversations

Conversations

In this section we will talk about how to send/receive messages from a Chatbot, the first step is the creation of the conversation, once you have the conversation Id you will be able to send a message to the Chatbot through a POST and to receive the message through A GET, while having the capacity to send context information through the body of the POST request as well.
Important: EDDI has a great feature for conversations with chatbots, it's the possibility to go back in time by using the two API endpoints : /undo and /redo !

Creating/initiating a conversation :

Create a Conversation with a Chatbot REST API Endpoint

Element
Tags
HTTP Method
POST
API endpoint
/bots/{environment}/{botId}
{environment}
(Path parameter):String Deployment environment (e.g: restricted,unrestricted,test)
{botId}
(Path parameter):String Id of the bot that you wish to start conversation with.

Response Model

1
{
2
"botId": "string",
3
"botVersion": Integer,
4
"userId": "string",
5
"environment": "string",
6
"conversationState": "string",
7
"redoCacheSize": 0,
8
"conversationOutputs": [
9
"input" : "string",
10
"expressions" : <arrayOfString>,
11
"intents" : <arrayOfString>,
12
"actions" : <arrayOfString>,
13
"httpCalls" : {JsonObject},
14
"properties" : <arrayOfString>,
15
"output" : "string"
16
],
17
"conversationProperties": {
18
"<nameOfProperty>" : {
19
"name" : "string",
20
"value" : "string" | {JsonObject},
21
"scope" : "string"
22
}},
23
"conversationSteps": [
24
{
25
"conversationStep": [
26
{
27
"key": "string",
28
"value": {}
29
}
30
],
31
"timestamp": "dateTime"
32
}
33
]
34
}
Copied!

Description of the Conversation response model

Element
Tags
botId
(String) The id of the bot that sent the reply.
botVersion
(integer) The version of the bot that sent the reply.
userId
(String) The id of the user who interacted with the bot.
environment
(String) the name of the environment where the bot is deployed
conversationState
(String) The state of the current conversation, could be:
READY,
IN_PROGRESS,
ENDED,
EXECUTION_INTERRUPTED,
ERROR
redoCount
(integer) if undo has been performed, this number indicates how many times redo can be done (=times undo has been triggered)
conversationOutputs
(Array: <conversationOutput>) Array of conversationOutput
conversationOutput.input
(String) The user's input.
conversationOutput.expressions
(Array: <String>) an array of the expressions involved in the creation of this reply (output).
conversationOutput.intents
(Array: <String>) an array of the intents involved in the creation of this reply (output).
conversationOutput.actions
(Array: <String>) an array of the actions involved in the creation of this reply (output).
conversationOutput.httpCalls
(Array: <JsonObject>) an array of the httpCalls objects involved in the creation of this reply (output).
conversationOutput.properties
(Array: <JsonObject>) the list of available properties in the current conversation.
conversationOutput.output
(String) The final bot's output
conversationProperties
(Array: <>) Array of conversationProperty, <nameOfProperty> is a dynamic value that represents the name of the property
<nameOfProperty>.name
(String) name of the property.
<nameOfProperty>.value
(String|JsonObject) value of the property.
<nameOfProperty>.scope
(String) scope can be
step (=valid one interaction [user input to user output]),
conversation (=valid for the entire conversation),
longTerm (=valid across conversations [based on given userId])
conversationSteps
(Array: <conversationStep>) Array of conversationStep.
Note conversationProperties can also be used in output templating e.g: [[${properties.city}]].

Sample Response

1
{
2
"botId": "5bf5418c46e0fb000b7636d0",
3
"botVersion": 10,
4
"userId": "anonymous-zj1p1GDtM5",
5
"environment": "unrestricted",
6
"conversationState": "READY",
7
"redoCacheSize": 0,
8
"conversationOutputs": [
9
{
10
"input": "madrid",
11
"expressions": "unknown(madrid)",
12
"intents": [
13
"unknown"
14
],
15
"actions": [
16
"current_weather_in_city"
17
],
18
"httpCalls": {
19
"currentWeather": {
20
"coord": {
21
"lon": -3.7,
22
"lat": 40.42
23
},
24
"weather": [
25
{
26
"id": 800,
27
"main": "Clear",
28
"description": "clear sky",
29
"icon": "01n"
30
}
31
],
32
"base": "stations",
33
"main": {
34
"temp": 10.86,
35
"pressure": 1019,
36
"humidity": 66,
37
"temp_min": 8.33,
38
"temp_max": 13.33
39
},
40
"visibility": 10000,
41
"wind": {
42
"speed": 5.7,
43
"deg": 240
44
},
45
"clouds": {
46
"all": 0
47
},
48
"dt": 1551735805,
49
"sys": {
50
"type": 1,
51
"id": 6443,
52
"message": 0.0049,
53
"country": "ES",
54
"sunrise": 1551681788,
55
"sunset": 1551723011
56
},
57
"id": 3117735,
58
"name": "Madrid",
59
"cod": 200
60
}
61
},
62
"properties": {
63
"currentWeather": {
64
"coord": {
65
"lon": -3.7,
66
"lat": 40.42
67
},
68
"weather": [
69
{
70
"id": 800,
71
"main": "Clear",
72
"description": "clear sky",
73
"icon": "01n"
74
}
75
],
76
"base": "stations",
77
"main": {
78
"temp": 10.86,
79
"pressure": 1019,
80
"humidity": 66,
81
"temp_min": 8.33,
82
"temp_max": 13.33
83
},
84
"visibility": 10000,
85
"wind": {
86
"speed": 5.7,
87
"deg": 240
88
},
89
"clouds": {
90
"all": 0
91
},
92
"dt": 1551735805,
93
"sys": {
94
"type": 1,
95
"id": 6443,
96
"message": 0.0049,
97
"country": "ES",
98
"sunrise": 1551681788,
99
"sunset": 1551723011
100
},
101
"id": 3117735,
102
"name": "Madrid",
103
"cod": 200
104
},
105
"city": "madrid"
106
},
107
"output": [
108
"The current weather situation of madrid is clear sky at 10.86 °C"
109
]
110
}
111
],
112
"conversationProperties": {
113
"city": {
114
"name": "city",
115
"value": "madrid",
116
"scope": "conversation"
117
}
118
},
119
"conversationSteps": [
120
{
121
"conversationStep": [
122
{
123
"key": "input:initial",
124
"value": "madrid"
125
},
126
{
127
"key": "actions",
128
"value": [
129
"current_weather_in_city"
130
]
131
},
132
{
133
"key": "output:text:current_weather_in_city",
134
"value": "The current weather situation of madrid is clear sky at 10.86 °C"
135
}
136
],
137
"timestamp": 1551736024776
138
}
139
]
140
}
Copied!
The conversationId will be provided through the location HTTP Header of the response, you will use that later to submit messages to the Chabot to maintain a conversation.

Example :

Request URL:
http://localhost:7070/bots/unrestricted/5ad2ab182de29719b44a792a
Response Body
no content
Response Code
201
Response Headers
1
{
2
"access-control-allow-origin": "*",
3
"date": "Sun, 15 Apr 2018 01:45:09 GMT",
4
"access-control-allow-headers": "authorization, Content-Type",
5
"content-length": "0",
6
"location": "eddi://ai.labs.conversation/conversationstore/conversations/5ad2aea52de29719b44a792c",
7
"access-control-allow-methods": "GET, PUT, POST, DELETE, PATCH, OPTIONS",
8
"access-control-expose-headers": "location",
9
"content-type": null
10
}
Copied!

Send/receive messages

Send a message

Send message in a conversation with a Chatbot REST API Endpoint

Element
Tags
HTTP Method
POST
API endpoint
/bots/{environment}/{botId}/{conversationId}
{environment}
(Path parameter):String Deployment environment (e.g: restricted,unrestricted,test)
botId
(Path parameter):String Id of the bot that you wish to continue a conversation with.
conversationId
(Path parameter): String Id of the conversation that you wish to send the message to.
returnDetailed
(Query parameter):Boolean - Default : false
returnCurrentStepOnly
(Query parameter):Boolean - Default : true
Request Body
JSON Object , example : { "input": "the message", "context": {} }
The context here is where you pass context variables that can be evaluated by EDDI, we will be explaining this in more details in Passing Context Information

Example :

Request URL
http://localhost:7070/bots/restricted/5aaf90e29f7dd421ac3c7dd4/5add1fe8a081a228a0588d1c?returnDetailed=false&returnCurrentStepOnly=true
Request Body
1
{
2
"input": "Hi!",
3
"context": {}
4
}
Copied!
Response Code
200
Response Body
1
{
2
"botId": "5aaf90e29f7dd421ac3c7dd4",
3
"botVersion": 1,
4
"environment": "restricted",
5
"conversationState": "READY",
6
"redoCacheSize": 0,
7
"conversationSteps": [
8
{
9
"conversationStep": [
10
{
11
"key": "input:initial",
12
"value": "Hi!"
13
}
14
],
15
"timestamp": 1524441253098
16
}
17
]
18
}
Copied!
Response Headers
1
{
2
"access-control-allow-origin": "*",
3
"date": "Sun, 22 Apr 2018 23:54:12 GMT",
4
"access-control-allow-headers": "authorization, Content-Type",
5
"content-length": "321",
6
"access-control-allow-methods": "GET, PUT, POST, DELETE, PATCH, OPTIONS",
7
"content-type": "application/json;resteasy-server-has-produces=true"
8
}
Copied!

Receive a message

Receive message in a conversation with a Chatbot REST API Endpoint

Element
Tags
HTTP Method
GET
API endpoint
/bots/{environment}/{botId}/{conversationId}
{environment}
(Path parameter):String Deployment environment (e.g: restricted,unrestricted,test)
{botId}
(Path parameter):String Id of the bot that you wish to continue a conversation with.
{conversationId}
(Path parameter): String Id of the conversation that you wish to receive a the message from.
returnDetailed
(Query parameter):Boolean - Default : false

Example

Request URL:
http://localhost:7070/bots/unrestricted/5aaf90e29f7dd421ac3c7dd4/5add1fe8a081a228a0588d1c?returnDetailed=false
Response Body
1
{
2
"botId": "5aaf90e29f7dd421ac3c7dd4",
3
"botVersion": 1,
4
"environment": "restricted",
5
"conversationState": "READY",
6
"redoCacheSize": 0,
7
"conversationSteps": [
8
{
9
"conversationStep": [
10
{
11
"key": "actions",
12
"value": [
13
"global_menu"
14
]
15
},
16
{
17
"key": "output:text:global_menu",
18
"value": "What do you want to do?"
19
},
20
{
21
"key": "quickReplies:global_menu",
22
"value": [
23
{
24
"value": "Show me your skillz",
25
"expressions": "confirmation(show_skills)",
26
"default": false
27
},
28
{
29
"value": "Tell me a joke",
30
"expressions": "trigger(tell_a_joke)",
31
"default": false
32
}
33
]
34
}
35
],
36
"timestamp": 1524441064450
37
},
38
{
39
"conversationStep": [
40
{
41
"key": "input:initial",
42
"value": "Hi!"
43
}
44
],
45
"timestamp": 1524441253098
46
}
47
]
48
}
Copied!
Response Code
200
Response Headers
1
{
2
"access-control-allow-origin": "*",
3
"date": "Mon, 23 Apr 2018 00:07:25 GMT",
4
"cache-control": "no-cache",
5
"access-control-allow-headers": "authorization, Content-Type",
6
"content-length": "891",
7
"access-control-allow-methods": "GET, PUT, POST, DELETE, PATCH, OPTIONS",
8
"content-type": "application/json"
9
}
Copied!

Undo and redo :

The undo and redo methods basically allow you to return a step back in a conversation, this is done by sending a POST along with bot and conversation ids to /bots/{environment}/{botId}/redo/{conversationId} endpoint, the GET call of the same endpoint with the same parameters will allow you to see if the last submitted undo/redo was successful by receiving a true or false in the response body.

Undo and redo in a conversation REST API Endpoint

Element
Tags
HTTP Method
POST
API endpoint
/bots/{environment}/{botId}/[undo/redo]/{conversationId}
{environment}
(Path parameter):String Deployment environment (e.g: restricted,unrestricted,test)
{botId}
(Path parameter):String Id of the bot that you wish to continue a conversation with.
{conversationId}
(Path parameter): String Id of the conversation that you wish to undo/redo the last conversation step.

Example (undo)

Request URL:
http://localhost:7070/bots/restricted/5aaf98e19f7dd421ac3c7de9/undo/5ade58dda081a23418503d6f
Response Body
no content
Response Code
200
Response Headers
1
{
2
"access-control-allow-origin": "*",
3
"date": "Mon, 23 Apr 2018 22:20:57 GMT",
4
"access-control-allow-headers": "authorization, Content-Type",
5
"content-length": "0",
6
"access-control-allow-methods": "GET, PUT, POST, DELETE, PATCH, OPTIONS",
7
"content-type": null
8
}
Copied!

Sample bot:

weather_bot_v2.zip
5KB
Binary
Weather-bot-v2.zip