Skip to content

Commit 8b112fb

Browse files
authored
feat: add rich menu deployment scripts and images (#17)
* feat: add rich menu deployment scripts and images This commit introduces the necessary files and scripts to deploy rich menus for the LINE bot. It includes: - `.gitignore`: To ignore the `.env` file containing sensitive information. - `README.md`: A basic README file explaining how to set environment variables. - `images/`: Contains the images for the rich menus. - `richmenu_deploy_page1.sh`: A script to deploy the first page of the rich menu. - `richmenu_deploy_page2.sh`: A script to deploy the second page of the rich menu. These scripts automate the process of creating, updating, and deploying rich menus, making it easier to manage the bot's user interface. They handle deleting existing rich menus and aliases, creating new ones, uploading images, and setting the default rich menu for all users. * feat(README.md): add richmenu directory to project structure The richmenu directory was added to the project, so it is necessary to update the README.md file to reflect this change. This commit adds the richmenu directory to the project structure in the README.md file. * Add page3 image * feat(richmenu): implement rich menu switching between pages This commit introduces a new rich menu page (page3) and enables switching between rich menu pages 1, 2, and 3. The changes include: - Modifying richmenu_deploy_page1.sh and richmenu_deploy_page2.sh to use the `richmenuswitch` action to navigate to page3. - Adding a new script, richmenu_deploy_page3.sh, to deploy the new rich menu page. This script handles creating the rich menu, uploading the image, and setting up the alias. The `richmenuswitch` action allows users to navigate between different rich menu configurations, providing a more dynamic and interactive experience. The new page3 script automates the deployment process for the new rich menu page. * Update page3 richmenu TODO: 對應的 postback event handler
1 parent c2a088c commit 8b112fb

10 files changed

Lines changed: 510 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ NCKU Chatbot aims to simplify student campus life by providing instant, accurate
1414
ncku-chatbot/
1515
├── linebot/ # LINE bot integration service
1616
├── crawler/ # Web crawling scripts and n8n templates (In Development)
17+
├── richmenu/ # LINE rich menu configuration files
1718
└── dify/ # DSL files, including prompts, LLM models, etc. (In Development)
1819
```
1920

richmenu/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

richmenu/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Rich menu setting
2+
3+
Set your environment variables before running the script.
4+
5+
```bash
6+
export LINE_ACCESS_TOKEN=<your_access_token>
7+
```

richmenu/images/page1.png

109 KB
Loading

richmenu/images/page2.png

109 KB
Loading

richmenu/images/page2_old.png

106 KB
Loading

richmenu/images/page3.png

236 KB
Loading

richmenu/richmenu_deploy_page1.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
# ======= 使用者設定 =======
4+
ACCESS_TOKEN=$LINE_ACCESS_TOKEN
5+
ALIAS_ID="richmenu-alias-page1"
6+
IMAGE_PATH="images/page1.png"
7+
CHATBAR_TEXT="點我會有驚喜歐!😎"
8+
RICHMENU_NAME="page1"
9+
# ==========================
10+
11+
echo "[1] 從 list 找出 name 為 ${RICHMENU_NAME} 的 rich menu..."
12+
MENU_IDS=$(curl -s -X GET "https://api.line.me/v2/bot/richmenu/list" \
13+
-H "Authorization: Bearer $ACCESS_TOKEN" \
14+
-H "Content-Type: application/json" | jq -r '.richmenus[] | select(.name=="'"$RICHMENU_NAME"'") | .richMenuId')
15+
16+
TOTAL_COUNT=$(echo "$MENU_IDS" | wc -l | tr -d ' ')
17+
echo "[2] 找到 $TOTAL_COUNT 個 rich menu 名稱為 '$RICHMENU_NAME'"
18+
19+
if [[ "$TOTAL_COUNT" -gt 0 ]]; then
20+
echo "[3] 開始刪除..."
21+
echo "$MENU_IDS" | while read OLD_ID; do
22+
echo "🗑️ 刪除 richMenuId: $OLD_ID"
23+
curl -s -X DELETE "https://api.line.me/v2/bot/richmenu/$OLD_ID" \
24+
-H "Authorization: Bearer $ACCESS_TOKEN" \
25+
-H "Content-Type: application/json"
26+
done
27+
else
28+
echo "[3] 沒有找到要刪除的 rich menu"
29+
fi
30+
31+
# === 刪除 alias ===
32+
echo "[4] 嘗試刪除 alias $ALIAS_ID..."
33+
ALIAS_EXISTS=$(curl -s -X GET "https://api.line.me/v2/bot/richmenu/alias/${ALIAS_ID}" \
34+
-H "Authorization: Bearer $ACCESS_TOKEN" \
35+
-H "Content-Type: application/json" | jq -r '.richMenuId')
36+
37+
if [[ "$ALIAS_EXISTS" != "null" ]]; then
38+
echo "🗑️ 刪除 alias $ALIAS_ID"
39+
curl -s -X DELETE "https://api.line.me/v2/bot/richmenu/alias/${ALIAS_ID}" \
40+
-H "Authorization: Bearer $ACCESS_TOKEN" \
41+
-H "Content-Type: application/json"
42+
else
43+
echo "✅ 無對應 alias,略過"
44+
fi
45+
46+
# 建立新 rich menu,並取得新 richMenuId
47+
echo "[5] 建立新的 rich menu..."
48+
CREATE_RES=$(curl -s -X POST "https://api.line.me/v2/bot/richmenu" \
49+
-H "Authorization: Bearer $ACCESS_TOKEN" \
50+
-H "Content-Type: application/json" \
51+
-d '{
52+
"size": { "width": 2500, "height": 1686 },
53+
"selected": true,
54+
"name": "'"$RICHMENU_NAME"'",
55+
"chatBarText": "'"$CHATBAR_TEXT"'",
56+
"areas": [
57+
{
58+
"bounds": {
59+
"x": 1036,
60+
"y": 29,
61+
"width": 1010,
62+
"height": 272
63+
},
64+
"action": {
65+
"type": "richmenuswitch",
66+
"richMenuAliasId": "richmenu-alias-page2",
67+
"data": "richmenu-changed-to-page2"
68+
}
69+
},
70+
{
71+
"bounds": {
72+
"x": 2067,
73+
"y": 29,
74+
"width": 433,
75+
"height": 264
76+
},
77+
"action": {
78+
"type": "richmenuswitch",
79+
"richMenuAliasId": "richmenu-alias-page3",
80+
"data": "richmenu-changed-to-page3"
81+
}
82+
},
83+
{
84+
"bounds": {
85+
"x": 124,
86+
"y": 776,
87+
"width": 1068,
88+
"height": 449
89+
},
90+
"action": {
91+
"type": "postback",
92+
"data": "clear_conversation_id"
93+
}
94+
},
95+
{
96+
"bounds": {
97+
"x": 1300,
98+
"y": 759,
99+
"width": 1093,
100+
"height": 458
101+
},
102+
"action": {
103+
"type": "postback",
104+
"data": "reset_user"
105+
}
106+
}
107+
]
108+
}')
109+
110+
NEW_ID=$(echo "$CREATE_RES" | jq -r '.richMenuId')
111+
echo "[5] 新的 richMenuId: $NEW_ID"
112+
113+
# 上傳圖片
114+
echo "[6] 上傳圖片..."
115+
curl -s -X POST "https://api-data.line.me/v2/bot/richmenu/$NEW_ID/content" \
116+
-H "Authorization: Bearer $ACCESS_TOKEN" \
117+
-H "Content-Type: image/png" \
118+
-T "$IMAGE_PATH"
119+
120+
# 設定 alias
121+
echo "[7] 綁定 alias: $ALIAS_ID$NEW_ID"
122+
curl -s -X POST "https://api.line.me/v2/bot/richmenu/alias" \
123+
-H "Authorization: Bearer $ACCESS_TOKEN" \
124+
-H "Content-Type: application/json" \
125+
-d '{
126+
"richMenuAliasId": "'$ALIAS_ID'",
127+
"richMenuId": "'$NEW_ID'"
128+
}'
129+
130+
# 設定預設 rich menu
131+
echo "[8] 設定預設 rich menu..."
132+
curl -s -X POST "https://api.line.me/v2/bot/user/all/richmenu/$NEW_ID" \
133+
-H "Authorization: Bearer $ACCESS_TOKEN" \
134+
-d ''
135+
136+
echo "✅ 部署完成!"
137+

richmenu/richmenu_deploy_page2.sh

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/bin/bash
2+
3+
# ======= 使用者設定 =======
4+
ACCESS_TOKEN=$LINE_ACCESS_TOKEN
5+
ALIAS_ID="richmenu-alias-page2"
6+
IMAGE_PATH="images/page2.png"
7+
CHATBAR_TEXT="喜歡的話,請追蹤我們的粉專🫶"
8+
RICHMENU_NAME="page2"
9+
# ==========================
10+
11+
echo "[1] 從 list 找出 name 為 ${RICHMENU_NAME} 的 rich menu..."
12+
MENU_IDS=$(curl -s -X GET "https://api.line.me/v2/bot/richmenu/list" \
13+
-H "Authorization: Bearer $ACCESS_TOKEN" \
14+
-H "Content-Type: application/json" | jq -r '.richmenus[] | select(.name=="'"$RICHMENU_NAME"'") | .richMenuId')
15+
16+
TOTAL_COUNT=$(echo "$MENU_IDS" | wc -l | tr -d ' ')
17+
echo "[2] 找到 $TOTAL_COUNT 個 rich menu 名稱為 '$RICHMENU_NAME'"
18+
19+
if [[ "$TOTAL_COUNT" -gt 0 ]]; then
20+
echo "[3] 開始刪除..."
21+
echo "$MENU_IDS" | while read OLD_ID; do
22+
echo "🗑️ 刪除 richMenuId: $OLD_ID"
23+
curl -s -X DELETE "https://api.line.me/v2/bot/richmenu/$OLD_ID" \
24+
-H "Authorization: Bearer $ACCESS_TOKEN" \
25+
-H "Content-Type: application/json"
26+
done
27+
else
28+
echo "[3] 沒有找到要刪除的 rich menu"
29+
fi
30+
31+
# === 刪除 alias ===
32+
echo "[4] 嘗試刪除 alias $ALIAS_ID..."
33+
ALIAS_EXISTS=$(curl -s -X GET "https://api.line.me/v2/bot/richmenu/alias/${ALIAS_ID}" \
34+
-H "Authorization: Bearer $ACCESS_TOKEN" \
35+
-H "Content-Type: application/json" | jq -r '.richMenuId')
36+
37+
if [[ "$ALIAS_EXISTS" != "null" ]]; then
38+
echo "🗑️ 刪除 alias $ALIAS_ID"
39+
curl -s -X DELETE "https://api.line.me/v2/bot/richmenu/alias/${ALIAS_ID}" \
40+
-H "Authorization: Bearer $ACCESS_TOKEN" \
41+
-H "Content-Type: application/json"
42+
else
43+
echo "✅ 無對應 alias,略過"
44+
fi
45+
46+
# 建立新 rich menu,並取得新 richMenuId
47+
echo "[5] 建立新的 rich menu..."
48+
CREATE_RES=$(curl -s -X POST "https://api.line.me/v2/bot/richmenu" \
49+
-H "Authorization: Bearer $ACCESS_TOKEN" \
50+
-H "Content-Type: application/json" \
51+
-d '{
52+
"size": {
53+
"width": 2500,
54+
"height": 1686
55+
},
56+
"selected": true,
57+
"name": "page2new",
58+
"chatBarText": "查看更多資訊",
59+
"areas": [
60+
{
61+
"bounds": {
62+
"x": 87,
63+
"y": 478,
64+
"width": 656,
65+
"height": 463
66+
},
67+
"action": {
68+
"type": "postback",
69+
"data": "example_question_law"
70+
}
71+
},
72+
{
73+
"bounds": {
74+
"x": 961,
75+
"y": 483,
76+
"width": 611,
77+
"height": 470
78+
},
79+
"action": {
80+
"type": "postback",
81+
"data": "example_question_housing"
82+
}
83+
},
84+
{
85+
"bounds": {
86+
"x": 1790,
87+
"y": 462,
88+
"width": 635,
89+
"height": 483
90+
},
91+
"action": {
92+
"type": "postback",
93+
"data": "example_question_activity"
94+
}
95+
},
96+
{
97+
"bounds": {
98+
"x": 103,
99+
"y": 1052,
100+
"width": 619,
101+
"height": 467
102+
},
103+
"action": {
104+
"type": "postback",
105+
"data": "example_question_admin_procedure"
106+
}
107+
},
108+
{
109+
"bounds": {
110+
"x": 949,
111+
"y": 1048,
112+
"width": 632,
113+
"height": 470
114+
},
115+
"action": {
116+
"type": "postback",
117+
"data": "example_question_course"
118+
}
119+
},
120+
{
121+
"bounds": {
122+
"x": 1778,
123+
"y": 1052,
124+
"width": 631,
125+
"height": 463
126+
},
127+
"action": {
128+
"type": "postback",
129+
"data": "example_question_club"
130+
}
131+
},
132+
{
133+
"bounds": {
134+
"x": 8,
135+
"y": 17,
136+
"width": 994,
137+
"height": 276
138+
},
139+
"action": {
140+
"type": "richmenuswitch",
141+
"richMenuAliasId": "richmenu-alias-page1",
142+
"data": "richmenu-changed-to-page1"
143+
}
144+
},
145+
{
146+
"bounds": {
147+
"x": 2067,
148+
"y": 21,
149+
"width": 429,
150+
"height": 276
151+
},
152+
"action": {
153+
"type": "richmenuswitch",
154+
"richMenuAliasId": "richmenu-alias-page3",
155+
"data": "richmenu-changed-to-page3"
156+
}
157+
}
158+
]
159+
}')
160+
161+
NEW_ID=$(echo "$CREATE_RES" | jq -r '.richMenuId')
162+
echo "[5] 新的 richMenuId: $NEW_ID"
163+
164+
# 上傳圖片
165+
echo "[6] 上傳圖片..."
166+
curl -s -X POST "https://api-data.line.me/v2/bot/richmenu/$NEW_ID/content" \
167+
-H "Authorization: Bearer $ACCESS_TOKEN" \
168+
-H "Content-Type: image/png" \
169+
-T "$IMAGE_PATH"
170+
171+
# 設定 alias
172+
echo "[7] 綁定 alias: $ALIAS_ID$NEW_ID"
173+
curl -s -X POST "https://api.line.me/v2/bot/richmenu/alias" \
174+
-H "Authorization: Bearer $ACCESS_TOKEN" \
175+
-H "Content-Type: application/json" \
176+
-d '{
177+
"richMenuAliasId": "'$ALIAS_ID'",
178+
"richMenuId": "'$NEW_ID'"
179+
}'
180+
181+
# 設定預設 rich menu
182+
echo "[8] 設定預設 rich menu..."
183+
curl -s -X POST "https://api.line.me/v2/bot/user/all/richmenu/$NEW_ID" \
184+
-H "Authorization: Bearer $ACCESS_TOKEN" \
185+
-d ''
186+
187+
echo "✅ 部署完成!"
188+

0 commit comments

Comments
 (0)