回答編集履歴

3

ごみ削除

2022/07/08 14:18

投稿

draq
draq

スコア2573

test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  - LINE Messaging API
36
36
  ```JavaScript
37
- function sendWithMessaging(replyToken, message) {
37
+ function sendWithMessaging() {
38
38
  const token = "(チャネルアクセストークン)";
39
39
  const to = "U......."; //宛先ユーザID
40
40
 

2

説明とサンプルを追加

2022/07/08 14:13

投稿

draq
draq

スコア2573

test CHANGED
@@ -1 +1,90 @@
1
- urlがLINE notify なのにペイロードがLINE Messaging APIになってるからじゃないでしょうか。
1
+ URL LINE Notify なのにペイロードが LINE Messaging API になってるからじゃないでしょうか。
2
+
3
+ ---
4
+ - LINE Notify API は、テキストメッセージと画像、スタンプぐらいしか使えないが割と簡単です。
5
+ Flex Messageは使えません。
6
+ - LINE Messaging API は、ちょっと複雑な代わりに LINE Notify より自由度が高いです。
7
+
8
+ お好きなほうをどうぞ。一応動作確認した簡単なサンプルを置いておきます。
9
+
10
+ - LINE Notify
11
+ ```JavaScript
12
+ function sendWithNotify() {
13
+ const token = "(LINE Notify のパーソナルアクセストークン)";
14
+
15
+ const message = "テストメッセージ with LINE Notify";
16
+
17
+ const endpoint = "https://notify-api.line.me/api/notify";
18
+ const options = {
19
+ headers: {
20
+ "Content-Type": "application/x-www-form-urlencoded",
21
+ Authorization: "Bearer " + token
22
+ },
23
+ method: "post",
24
+ muteHttpExceptions: true,
25
+ payload: "message=" + encodeURIComponent(message)
26
+ };
27
+
28
+ const res = UrlFetchApp.fetch(endpoint, options);
29
+ if (res.getResponseCode() !== 200) {
30
+ throw new Error(res.getContentText());
31
+ }
32
+ }
33
+ ```
34
+
35
+ - LINE Messaging API
36
+ ```JavaScript
37
+ function sendWithMessaging(replyToken, message) {
38
+ const token = "(チャネルアクセストークン)";
39
+ const to = "U......."; //宛先ユーザID
40
+
41
+ const sampleFlexMessage = {
42
+ "type": "bubble",
43
+ "body": {
44
+ "type": "box",
45
+ "layout": "vertical",
46
+ "contents": [
47
+ {
48
+ "type": "text",
49
+ "text": "Brown Cafe",
50
+ "weight": "bold",
51
+ "size": "xl"
52
+ },
53
+ {
54
+ "type": "text",
55
+ "text": "Miraina Tower, 4-1-6 Shinjuku, Tokyo",
56
+ "wrap": true,
57
+ "color": "#666666",
58
+ "size": "sm",
59
+ "flex": 5
60
+ }
61
+ ]
62
+ }
63
+ };
64
+
65
+ const endPoint = "https://api.line.me/v2/bot/message/push";
66
+ const payload = {
67
+ to,
68
+ messages: [{
69
+ "type": "flex",
70
+ "altText": "sample flex message",
71
+ "contents": sampleFlexMessage
72
+ }]
73
+ };
74
+
75
+ const options = {
76
+ headers: {
77
+ "Content-Type": "application/json; charset=UTF-8",
78
+ Authorization: "Bearer " + token
79
+ },
80
+ method: "post",
81
+ muteHttpExceptions: true,
82
+ payload: JSON.stringify(payload)
83
+ };
84
+
85
+ const res = UrlFetchApp.fetch(endPoint, options);
86
+ if (res.getResponseCode() !== 200) {
87
+ throw new Error(res.getContentText());
88
+ }
89
+ }
90
+ ```

1

スペルミスの修正

2022/07/07 23:58

投稿

draq
draq

スコア2573

test CHANGED
@@ -1 +1 @@
1
- urlがLINE notufy なのにペイロードがLINE Messaging APIになってるからじゃないでしょうか。
1
+ urlがLINE notify なのにペイロードがLINE Messaging APIになってるからじゃないでしょうか。