LINEbotを使ってアンケートをとり回答毎に別々のメッセージと画像を送る

Google

1const SPREAD_SHEET_ID = "***************************"; 2const SHEET_NAME = "シート1" 3const ACCESS_TOKEN = "****************************"; 4 5const sheet = SpreadsheetApp.openById(SPREAD_SHEET_ID).getSheetByName(SHEET_NAME); 6const bot = new LineBotSdk.client(ACCESS_TOKEN); 7function doPost(e) { bot.call(e, callback) }; 8function callback(e) { 9 if (bot.bool(e, "message", "text")) { 10 // ユーザーがメッセージ送ってきた時、応答メッセージでアンケートを送る 11 question(e); 12 } else if (e.type == "follow") { 13 question(e); 14 } else if (e.type == "postback") { 15 const postbackData = e.postback.data; 16 if (["会員", "非会員"].includes(postbackData)) { 17 const cells = sheet.createTextFinder(e.source.userId).findAll(); 18 if (cells.length == 0) { 19 sheet.appendRow([e.source.userId, postbackData]); 20 } else { 21 cells[0].offset(0, 1).setValue(postbackData); 22 } 23 if (postbackData === "会員") { 24 bot.replyMessage(e, [bot.textMessage("ご回答ありがとうございます$$会員で登録しました$これから会員のお知らせを配信します$",[ 25 bot.emoji("5ac1bfd5040ab15980c9b435", "001"), 26 bot.emoji("5ac1bfd5040ab15980c9b435", "002"), 27 bot.emoji("5ac1bfd5040ab15980c9b435", "011"), 28 bot.emoji("5ac1bfd5040ab15980c9b435", "009"),])]); 29//↓ここから下のflex messageが出ない 30 const flex_message = { 31 "type": "bubble", 32 "body": { 33 "type": "box", 34 "layout": "vertical", 35 "contents": [ 36 { 37 "type": "image", 38 "url": "***********************", 39 "size": "full", 40 "aspectMode": "cover", 41 "aspectRatio": "1:1", 42 "gravity": "center" 43 }, 44 { 45 "type": "box", 46 "layout": "vertical", 47 "contents": [], 48 "position": "absolute", 49 "background": { 50 "type": "linearGradient", 51 "angle": "0deg", 52 "endColor": "#00000000", 53 "startColor": "#00000099" 54 }, 55 "width": "100%", 56 "height": "40%", 57 "offsetBottom": "0px", 58 "offsetStart": "0px", 59 "offsetEnd": "0px" 60 }, 61 { 62 "type": "box", 63 "layout": "horizontal", 64 "contents": [ 65 { 66 "type": "box", 67 "layout": "vertical", 68 "contents": [ 69 { 70 "type": "box", 71 "layout": "horizontal", 72 "contents": [] 73 }, 74 { 75 "type": "box", 76 "layout": "horizontal", 77 "contents": [] 78 } 79 ], 80 "spacing": "xs" 81 } 82 ], 83 "position": "absolute", 84 "offsetBottom": "0px", 85 "offsetStart": "0px", 86 "offsetEnd": "0px", 87 "paddingAll": "20px" 88 } 89 ], 90 "paddingAll": "0px" 91 } 92} 93 } 94 95 if (postbackData === "非会員") { 96 bot.replyMessage(e, [bot.textMessage(`ご回答ありがとうございます。$$非会員で登録しました$これから非会員のお知らせを配信します$`,[ 97 bot.emoji("5ac1bfd5040ab15980c9b435", "038"), 98 bot.emoji("5ac1bfd5040ab15980c9b435", "044"), 99 bot.emoji("5ac1bfd5040ab15980c9b435", "047"), 100 bot.emoji("5ac1bfd5040ab15980c9b435", "056"),])]); 101 } 102 } 103 } 104}; 105 106function question(e) { 107 bot.replyMessage(e, [bot.flexMessage({ 108 "type": "bubble", 109 "body": { 110 "type": "box", 111 "layout": "vertical", 112 "contents": [ 113 { 114 "type": "text", 115 "wrap": true, 116 "color": "#666666", 117 "size": "sm", 118 "text": "欲しい情報の会員種別を教えてください", 119 "weight": "bold", 120 "style": "italic", 121 "align": "center" 122 } 123 ] 124 }, 125 "footer": { 126 "type": "box", 127 "layout": "vertical", 128 "spacing": "sm", 129 "contents": [ 130 { 131 "type": "button", 132 "style": "primary", 133 "action": { 134 "type": "postback", 135 "label": "会員", 136 "data": "会員" 137 }, 138 "height": "sm", 139 "color": "#00008b" 140 }, 141 { 142 "type": "button", 143 "style": "secondary", 144 "height": "sm", 145 "action": { 146 "type": "postback", 147 "label": "非会員", 148 "data": "非会員" 149 }, 150 "color": "#ffff00" 151 }, 152 { 153 "type": "box", 154 "layout": "vertical", 155 "contents": [], 156 "margin": "sm" 157 } 158 ], 159 "flex": 0 160 } 161 })]); 162} 163

コメントを投稿

0 コメント