Events subscription

Games and applications can subscribe to get information about certain OK events in a real time mode.

When an event happens a specific to this event message will be sent to a special app’s URL (called webhook) that will contain all valuable information about happened event.

As an alternative you can get information about these events via long polling API using events.updates method.

How to enable

This feature settings are available in a Настройки подписки на события block of app settings:

To enable it complete following steps:

  • in a Ссылка webhook field specify an URL of your service that will process our requests;
  • verify your webhook by a verification request;
  • select events you require to get information about;
  • do not forget to save app settings.

After a couple of minutes messages will start to come to your webhook when events happen.

Webhook verification

To enable a feature you need to verify your webhook first.

To verify do this:

  • specify it’s url in a Ссылка webhook field;
  • prepare your webhook service to process a verification request we send;
  • press a Подтвердить button to verify your webhook.

Make sure our verification requests are not blocked because of CORS protection. Allow requests that are coming from nap.okapps.ru domain before verification. To allow them you need to pass Access-Control-Allow-Origin and Access-Control-Allow-Headers in a response to requests from our domain.

Verification request has following properties:

  • POST request
  • Content-type: application/json
  • Request body: {“webhookType”: “CONFIRMATION”}

As a response we expect:

  • response code: 200
  • Content-type: application/html or application/text
  • Response body: specified in app settings

How to process event messages

When event happens on our platform we send a request to your specified webhook with a HTTP request:

  • POST request
  • Content-type: application/json
  • UserAgent: OK/1.0 Webhook API
  • Request body: depend on an event type

As a response we expect a 200 response code with non specified body.

Event types

Depending on event we sent a specific message to your webhook URL.

At the moment following requests are supported:

  • user joins/leaves a group;
  • user enables/disables group messages in a group.

Only events that are linked to an official game’s group are process on our side.

To enable support for these events you need to:

  • have a group on our platform;
  • have an app / game on our platform;
  • link your group to an app / game.

To link a group to your app it must be specified in a Официальная группа field of app’s settings.

Join / leave a group events

Request body for a join a group event

{
  "type": "JOIN",
  "timestamp": 1618250409915,
  "userId": "user:1234567890",
  "userName": "FirstName LastName",
  "groupId": "group:1234567890123456",
  "webhookType": "GROUP"
}

Request body for a leave a group event

{
  "type": "LEAVE",
  "timestamp": 1618250409915,
  "userId": "user:1234567890",
  "userName": "FirstName LastName",
  "groupId": "group:1234567890123456",
  "webhookType": "GROUP"
}

Enable / disable group messages events

Request body for an enable messages event

{
  "type": "MESSAGES_ON",
  "timestamp": 1618250409915,
  "userId": "user:1234567890",
  "userName": "FirstName LastName",
  "groupId": "group:1234567890123456",
  "webhookType": "GROUP"
}

Request body for a disable messages event

{
  "type": "MESSAGES_OFF",
  "timestamp": 1618250409915,
  "userId": "user:1234567890",
  "userName": "FirstName LastName",
  "groupId": "group:1234567890123456",
  "webhookType": "GROUP"
}