Skip to content

Commit 533e0d7

Browse files
committed
Merge branch '857-webconnector-prevent-api-breakchanges'
2 parents 4d8478d + b6e1724 commit 533e0d7

7 files changed

+385
-36
lines changed

bot/connector-web/Swagger_TOCKWebConnector.yaml

+120-36
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,33 @@ info:
44
version: "1.0.0"
55
title: "Swagger Web Connector TOCK"
66
servers:
7-
- url: "https://demo-bot.tock.ai/io/[namespace]/demo/web"
7+
- url: "https://demo-bot.tock.ai/"
88
paths:
9-
/web:
9+
/{id}:
1010
post:
1111
summary: "Send query to the bot"
1212
description: ""
13+
requestBody:
14+
description: "Query to be sent with user ID"
15+
required: true
16+
content:
17+
application/json:
18+
schema:
19+
$ref: '#/components/schemas/Query'
1320
parameters:
14-
- in: "query"
15-
name: "body"
16-
description: "Query to be sent with user ID"
21+
- name: id
22+
in: path
23+
description: Connector path
1724
required: true
1825
schema:
19-
$ref: "#/components/schemas/Query"
26+
type: string
2027
responses:
2128
200:
2229
description: "OK"
2330
content:
2431
application/json:
2532
schema:
26-
oneOf:
27-
- $ref: "#/components/schemas/Text_Response"
28-
- $ref: "#/components/schemas/Card"
29-
- $ref: "#/components/schemas/Carousel"
33+
$ref: "#/components/schemas/Response"
3034
example:
3135
responses:
3236
- text: 'Welcome to the Chatbot :)'
@@ -40,6 +44,29 @@ paths:
4044
500:
4145
description: "Internal Server Error"
4246

47+
/{id}/sse:
48+
get:
49+
summary: "Stream bot responses for the given user"
50+
parameters:
51+
- name: id
52+
in: path
53+
description: Connector path
54+
required: true
55+
schema:
56+
type: string
57+
- name: userId
58+
in: query
59+
description: userId to stream
60+
required: true
61+
schema:
62+
type: string
63+
responses:
64+
200:
65+
description: "OK"
66+
content:
67+
application/json:
68+
schema:
69+
$ref: "#/components/schemas/Response"
4370

4471
components:
4572
schemas:
@@ -53,35 +80,88 @@ components:
5380
type: "string"
5481
example: "ID_00001"
5582

56-
Text_Response:
83+
Response:
5784
type: "object"
5885
properties:
5986
responses:
6087
type: "array"
6188
items:
62-
$ref: "#/components/schemas/Text"
89+
$ref: "#/components/schemas/Message"
6390

64-
Text:
91+
Message:
6592
type: "object"
66-
required: ["text"]
93+
required: ["version"]
6794
properties:
6895
text:
6996
type: "string"
7097
example: "Welcome to the Chatbot :)"
7198
buttons:
72-
type: "array"
73-
items:
74-
$ref: "#/components/schemas/Button"
99+
$ref: '#/components/schemas/Buttons'
100+
card:
101+
$ref: "#/components/schemas/Card"
102+
carousel:
103+
$ref: '#/components/schemas/Carousel'
104+
widget:
105+
$ref: "#/components/schemas/Widget"
106+
version:
107+
type: "string"
108+
example: "1"
75109

76-
Button:
110+
Buttons:
111+
type: "array"
112+
items:
113+
oneOf:
114+
- $ref: "#/components/schemas/PostBack"
115+
- $ref: "#/components/schemas/QuickReply"
116+
- $ref: "#/components/schemas/UrlButton"
117+
discriminator:
118+
propertyName: type
119+
mapping:
120+
postback: '#/components/schemas/PostBack'
121+
quick_reply: '#/components/schemas/QuickReply'
122+
web_url: '#/components/schemas/UrlButton'
123+
124+
PostBack:
77125
type: "object"
126+
required: ["title", "type"]
78127
properties:
79128
title:
80129
type: "string"
81130
example: "Help me on Topic 1"
82131
payload:
83132
type: "string"
84133
example: "helpTopic1?_previous_intent=greetings"
134+
type:
135+
type: "string"
136+
example: "postback"
137+
138+
QuickReply:
139+
type: "object"
140+
required: ["title", "type"]
141+
properties:
142+
title:
143+
type: "string"
144+
example: "Choice Topic 1"
145+
payload:
146+
type: "string"
147+
example: "choiceTopic1?_previous_intent=greetings"
148+
type:
149+
type: "string"
150+
example: "quick_reply"
151+
152+
UrlButton:
153+
type: "object"
154+
required: ["title", "url", "type"]
155+
properties:
156+
title:
157+
type: "string"
158+
example: "Help me on Topic 1"
159+
url:
160+
type: "string"
161+
example: "http://www.sncf.com"
162+
type:
163+
type: "string"
164+
example: "web_url"
85165

86166
Carousel:
87167
type: "object"
@@ -101,28 +181,32 @@ components:
101181
type: "string"
102182
example: "subTitle"
103183
file:
104-
type: "object"
105-
properties:
106-
url:
107-
type: "string"
108-
example: "http://url1.fr/image1.jpg"
109-
name:
110-
type: "string"
111-
example: "name"
112-
type:
113-
type: "string"
114-
example: "image"
115-
actions:
116-
type: array
117-
items:
118-
$ref: "#/components/schemas/Actions"
184+
$ref: '#/components/schemas/File'
185+
buttons:
186+
$ref: "#/components/schemas/Buttons"
119187

