-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1_addRichMenu.py
126 lines (115 loc) · 2.7 KB
/
1_addRichMenu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 網路請求工具
import requests
# 輸出排版工具
from pprint import pprint
# 自訂組態檔 (放置 LINE Bot 重要設定)
from config import Config
# LINE BOT 設定
config = Config()
# 新增 Rich Menu 用的網址
url_add_rich_menu = f'https://api.line.me/v2/bot/richmenu'
# 聊天機器人的名稱
str_chatbot_name = '胖胖貓咪的情緒選單'
# Rich Menu 規格與設定
str_raw = '''
{
"size":{
"width":2500,
"height":1686
},
"selected":false,
"name":"my rich menu",
"chatBarText":"''' + str_chatbot_name + '''",
"areas":[
{
"bounds":{
"x":0,
"y":0,
"width":833.333,
"height":843
},
"action":{
"type":"message",
"text":"[[[喜歡]]]"
}
},
{
"bounds":{
"x":833.333,
"y":0,
"width":833.333,
"height":843
},
"action":{
"type":"message",
"text":"[[[悲傷]]]"
}
},
{
"bounds":{
"x":1666.666,
"y":0,
"width":833.333,
"height":843
},
"action":{
"type":"message",
"text":"[[[厭惡噁心]]]"
}
},
{
"bounds":{
"x":0,
"y":843,
"width":833.333,
"height":843
},
"action":{
"type":"message",
"text":"[[[憤怒]]]"
}
},
{
"bounds":{
"x":833.333,
"y":843,
"width":833.333,
"height":843
},
"action":{
"type":"message",
"text":"[[[幸福]]]"
}
},
{
"bounds":{
"x":1666.666,
"y":843,
"width":833.333,
"height":843
},
"action":{
"type":"message",
"text":"[[[其它]]]"
}
}
]
}
'''
str_raw = str_raw.encode('utf-8')
# 請求標頭
my_headers = {
'Authorization': f'Bearer {config["YOUR_CHANNEL_ACCESS_TOKEN"]}',
'Content-Type': 'application/json'
}
# 執行請求 (新增 RichMenu)
response = requests.post(url = url_add_rich_menu, data = str_raw, headers = my_headers)
# 輸出回應結果 (會取得 Rich Menu Id)
pprint(response.text)
"""
輸出
'{"richMenuId":"RichMenu ID 的值"}'
例如
'{"richMenuId":"richmenu-e0fef82f307d6507199056192da09143"}'
之後請將 richMenuId 的值,複製到 2_uploadRichMenuImage.py 和 3_setRichMenu.py 當中
"""