forked from googleworkspace/gws-odo-addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integrationTypeService.gs
236 lines (195 loc) · 6.44 KB
/
integrationTypeService.gs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
* @fileoverview Code related to information that the Odo Add-on
* may show in various contexts if the chosen integration type is
* INTEGRATION_TYPE.GENERIC_SERVICE
*/
/**
* Function used to return the record data as a formatted Card to be
* displayed. Called from integrationTypeAll.gs as a context specific
* handler for this integration.
*
* @param {string} Calling context (i.e. CALL_CONTEXT.GMAIL_VIEW)
*
* @return {CardService.Card}
*/
function buildServiceBasicCard(context) {
let config = getConfig();
let integrationData;
// if there is previously stored data for this integration type,
// display it. else, show the default values.
if (
config.saved &&
config.integrationType === INTEGRATION_TYPE.GENERIC_SERVICE
) {
integrationData = config.integrationData;
} else {
integrationData = serviceBasicGetDefaultConfig();
}
let buttonUrl = integrationData.buttonUrl;
let message = integrationData.message;
let buttonText = integrationData.buttonText;
buttonUrl = findAndReplaceMergeKeys(buttonUrl, { uriEncodeValue: true });
message = findAndReplaceMergeKeys(message);
buttonText = findAndReplaceMergeKeys(buttonText);
let card = CardService.newCardBuilder();
let brandedHeader = buildCustomerBrandedHeader();
card.setHeader(brandedHeader);
let section = CardService.newCardSection();
section.addWidget(CardService.newTextParagraph().setText(message));
section.addWidget(
CardService.newTextButton()
.setText(buttonText)
.setOpenLink(CardService.newOpenLink().setUrl(buttonUrl))
);
let button2Url = integrationData.button2Url;
let message2 = integrationData.message2;
let button2Text = integrationData.button2Text;
if (button2Text && button2Url) {
button2Url = findAndReplaceMergeKeys(button2Url, { uriEncodeValue: true });
button2Text = findAndReplaceMergeKeys(button2Text);
if (message2) {
message2 = findAndReplaceMergeKeys(message2);
section.addWidget(CardService.newTextParagraph().setText(message2));
}
section.addWidget(
CardService.newTextButton()
.setText(button2Text)
.setOpenLink(CardService.newOpenLink().setUrl(button2Url))
);
}
card.addSection(section);
return card.build();
}
/**
* Creates and returns the card that gives the user options to configure
* the Service integration. Called from integrationTypeAll.gs based on the
* value of the 'buildConfigureIntegrationCard' parameter.
*
* @return {CardService.Card}
*/
function buildServiceBasicConfigureCard() {
let config = getConfig();
let integrationData;
integrationData = getConfigIntegrationData(INTEGRATION_TYPE.GENERIC_SERVICE);
/*
if (
config.saved &&
config.integrationType === INTEGRATION_TYPE.GENERIC_SERVICE
) {
integrationData = config.integrationData;
} else {
integrationData = serviceBasicGetDefaultConfig();
}
*/
let buttonUrl = integrationData.buttonUrl;
let message = integrationData.message;
let buttonText = integrationData.buttonText;
let button2Url = integrationData.button2Url;
let message2 = integrationData.message2;
let button2Text = integrationData.button2Text;
let card = CardService.newCardBuilder();
let section = CardService.newCardSection();
let input;
section.addWidget(CardService.newTextParagraph().setText('Primary Button:'));
input = CardService.newTextInput()
.setFieldName('message')
.setTitle('Message')
.setValue(message);
section.addWidget(input);
input = CardService.newTextInput()
.setFieldName('buttonText')
.setTitle('Button Text')
.setValue(buttonText);
section.addWidget(input);
input = CardService.newTextInput()
.setFieldName('buttonUrl')
.setTitle('Button URL')
.setValue(buttonUrl);
section.addWidget(input);
section.addWidget(
CardService.newTextParagraph().setText('<br><br>Optional Secondary Button:')
);
input = CardService.newTextInput()
.setFieldName('message2')
.setTitle('Message 2')
.setValue(message2);
section.addWidget(input);
input = CardService.newTextInput()
.setFieldName('button2Text')
.setTitle('Button 2 Text')
.setValue(button2Text);
section.addWidget(input);
input = CardService.newTextInput()
.setFieldName('button2Url')
.setTitle('Button 2 URL')
.setValue(button2Url);
section.addWidget(input);
card.addSection(section);
return card;
}
/**
* Function that gets called for this particular integration when user
* clicks '← Done' button in integration configuration card. Saves the
* selections and returns them as an object to be stored in the
* 'integrationData' field of the config object if/when the user saves their
* configurations.
*
* This is the handler that's defined as
* 'saveConfigureIntegrationSelections' in integrationTypeAll.gs.
*
* @param {object} formInputs - Contains user selections
*
* @return {object}
*/
function saveServiceBasicConfigureSelections(formInputs) {
let message = formInputs['message'].stringInputs.value[0];
let buttonText = formInputs['buttonText'].stringInputs.value[0];
let buttonUrl = formInputs['buttonUrl'].stringInputs.value[0];
let message2 = '';
let button2Text = '';
let button2Url = '';
if (formInputs['message2']) {
message2 = formInputs['message2'].stringInputs.value[0];
}
if (formInputs['button2Text']) {
button2Text = formInputs['button2Text'].stringInputs.value[0];
}
if (formInputs['button2Url']) {
button2Url = formInputs['button2Url'].stringInputs.value[0];
}
let integrationData = {
message: message,
buttonText: buttonText,
buttonUrl: buttonUrl,
message2: message2,
button2Text: button2Text,
button2Url: button2Url,
};
return integrationData;
}
/**
* Function that returns default configuration fields and values for
* an integration type of INTEGRATION_TYPE.GENERIC_SERVICE, to be stored
* as the 'integrationData' field in 'config'. Called when setting
* up default configuration.
*
* @return {Object}
*/
function serviceBasicGetDefaultConfig() {
return {
message:
'Click the button below to launch a ' +
'{{toolName}} session ' +
'with <b>{{token || participants}}</b>.',
buttonText: 'Launch {{toolName}}',
// note: any merge tags in the buttonUrl will get URI encoded
buttonUrl:
THIRD_PARTY_SERVICE_URL +
'?loadingMessage=Loading%20' +
'{{toolName}}%20with%20' +
'{{token || participants}}',
message2: '',
button2Text: '',
button2Url: '',
};
}