LINE Messaging API -インベントオブジェクト-

LINEボットを作るのに、Webhookで受けるデータって イベントごとにどんなデータが来てるか、のメモです。

公式のドキュメントはこちら

まず、LINEサーバからMessaging APIに送られてくるイベントは大きく分けて以下。

イベント

  • メッセージ
  • フォロー
  • ブロック
  • グループへの参加
  • グループからの退会
  • グループへの他メンバーの参加
  • グループからの他メンバーの退会
  • LINEビーコンの受信

おそらく主として使うのは、メッセージイベント。 文字や画像などを送るやつ。 メッセージイベントはさらに、タイプで分岐していてタイプは、以下。

  • テキスト
  • 画像
  • 動画
  • 音声
  • 位置
  • スタンプ

それぞれのイベント時に受信できるデータのjson ファイルはこちら に置いておきます。

中身は以下の通り。

メッセージイベント

  • メッセージ テキスト
{
  "events": [
    {
      "type": "message",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000,
      "message": {
        "type": "text",
        "id": "0000000000000",
        "text": "XXXXXXX"
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • メッセージ 画像
{
  "events": [
    {
      "type": "message",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000,
      "message": {
        "type": "image",
        "id": "0000000000000",
        "contentProvider": {
          "type": "line"
        }
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • メッセージ 動画
{
  "events": [
    {
      "type": "message",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000,
      "message": {
        "type": "video",
        "id": "0000000000000",
        "contentProvider": {
          "type": "line"
        },
        "duration": 0000
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • メッセージ 音声
{
  "events": [
    {
      "type": "message",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000,
      "message": {
        "type": "audio",
        "id": "0000000000000",
        "contentProvider": {
          "type": "line"
        },
        "duration": 0000
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • メッセージ 位置
{
  "events": [
    {
      "type": "message",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000,
      "message": {
        "type": "location",
        "id": "0000000000000",
        "address": "?日本、〒000-0000 XX県XXX市XXX0丁目00-00 XXXXXXXXX",
        "latitude": 00.000000,
        "longitude": 000.000000
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • メッセージ スタンプ
{
  "events": [
    {
      "type": "message",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000,
      "message": {
        "type": "sticker",
        "id": "0000000000000",
        "stickerId": "00000000",
        "packageId": "0000000"
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • フォロー
{
  "events": [
    {
      "type": "follow",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • ブロック
{
  "events": [
    {
      "type": "unfollow",
      "source": {
        "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "user"
      },
      "timestamp": 0000000000000
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • グループへの参加
{
  "events": [
    {
      "type": "join",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "roomId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "room"
      },
      "timestamp": 0000000000000
    },
    {
      "type": "memberLeft",
      "source": {
        "roomId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "room"
      },
      "timestamp": 0000000000000,
      "left": {
        "members": [
          {
            "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "type": "user"
          }
        ]
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • グループからの退会
{
  "events": [
    {
      "type": "leave",
      "source": {
        "groupId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "group"
      },
      "timestamp": 0000000000000
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • グループへの他メンバーの参加
{
  "events": [
    {
      "type": "memberJoined",
      "replyToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "source": {
        "roomId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "room"
      },
      "timestamp": 0000000000000,
      "joined": {
        "members": [
          {
            "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "type": "user"
          }
        ]
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
  • グループからの他メンバーの退会
{
  "events": [
    {
      "type": "memberLeft",
      "source": {
        "roomId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "type": "room"
      },
      "timestamp": 0000000000000,
      "left": {
        "members": [
          {
            "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "type": "user"
          }
        ]
      }
    }
  ],
  "destination": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}