120-
Actions:
188+
File:
121189
type: "object"
190+
required: ["url", "name", "type"]
122191
properties:
123-
title:
192+
url:
193+
type: "string"
194+
example: "http://url1.fr/image1.jpg"
195+
name:
196+
type: "string"
197+
example: "name"
198+
type:
199+
type: "string"
200+
example: "image"
201+
202+
Widget:
203+
type: "object"
204+
required: ["data", "type"]
205+
properties:
206+
data:
207+
type: "object"
208+
type:
124209
type: "string"
125-
example: "Action1"
126210

127211
externalDocs:
128212
description: "TOCK Documentation"

bot/connector-web/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
<version>${assertj}</version>
5656
<scope>test</scope>
5757
</dependency>
58+
<dependency>
59+
<groupId>org.junit.jupiter</groupId>
60+
<artifactId>junit-jupiter-engine</artifactId>
61+
<scope>test</scope>
62+
</dependency>
5863

5964
</dependencies>
6065

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import ai.tock.bot.connector.media.MediaFile
2+
import ai.tock.bot.connector.web.WebConnectorResponse
3+
import ai.tock.bot.connector.web.WebMessage
4+
import ai.tock.bot.connector.web.send.PostbackButton
5+
import ai.tock.bot.connector.web.send.QuickReply
6+
import ai.tock.bot.connector.web.send.UrlButton
7+
import ai.tock.bot.connector.web.send.WebCard
8+
import ai.tock.bot.connector.web.send.WebCarousel
9+
import ai.tock.bot.engine.action.SendAttachment
10+
import ai.tock.shared.jackson.mapper
11+
import ai.tock.shared.resourceAsStream
12+
import com.fasterxml.jackson.module.kotlin.readValue
13+
import org.assertj.core.api.Assertions
14+
import org.junit.jupiter.api.Test
15+
16+
internal class WebConnectorResponseTest {
17+
18+
@Test
19+
fun `text only`() {
20+
val expected = WebConnectorResponse(
21+
responses = listOf(
22+
WebMessage(text = "Text only")
23+
)
24+
)
25+
val deserializedEvent = mapper.readValue<WebConnectorResponse>(resourceAsStream("/text_only.json"))
26+
Assertions.assertThat(deserializedEvent).isEqualTo(expected)
27+
}
28+
29+
@Test
30+
fun `text with buttons`() {
31+
val expected = WebConnectorResponse(
32+
responses = listOf(
33+
WebMessage(
34+
text = "Text with Buttons",
35+
buttons = listOf(
36+
PostbackButton(
37+
title = "title",
38+
payload = "payload"
39+
),
40+
QuickReply(
41+
title = "title",
42+
payload = "payload",
43+
imageUrl = null
44+
),
45+
UrlButton(
46+
title = "title",
47+
url = "http://www.sncf.com"
48+
)
49+
)
50+
)
51+
52+
)
53+
)
54+
val deserializedEvent = mapper.readValue<WebConnectorResponse>(resourceAsStream("/text_with_buttons.json"))
55+
Assertions.assertThat(deserializedEvent).isEqualTo(expected)
56+
}
57+
58+
@Test
59+
fun `web card with buttons`() {
60+
val expected = WebConnectorResponse(
61+
responses = listOf(
62+
WebMessage(
63+
card = WebCard(
64+
title = "title",
65+
subTitle = "subTitle",
66+
file = MediaFile(
67+
url = "http://www.sncf.com/image.png",
68+
name = "imageName",
69+
type = SendAttachment.AttachmentType.image
70+
),
71+
buttons = listOf(
72+
PostbackButton(
73+
title = "title",
74+
payload = "payload"
75+
),
76+
UrlButton(
77+
title = "title",
78+
url = "http://www.sncf.com"
79+
)
80+
)
81+
)
82+
)
83+
)
84+
)
85+
val deserializedEvent = mapper.readValue<WebConnectorResponse>(resourceAsStream("/card_with_buttons.json"))
86+
Assertions.assertThat(deserializedEvent).isEqualTo(expected)
87+
}
88+
89+
@Test
90+
fun `carousel with two cards and one button`() {
91+
val expected = WebConnectorResponse(
92+
responses = listOf(
93+
WebMessage(
94+
text = "carousel with two cards and one button",
95+
carousel = WebCarousel(
96+
cards = listOf(
97+
WebCard(
98+
title = "item 1",
99+
subTitle = "subtitle 1",
100+
file = MediaFile(
101+
url = "http://www.sncf.com/image1.png",
102+
name = "imageName 1",
103+
type = SendAttachment.AttachmentType.image
104+
),
105+
buttons = listOf(
106+
PostbackButton(
107+
title = "choice item 1",
108+
payload = "payload"
109+
)
110+
)
111+
),
112+
WebCard(
113+
title = "item 2",
114+
subTitle = "subtitle 2",
115+
file = MediaFile(
116+
url = "http://www.sncf.com/image2.png",
117+
name = "imageName 2",
118+
type = SendAttachment.AttachmentType.image
119+
),
120+
buttons = listOf(
121+
PostbackButton(
122+
title = "choice item 2",
123+
payload = "payload"
124+
)
125+
)
126+
)
127+
)
128+
),
129+
buttons = listOf(
130+
PostbackButton(
131+
title = "refresh",
132+
payload = "payload"
133+
)
134+
)
135+
)
136+
)
137+
)
138+
val deserializedEvent = mapper.readValue<WebConnectorResponse>(resourceAsStream("/carousel_with_2_cards_and_1_button.json"))
139+
Assertions.assertThat(deserializedEvent).isEqualTo(expected)
140+
}
141+
142+
}

0 commit comments

Comments
 (0)