-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Code.gs
69 lines (61 loc) · 1.34 KB
/
Code.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
/**
* Responds to an ADDED_TO_SPACE event
* in Google Chat.
*
* @param event the event object from Google Chat
* @return JSON-formatted response
*/
function onAddToSpace(event) {
console.info(event);
var message = "";
if (event.space.type === "DM") {
message = "Thank you for adding me to a DM, " +
event.user.displayName + "!";
} else {
message = "Thank you for adding me to " +
event.space.displayName;
}
return { "text": message };
}
/**
* Responds to a REMOVED_FROM_SPACE event
* in Google Chat.
*
* @param event the event object from Google Chat
*/
function onRemoveFromSpace(event) {
console.info(event);
console.info("Chat app removed from ", event.space.name);
}
/**
* Creates a card-formatted response.
*
* @param widgets the UI components to send
* @return JSON-formatted response
*/
function createCardResponse(widgets) {
return {
"cards": [
header,
{
"sections": [{
"widgets": widgets
}]
}]
};
}
/**
* Responds to a MESSAGE event triggered in Google Chat.
*
* @param event the event object from Google Chat
* @return JSON-formatted response
*/
function onMessage(event) {
var userMessage = event.message.text;
var widgets = [{
"textParagraph": {
"text": "You said: " + userMessage
}
}];
return createCardResponse(widgets);
}