実現したいこと
Line Messaging APIでメッセージを送る際に単独で送りたいときは単独で、
複数送りたい時には複数送りたいと考えています。
発生している問題・分からないこと
text2に何も入れていないときにはtext1のみ送信して欲しいのですが
sendLineMessageFromUserId(userId, text1, text2)を他の関数で実行した際
Exception: Request failed for https://api.line.me returned code 400. Truncated server response: {"message":"The request body has 1 error(s)","details":[{"message":"May not be empty","property":"messages[1].text"}]} (use muteHttpExceptions option to examine full response)
となってしまいます。
ソースコードのreturn send~の部分は他の関数内の部分です。
該当のソースコード
function sendLineMessageFromUserId(userId, text1, text2) { var url = "https://api.line.me/v2/bot/message/push"; const payload = { "to": userId, "messages": [ { "type": "text", "text": text1 }, { "type": "text", "text": text2 } ] }; const params = { "method": "post", "contentType": "application/json", "headers": headers, "payload": JSON.stringify(payload) }; return UrlFetchApp.fetch(url, params); } return sendLineMessageFromUserId(userId, remindText,);
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
return sendLineMessageFromUserId(userId, remindText,);
を
return sendLineMessageFromUserId(userId, remindText,"あ");
にしたところ
remindTextの内容と「あ」が送信されてきました。
sendLineMessageFromUserId(userId, text1, text2 = "い")で
return sendLineMessageFromUserId(userId, remindText);
にしたところ
remindTextの内容と「い」が送信されてきました。
補足
特になし

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。