【目的】
地域の連絡用に公式LINEを準備したいと考えている初心者です。
下記のページの実装を行いましたが、添付ファイルのようなエラーが表示されました。
チャンネルアクセストークンを再設定したりしましたが、うまくいきません。なぜか教えていただけないでしょうか。
ページ:「複合リッチメニューの実装」https://mainichi-ippo.com/gas5/
コード
//参考:https://mainichi-ippo.com/gas5/
const bot = new LineBotSdk.client(PropertiesService.getScriptProperties().getProperty('LINEb_TOKEN'));
function createRichMenuA() {
let richmenu = bot.richmenu({
"name": "オリジナルリッチメニュー",
"barText": "メニュー",
"size": { "width": 2500, "height": 1686 },
"selected": true,
"areas": [
bot.area({ "x": 0, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-a", "data": "change to A"}) }),
bot.area({ "x": 833, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-b", "data": "change to B"}) }),
bot.area({"x": 1667, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-c", "data": "change to C"}) }),
bot.area({ "x": 0, "y": 337, "width": 833, "height": 674,
"action": bot.aMessage({"text": 'アンケート' }) }),
bot.area({ "x": 833, "y": 337, "width": 833, "height": 674,
"action": bot.aMessage({"text": 'つかいかた' }) }),
bot.area({"x": 1667, "y": 337, "width": 833, "height": 674,
"action": bot.aMessage({"text": "コミュニティバス"}) }),
bot.area({ "x": 0, "y": 1011, "width": 833, "height": 674,
"action": bot.aMessage({"text": "閲覧"}) }),
bot.area({ "x": 833, "y": 1011, "width": 833, "height": 674,
"action": bot.aMessage({"text": "ごみ収集日一覧"}) }),
bot.area({"x": 1667, "y": 1011, "width": 833, "height": 674,
"action": bot.aMessage({"text": "イベントカレンダー"}) }),
]
})
let res = bot.createRichMenu(richmenu);
console.log(res.toString());
}
function createRichMenuB() {
let richmenu = bot.richmenu({
"name": "オリジナルリッチメニュー",
"barText": "メニュー",
"size": { "width": 2500, "height": 1686 },
"selected": true,
"areas": [
bot.area({ "x": 0, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-a", "data": "change to A"}) }),
bot.area({ "x": 833, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-b", "data": "change to B"}) }),
bot.area({"x": 1667, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-c", "data": "change to C"}) }),
bot.area({ "x": 0, "y": 337, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-1"}) }),
bot.area({ "x": 833, "y": 337, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-2"}) }),
bot.area({"x": 1667, "y": 337, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-3"}) }),
bot.area({ "x": 0, "y": 786, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-4"}) }),
bot.area({ "x": 833, "y": 786, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-5"}) }),
bot.area({"x": 1667, "y": 786, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-6"}) }),
bot.area({ "x": 0, "y": 1122, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-7"}) }),
bot.area({ "x": 833, "y": 1122, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-8"}) }),
bot.area({"x": 1667, "y": 1122, "width": 833, "height": 450,
"action": bot.aMessage({"text": "ボタンB-9"}) }),
]
})
let res = bot.createRichMenu(richmenu);
console.log(res.toString());
}
function createRichMenuC() {
let richmenu = bot.richmenu({
"name": "オリジナルリッチメニュー",
"barText": "メニュー",
"size": { "width": 2500, "height": 1686 },
"selected": true,
"areas": [
bot.area({ "x": 0, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-a", "data": "change to A"}) }),
bot.area({ "x": 833, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-b", "data": "change to B"}) }),
bot.area({"x": 1667, "y": 0, "width": 833, "height": 336,
"action": bot.aSwitch({"aliasId": "switch-to-c", "data": "change to C"}) }),
bot.area({ "x": 0, "y": 337, "width": 833, "height": 1349,
"action": bot.aMessage({"text": "ボタンC-1"}) }),
bot.area({ "x": 833, "y": 337, "width": 833, "height": 1349,
"action": bot.aMessage({"text": "ボタンC-2"}) }),
bot.area({"x": 1667, "y": 337, "width": 833, "height": 1349,
"action": bot.aMessage({"text": "ボタンC-3"}) }),
]
})
let res = bot.createRichMenu(richmenu);
console.log(res.toString());
}
// エイリアス作成
function createRichMenuArias() {
deleteRichMenuArias(); // 既存のエイリアスを削除
bot.createRichMenuArias("switch-to-a", "リッチメニューAのID");
bot.createRichMenuArias("switch-to-b", "リッチメニューBのID");
bot.createRichMenuArias("switch-to-c", "リッチメニューCのID");
}
// エイリアス削除
function deleteRichMenuArias() {
bot.deleteRichMenuArias("switch-to-a");
bot.deleteRichMenuArias("switch-to-b");
bot.deleteRichMenuArias("switch-to-c");
}
// エイリアス変更
// function updateRichMenuArias() {
// bot.updateRichMenuArias("switch-to-a", "リッチメニューAのID");
// bot.updateRichMenuArias("switch-to-b", "リッチメニューBのID");
// bot.updateRichMenuArias("switch-to-c", "リッチメニューCのID");
// }
function uploadRichmenuImageA() {
const file = DriveApp.getFileById("リッチメニューAの画像ID");
const blob = Utilities.newBlob(
file.getBlob().getBytes(),
file.getMimeType(),
file.getName()
);
bot.setRichMenuImage("リッチメニューAのID", blob);
}
function uploadRichmenuImageB() {
const file = DriveApp.getFileById("リッチメニューBの画像ID");
const blob = Utilities.newBlob(
file.getBlob().getBytes(),
file.getMimeType(),
file.getName()
);
bot.setRichMenuImage("リッチメニューBのID", blob);
}
function uploadRichmenuImageC() {
const file = DriveApp.getFileById("リッチメニューCの画像ID");
const blob = Utilities.newBlob(
file.getBlob().getBytes(),
file.getMimeType(),
file.getName()
);
bot.setRichMenuImage("リッチメニューCのID", blob);
}
// デフォルト表示
function setDefaultRichMenu() {
bot.setDefaultRichMenu("リッチメニューAのID");
}
// // デフォルト取り下げ
// function deleteDefaultRichMenu() {
// bot.deleteDefaultRichMenu();
// }
【目指したい姿】
・公式アカウントを友達登録した際に、3問のアンケート(属性・年齢・性別)を選択式で実施。
リッチメニューはパターンA。
IDとユーザーネームを自動取得し、回答と併せてスプレッドシートに記載。
・属性(回答:1・2)をもとにタグ付けする
1にはリッチメニューの表示はタブBとタブC
2にはリッチメニューの表示はタブBとタブD