-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathmessage.dart
More file actions
183 lines (160 loc) · 4.53 KB
/
Copy pathmessage.dart
File metadata and controls
183 lines (160 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
class ListTextDialogflow {
List<String> listText = [];
ListTextDialogflow(Map response) {
List<dynamic> listText = response['text']['text'];
listText.forEach((element) => this.listText.add(element));
}
}
class ImageDialogflow {
String imageUri;
String accessibilityText;
ImageDialogflow(Map response) {
this.imageUri = response['imageUri'];
this.accessibilityText = response['accessibilityText'];
}
}
class QuickReplies {
String title;
List<String> quickReplies = [];
QuickReplies(Map response) {
this.title = response['quickReplies']['title'];
List<dynamic> listQuickReplies = response['quickReplies']['quickReplies'];
listQuickReplies.forEach((element) => this.quickReplies.add(element));
}
}
class ButtonDialogflow {
String text;
String postback;
ButtonDialogflow(Map response) {
text = response['text'];
postback = response['postback'];
}
}
class CardDialogflow {
String title;
String subtitle;
String imageUri;
List<ButtonDialogflow> buttons = [];
CardDialogflow(Map response) {
this.title = response['card']['title'];
this.subtitle = response['card']['subtitle'];
this.imageUri = response['card']['imageUri'];
List<dynamic> listButtons = response['card']['buttons'];
for (int i = 0; i < listButtons.length; i++) {
ButtonDialogflow b = new ButtonDialogflow(listButtons[i]);
buttons.add(b);
}
}
}
class SimpleResponse {
String textToSpeech;
String ssml;
String displayText;
SimpleResponse(Map response) {
this.textToSpeech = response['textToSpeech'];
this.ssml = response['ssml'];
this.displayText = response['displayText'];
}
}
class SimpleResponses {
List<SimpleResponse> simpleResponses = [];
SimpleResponses(Map response) {
List<dynamic> listSimpleResponse =
response['simpleResponses']['simpleResponses'];
for (int i = 0; i < listSimpleResponse.length; i++) {
SimpleResponse b = new SimpleResponse(listSimpleResponse[i]);
simpleResponses.add(b);
}
}
}
class BasicCardDialogflow {
String title;
String subtitle;
String formattedText;
ImageDialogflow image;
List<dynamic> buttons;
BasicCardDialogflow(Map response) {
this.title = response['basicCard']['title'];
this.subtitle = response['basicCard']['subtitle'];
this.formattedText = response['basicCard']['formattedText'];
this.image = new ImageDialogflow(response['basicCard']['image']);
this.buttons = response['basicCard']['buttons'];
}
}
class ItemCarousel {
dynamic info;
String title;
String description;
ImageDialogflow image;
ItemCarousel(Map item) {
this.info = item['info'];
this.title = item['title'];
this.description = item['description'];
this.image = new ImageDialogflow(item['image']);
}
}
class CarouselSelect {
List<ItemCarousel> items = [];
CarouselSelect(Map response) {
List<dynamic> list = response['carouselSelect']['items'];
for (var i = 0; i < list.length; i++) {
items.add(new ItemCarousel(list[i]));
}
}
}
class MessageType {
final String value;
const MessageType._(this.value);
static const card = MessageType._('card');
static const basicCard = MessageType._('basicCard');
static const simpleResponses = MessageType._('simpleResponses');
static const carouselSelect = MessageType._('carouselSelect');
static const text = MessageType._("text");
static const map = MessageType._("map");
}
class TypeMessage {
final String platform;
final MessageType type;
final Object value;
TypeMessage(this.platform, this.type, this.value);
static TypeMessage fromJson(Map data) {
final platform = data['platform'] ?? "";
if (data.containsKey('card')) {
return TypeMessage(
platform,
MessageType.card,
CardDialogflow(data),
);
} else if (data.containsKey('basicCard')) {
return TypeMessage(
platform,
MessageType.basicCard,
BasicCardDialogflow(data),
);
} else if (data.containsKey('simpleResponses')) {
return TypeMessage(
platform,
MessageType.simpleResponses,
SimpleResponses(data),
);
} else if (data.containsKey('carouselSelect')) {
return TypeMessage(
platform,
MessageType.carouselSelect,
CarouselSelect(data),
);
} else if (data.containsKey("text")) {
return TypeMessage(
platform,
MessageType.text,
ListTextDialogflow(data),
);
} else {
return TypeMessage(
platform,
MessageType.map,
data,
);
}
}
}