[LINE] リッチメニューAPIを試してみた

# Rich Menu API

* Rich Menu API を触ってみた時のコマンドを箇条書きレベルで書き起こしておく 
*  ( 詳しくは、APIドキュメントを見ながら作業することをオススメします)

## Rich Menu APIのドキュメント

* https://developers.line.me/ja/docs/messaging-api/reference/#beacon-event

## 備忘録 (コマンド箇条書きレベル)

* [手順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
{}
```

#  結果

<img width="609" alt="スクリーンショット 2018-07-11 午後6.56.26.png" src="https://qiita-image-store.s3.amazonaws.com/0/102862/2b2b60ec-0174-88d6-2e14-22f10ab70c78.png">