Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Web Hook Events

Bob edited this page Mar 8, 2018 · 20 revisions

How to generate a signature

To authenticate the request, every event has a header X-Web-Hook-Signature, a web hook should use HMAC sha256 with shared_secret key which is provided when registered with an event to generate a hex string hash then compare with the signature to make sure the request is authorized.

message has the following format (event_time can be found in header X-Web-Hook-Event-Time):

web_hook_id=<id>&event_time=<event_time>

Episode Event

When an episode is downloaded and ready to be played, this event will be emitted.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: EPISODE_DOWNLOAD
X-Web-Hook-Signature: <singature hash>

Response from web hook

<id of the web hook>

Event Schema

The event object has the following structure:

field name type example explanation
episode object see the example below the episode information.

episode object

{
  "id": "f0317eb2-d487-4e89-9e8d-9cccffd73e00",
  "url": "https://yoursite.com/play/f0317eb2-d487-4e89-9e8d-9cccffd73e00",
  "bgm_eps_id": 711764,
  "name": "01",
  "name_cn": "没干劲的不正经老师",
  "status": 2,
  "episode_no": 1,
  "airdate": "2017-04-29",
  "thumbnail_image": {
    "url": "/pic/587b0a9b-c2ba-4f01-b553-6d14ed60f311/cover.jpg",
    "dominant_color": "#ffcfc3",
    "width": 600,
    "height": 400
  },
  "bangumi": {
    "id": "46a469ee-5041-4f7c-8bf3-43ea6166a728",
    "bgm_id": 174138,
    "name": "ロクでなし魔術講師と禁忌教典",
    "name_cn": "不正经的魔术讲师与禁忌教典",
    "summary": "厌恶魔术的魔术讲师所展开的叛逆英雄幻想剧!魔术与科学共同发展的世界——卢瓦佛斯。位于魔导大国·阿尔扎诺帝国南部的“阿尔扎诺帝国魔法学院”,是学习世界最先端魔术的最高学舍...",
    "image": "http://lain.bgm.tv/pic/cover/l/fb/9a/212500_858ip.jpg",
    "cover_image": {
      "url": "/pic/587b0a9b-c2ba-4f01-b553-6d14ed60f311/cover.jpg",
      "dominant_color": "#ffcfc3",
      "width": 600,
      "height": 400
    },
    "type": 2,
    "status": 1,
    "air_date": "2017-04-29",
    "air_weekday": 6,
    "eps": 12,
  }
}

Token Added Event

When a user added a web hook token.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: TOKEN_ADDED
X-Web-Hook-Signature: <singature hash>

Response from web hook

<id of the web hook>

Event Schema

field name type example explanation
favorites array see the example below A favorite object list with user_id replaced by token_id

User Favorite Change Event

When user change its favorite, include add, change status of a favorite, this event will be emitted.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: USER_FAVORITE_CHANGED
X-Web-Hook-Signature: <singature hash>

Response from web hook

<id of the web hook>

Event Schema

field name type example explanation
favorites array see the example below A favorite object list with user_id replaced by token_id

favorite

{
  "id": "808a7d09-629f-41a3-a1bc-0924a95c5cc6",
  "token_id": "afb23de8d",
  "bangumi_id": "46a469ee-5041-4f7c-8bf3-43ea6166a728",
  "status": 3
}

Token Removed Event

When user removed a webhook token.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: TOKEN_REMOVED
X-Web-Hook-Signature: <singature hash>

Response from webhook

<id of the web hook>

Event Schema

field name type example explanation
token_id string f2da2001 removed token_id

Keep Alive Event

When a web hook is not dead, every 5 minutes this event will be emitted to ensure the web hook is working. This event will also be a notification for the last event result.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: KEEP_ALIVE
X-Web-Hook-Signature: <singature hash>

Response from web hook

<id of the web hook>

Event Schema

field name type example explanation
status number 1 This the current status of web hook, reflect if the last event is successful. If a web hook finds this value is 2, that means an error has occurred during the last event, the web hook may have some obsolete data. it must manually request the revive API with all its token to get the latest information.

Initial Event

When a web hook is registered, this event will be emitted once. Web Hook should request revive API to finish the initial process.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: INITIAL
X-Web-Hook-Signature: <singature hash>

Response from web hook

<id of the web hook>

Event Schema

field name type example explanation
url string "http://localhost:9800/" URL of this web hook
web_hook_id number d92db89d-54f2-43aa-82d9-205aad99b96e Web hook should store this id for response and future use.

User Email Changed

When user email address changed and confirmed, web hook will be informed and received the new email address.

Headers:

X-Web-Hook-Event-Time: <utc milliseconds from epoch> (for example: 1509704329938)
X-Web-Hook-Event-Type: USER_EMAIL_CHANGED
X-Web-Hook-Signature: <singature hash>

Response from web hook

<id of the web hook>

Event Schema

field name type example explanation
email string "johndoe@example.com" user's new email address
token string adb26sf token id in web hook represent a user.