Rich Menu API
- Rich Menu API を触ってみた時のコマンドを箇条書きレベルで書き起こしておく
- ( 詳しくは、APIドキュメントを見ながら作業することをオススメします)
Rich Menu APIのドキュメント
備忘録 (コマンド箇条書きレベル)
- [手順1 ] リッチメニューを作成する。(指定するパラメータ等はドキュメント参照)
- 成功時に、リッチメニューIDが返る。
curl -X POST -H 'Content-Type:application/json' -H 'Authorization: Bearer {トークン}' -d '{
"size":{
"width":2500,
"height":1686
},
"selected":false,
"name":"Controller",
"chatBarText":"Controller",
"areas":[
{
"bounds":{
"x":551,
"y":325,
"width":321,
"height":321
},
"action":{
"type":"message",
"text":"up"
}
},
{
"bounds":{
"x":876,
"y":651,
"width":321,
"height":321
},
"action":{
"type":"message",
"text":"right"
}
},
{
"bounds":{
"x":551,
"y":972,
"width":321,
"height":321
},
"action":{
"type":"message",
"text":"down"
}
},
{
"bounds":{
"x":225,
"y":651,
"width":321,
"height":321
},
"action":{
"type":"message",
"text":"left"
}
},
{
"bounds":{
"x":1433,
"y":657,
"width":367,
"height":367
},
"action":{
"type":"message",
"text":"btn b"
}
},
{
"bounds":{
"x":1907,
"y":657,
"width":367,
"height":367
},
"action":{
"type":"message",
"text":"btn a"
}
}
]
}' https://api.line.me/v2/bot/richmenu
{"richMenuId":"richmenu-43cc82a1d3a1ba0d0bff4949813b994c"}
- [手順2 ] リッチメニューの画像をアップロード。(※画像サイズの指定あり!)
- 成功時に、空のJSONが返る。
% curl -X POST \
-H 'Authorization: Bearer {トークン}' \
-H 'Content-Type: image/png' \
-H 'Expect:' \
-T ~/Desktop/image.png \
https://api.line.me/v2/bot/richmenu/richmenu-43cc82a1d3a1ba0d0bff4949813b994c/content
{}%
- [手順3 ] 設定済みのリッチメニュー一覧を取得。
- 成功時に、対象のリッチメニューが返る。
% curl \
-H 'Authorization: Bearer {トークン}' \
https://api.line.me/v2/bot/richmenu/list
{"richmenus":[{"richMenuId":"richmenu-403be88b3e8731396ea66e32984074c0","name":"Controller","size":{"width":2500,"height":1686},"chatBarText":"Controller","selected":false,"areas":[{"bounds":{"x":551,"y":325,"width":321,"height":321},"action":{"type":"message","text":"up","type":"message"}},{"bounds":{"x":876,"y":651,"width":321,"height":321},"action":{"type":"message","text":"right","type":"message"}},{"bounds":{"x":551,"y":972,"width":321,"height":321},"action":{"type":"message","text":"down","type":"message"}},{"bounds":{"x":225,"y":651,"width":321,"height":321},"action":{"type":"message","text":"left","type":"message"}},{"bounds":{"x":1433,"y":657,"width":367,"height":367},"action":{"type":"message","text":"btn b","type":"message"}},{"bounds":{"x":1907,"y":657,"width":367,"height":367},"action":{"type":"message","text":"btn a","type":"message"}}]}]}
- [手順4 ] ユーザとリッチメニューの紐付け。
- 成功時に、空のJSONが返る。
- ユーザのIDを指定する (※APIからも取得できる)
% curl -X POST \
-H 'Authorization: Bearer {トークン}' \
-H 'Content-Length: 0' \
https://api.line.me/v2/bot/user/{LINEUserID}/richmenu/richmenu-43cc82a1d3a1ba0d0bff4949813b994c
{}