実現したいこと
LINEのリッチメニューで、ボタンを押したらプッシュメッセージにてアンケートを実施したい
発生している問題・分からないこと
右下のボタンを押しても何も動作しない
該当のソースコード
GAS
1function createRichMenuA() { 2 let richmenu = bot.richmenu({ 3 "name": "移住希望者A", 4 "barText": "←キーボード / メニュー", 5 "size": { "width": 2500, "height": 1686 }, 6 "selected": true, 7 "areas": [ 8 bot.area({ "x": 0, "y": 0, "width": 1250, "height": 220, 9 "action": bot.aSwitch({"aliasId": "switch-to-a", "data": "change to A"}) }), 10 bot.area({ "x": 1250, "y": 0, "width": 1250, "height": 220, 11 "action": bot.aSwitch({"aliasId": "switch-to-c", "data": "change to C"}) }), 12 13 bot.area({ "x": 0, "y": 220, "width": 2500, "height": 733, //真ん中横長・アンケート 14 "action": bot.aMessage({"text": "真ん中"}) }), 15 bot.area({ "x": 0, "y": 954, "width": 833, "height": 733, //左下・webページ 16 "action": bot.aUri({"uri": "https://ieno-osagari.studio.site/"}) }), 17 bot.area({ "x": 834, "y": 954, "width": 833, "height": 733, //真ん中下・webページ 18 "action": bot.aUri({"uri": "https://ieno-osagari.studio.site/"}) }), 19 bot.area({ "x": 1667, "y": 954, "width": 833, "height": 733, //右下・アンケート 20 "action": bot.aPostback({ 21 "data": "sendSurvey" 22 }) }), 23 ] 24 }); 25 26 let res = bot.createRichMenu(richmenu); 27 console.log("Rich menu created: " + res.toString()); 28} 29 30// Postbackイベントを処理する関数 31function handlePostback(event) { 32 console.log("Postback received: " + event.postback.data); 33 34 if (event.postback.data === "sendSurvey") { 35 sendSurvey(event); 36 } else if (event.postback.data.startsWith("answer-")) { 37 handleNextStep(event); 38 } 39} 40 41// アンケート用のプッシュメッセージを送信する関数 42function sendSurvey(event) { 43 console.log("Sending survey to: " + event.source.userId); 44 45 bot.pushMessage(event.source.userId, { 46 "type": "text", 47 "text": "あなたの移住希望地を選んでください。", 48 "quickReply": { 49 "items": [ 50 { 51 "type": "action", 52 "action": { 53 "type": "postback", 54 "label": "北海道", 55 "data": "answer-hokkaido" 56 } 57 }, 58 { 59 "type": "action", 60 "action": { 61 "type": "postback", 62 "label": "沖縄", 63 "data": "answer-okinawa" 64 } 65 }, 66 { 67 "type": "action", 68 "action": { 69 "type": "postback", 70 "label": "東京", 71 "data": "answer-tokyo" 72 } 73 }, 74 { 75 "type": "action", 76 "action": { 77 "type": "postback", 78 "label": "京都", 79 "data": "answer-kyoto" 80 } 81 } 82 ] 83 } 84 }); 85} 86 87// 次のステップに進む処理 88function handleNextStep(event) { 89 let uri = ''; 90 switch (event.postback.data) { 91 case 'answer-hokkaido': 92 uri = 'https://example.com/hokkaido'; // 北海道のURL 93 break; 94 case 'answer-okinawa': 95 uri = 'https://example.com/okinawa'; // 沖縄のURL 96 break; 97 case 'answer-tokyo': 98 uri = 'https://example.com/tokyo'; // 東京のURL 99 break; 100 case 'answer-kyoto': 101 uri = 'https://example.com/kyoto'; // 京都のURL 102 break; 103 } 104 105 if (uri) { 106 console.log("Redirecting to: " + uri); 107 bot.pushMessage(event.source.userId, { 108 type: 'text', 109 text: 'こちらのリンクをご覧ください。', 110 quickReply: { 111 items: [ 112 { 113 type: "action", 114 action: { 115 type: "uri", 116 label: "リンク先はこちら", 117 uri: uri 118 } 119 } 120 ] 121 } 122 }); 123 } 124} 125 126// メインイベントハンドラ 127function handleEvent(event) { 128 if (event.type === 'postback') { 129 handlePostback(event); 130 } else if (event.type === 'message' && event.message.type === 'text') { 131 handleResponse(event); // 他のメッセージイベントも処理する場合 132 } 133} 134 135// デバッグ用にログを追加 136console.log("Bot started and waiting for events..."); 137 138
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
該当の解決方法は見つかりませんでした
補足
GASでの実行、Webhook URL での認証は成功します
あなたの回答
tips
プレビュー