回答編集履歴

3

 

2022/04/01 23:19

投稿

退会済みユーザー
test CHANGED
@@ -4,7 +4,7 @@
4
4
  ただし、ファイルのパーミッションを公開設定にする必要があるようです。
5
5
  下記の
6
6
  ```
7
- // 共有設定と画像URL取得
7
+ // パーミッション設定と画像取得
8
8
  fileImage.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
9
9
  ```
10
10
  の部分です。
@@ -40,7 +40,7 @@
40
40
  } else {
41
41
  if (questionTitle == "添付画像") {
42
42
  const fileImage = DriveApp.getFileById(answer);
43
- // 共有設定と画像URL取得
43
+ // パーミッション設定と画像取得
44
44
  fileImage.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
45
45
  blob = fileImage.getBlob();
46
46
  continue;

2

 

2022/04/01 23:02

投稿

退会済みユーザー
test CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  詳細は下記を参照:
13
13
  https://qiita.com/Qnoir/items/9048cbb08e0ca3297306
14
-
14
+
15
15
  ---
16
16
 
17
17
  コードを直すとすれば下記のようになるでしょうか。

1

追記

2022/04/01 22:45

投稿

退会済みユーザー
test CHANGED
@@ -1,7 +1,82 @@
1
1
  LINE Notify APIのドキュメント(Messaging APIではありません)によると、 imageFile プロパティにファイルを指定することでアップロードできます。
2
2
  https://notify-bot.line.me/doc/ja/
3
3
 
4
- ただし、パーミッションを公開設定にする必要があります。
4
+ ただし、ファイルのパーミッションを公開設定にする必要があるようです。
5
+ 下記の
6
+ ```
7
+ // 共有設定と画像URL取得
8
+ fileImage.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
9
+ ```
10
+ の部分です。
5
11
 
6
- 詳細は下記記事を参照:
12
+ 詳細は下記を参照:
7
13
  https://qiita.com/Qnoir/items/9048cbb08e0ca3297306
14
+
15
+ ---
16
+
17
+ コードを直すとすれば下記のようになるでしょうか。
18
+ (元の質問のコメントその他のコードはほぼ残してあります)
19
+ ```js
20
+ function autoLine(e) {
21
+ /* ステップ1: フォームのデータを取得する */
22
+ //すべての質問と回答を取得する
23
+ let itemResponses = e.response.getItemResponses();
24
+
25
+ /* ステップ2: 必要なデータを抽出する */
26
+ //個々の質問と回答を格納するための空配列を宣言する
27
+ let questionAndAnswers = [];
28
+ let blob = null;
29
+ //for文(ループ)で変数itemResponsesから個々の質問と回答を取得する
30
+ for(let i = 0; i < itemResponses.length; i++) {
31
+ //質問のタイトルを取得する
32
+ let questionTitle = itemResponses[i].getItem().getTitle();
33
+
34
+ //回答を取得する
35
+ let answer = itemResponses[i].getResponse();
36
+
37
+ //未回答の質問かどうかで送信文章を調整する
38
+ if(!answer) {
39
+ questionAndAnswers.push(questionTitle + ": 未回答");
40
+ } else {
41
+ if (questionTitle == "添付画像") {
42
+ const fileImage = DriveApp.getFileById(answer);
43
+ // 共有設定と画像URL取得
44
+ fileImage.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
45
+ blob = fileImage.getBlob();
46
+ continue;
47
+ }
48
+ questionAndAnswers.push("≪" + questionTitle + "≫\n" + answer + "\n");
49
+ }
50
+ }
51
+
52
+ /* ステップ3: 宛先、本文を決める */
53
+ //LINEの宛先
54
+ //★★★LINE Notifyのトークンを入力してください★★★
55
+ let token = "LINEトークンを入れています";
56
+
57
+ //LINEの本文
58
+ //★★★お好きな本文に変更ください★★★
59
+ let body = "\n状況報告書フォームの回答を受信しました。\n"
60
+ + "\n"
61
+ //一次元配列questionAndAnswersに対してjoinメソッドを使って文字列を作成する
62
+ //区切り文字は改行"\n"
63
+ + questionAndAnswers.join("\n");
64
+
65
+ /* ステップ4: 管理者にLINEを送信する */
66
+ //管理者にLINEを送信する
67
+ sendLine(token, body, blob);
68
+ }
69
+
70
+ function sendLine(token, body, blob) {
71
+ let options =
72
+ {
73
+ "method" : "post",
74
+ "payload" : {"message": body,
75
+ "imageFile" : blob,
76
+ },
77
+ "headers" : {"Authorization" : "Bearer "+ token}
78
+ };
79
+
80
+ UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
81
+ }
82
+ ```