-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathline.gs
127 lines (121 loc) · 3.21 KB
/
line.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
// 参考ページ
// API method: https://developers.line.biz/ja/reference/messaging-api/#get-narrowcast-progress-status
// メッセージ作成: https://developers.line.biz/flex-simulator/
function parseEvent(request){
//LINE Messaging APIのチャネルアクセストークンを設定
// WebHookで取得したJSONデータをオブジェクト化し、取得
let eventData = JSON.parse(request.postData.contents).events[0];
return eventData
}
function requestLineAPI(method,url,payload){
const options = {
'payload' : JSON.stringify(payload),
'myamethod' : method,
'headers' : {"Authorization" : "Bearer " + PropertiesService.getScriptProperties().getProperty("LineToken")},
'contentType' : 'application/json'
};
log(JSON.stringify(payload))
var resp = UrlFetchApp.fetch(url, options);
}
// ユーザからのメッセージへ返信
function replyMessage(replyToken,messages){
requestLineAPI(
"POST",
"https://api.line.me/v2/bot/message/reply",
{
'replyToken': replyToken,
'messages': messages,
},
)
}
// 全てのユーザへメッセージを送信
function sendToAllUser(messages){
requestLineAPI(
"POST",
"https://api.line.me/v2/bot/message/broadcast",
{
'messages': messages,
},
)
}
function generateMessage(message){
return{
"type":"text",
"text":message,
}
}
function generateTasksMessage(tasks){
var bubbles = []
const colors = ["#BBFFFF","#FFDDFF","#FFFFDD","#EEEEEE"]
for(const index in tasks){
bubbles.push(generateTaskBubble(tasks[index],colors[index % colors.length]))
}
return{
"type": "flex",
"altText": "This is a Flex Message",
"contents": {
"type": "carousel",
"contents": bubbles,
}
}
}
function generateTaskBubble(task,color){
const deadline = task.deadline.toLocaleDateString('en-us', { weekday:"long", year:"numeric", month:"short", day:"numeric"})
const createdAt = task.createdAt.toLocaleDateString('en-us', { weekday:"long", year:"numeric", month:"short", day:"numeric"})
return {
"type": "bubble",
"size": "deca",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": task.title,
"color": "#000000",
"align": "center",
"size": "md",
"gravity": "center"
}
],
"backgroundColor": color,
"paddingTop": "19px",
"paddingAll": "12px",
"paddingBottom": "16px"
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"color": "#8C8C8C",
"size": "xxs",
"wrap": true,
"text": "deadline: " + deadline,
},
{
"type": "text",
"color": "#8C8C8C",
"size": "xxs",
"wrap": true,
"text": "createdAt: "+ createdAt,
}
],
"flex": 1
}
],
"spacing": "md",
"paddingAll": "12px"
},
"styles": {
"footer": {
"separator": false
}
}
}
}