eventsub - YoYoGames/GMEXT-Twitch GitHub Wiki
These are the functions of this module:
- twitch_eventsub_create_eventsub_subscription
- twitch_eventsub_delete_eventsub_subscription
- twitch_eventsub_get_eventsub_subscriptions
- twitch_eventsub_live_connect
- twitch_eventsub_live_disconnect
Twitch Endpoint: Create EventSub Subscription
This function creates an EventSub subscription.
If you use webhooks to receive events, the request must specify an app access token. The request will fail if you use a user access token. If the subscription type requires user authorization, the user must have granted your app (client ID) permissions to receive those events before you subscribe to them. For example, to subscribe to channel.subscribe events, your app must get a user access token that includes the TWITCH_SCOPE_CHANNEL_READ_SUBSCRIPTIONS
scope, which adds the required permission to your app access token's client ID.
If you use WebSockets to receive events, the request must specify a user access token. The request will fail if you use an app access token. If the subscription type requires user authorization, the token must include the required scope. However, if the subscription type doesn't include user authorization, the token may include any scopes or no scopes.
If you use Conduits to receive events, the request must specify an app access token. The request will fail if you use a user access token.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Success Callback, or Failure Callback.
Syntax:
twitch_eventsub_create_eventsub_subscription(type, version, condition, transport, method, optionals, callback_success, callback_failed)
Argument | Type | Description |
---|---|---|
type | String | The type of subscription to create. For a list of subscriptions that you can create, see Subscription Types. Set this field to the value in the Name column of the Subscription Types table. |
version | String | The version number that identifies the definition of the subscription type that you want the response to use. |
condition | Struct | A JSON object that contains the parameter values that are specific to the specified subscription type. For the object's required and optional fields, see the subscription type's documentation. |
transport | Struct | The transport details that you want Twitch to use when sending you notifications. |
method | String | The transport method. Possible values are: - "webhook" - "websocket" - "conduit" The demo project provides example code that shows how to use the "websocket" method. The other transports methods can also be used, though require additional setup. See Getting Events Using Webhook Callbacks and Getting Events Using Conduits. |
optionals | Struct | The optional parameters to be passed into the function: - callback : String : The callback URL where the notifications are sent. The URL must use the HTTPS protocol and port 443. See Processing an event. Specify this field only if method is set to "webhook" . NOTE: Redirects are not followed.- secret : String : The secret used to verify the signature. The secret must be an ASCII string that's a minimum of 10 characters long and a maximum of 100 characters long. For information about how the secret is used, see Verifying the event message. Specify this field only if method is set to "webhook" .- session_id : String : An ID that identifies the WebSocket to send notifications to. When you connect to EventSub using WebSockets, the server returns the ID in the Welcome message. Specify this field only if "method" is set to "websocket" .- conduit_id : String : An ID that identifies the conduit to send notifications to. When you create a conduit, the server returns the conduit ID. Specify this field only if method is set to "conduit" . |
callback_success | Function | Triggered if the request succeeded |
callback_failed | Function | Triggered if the request failed |
Returns:
N/A
Triggers:
These members are returned in the success callback:
Member | Type | Description |
---|---|---|
data | Array | A list that contains the single subscription that you created. |
├── id | String | An ID that identifies the subscription. |
├── status | String | The subscription's status. The subscriber receives events only for enabled subscriptions. Possible values are: "enabled" — The subscription is enabled. "webhook_callback_verification_pending" — The subscription is pending verification of the specified callback URL (see Responding to a challenge request). |
├── type | String | The subscription's type. See Subscription Types. |
├── version | String | The version number that identifies this definition of the subscription's data. |
├── condition | Struct | The subscription's parameter values. This is a string-encoded JSON object whose contents are determined by the subscription type. |
├── created_at | String | The date and time (in RFC3339 format) of when the subscription was created. |
├── transport | Struct | The transport details used to send the notifications. |
├── method | String | The transport method. Possible values are: "webhook" , "websocket" , "conduit"
|
├── callback | String | The callback URL where the notifications are sent. Included only if method is set to "webhook" . |
├── session_id | String | An ID that identifies the WebSocket that notifications are sent to. Included only if method is set to "websocket" . |
├── connected_at | String | The UTC date and time that the WebSocket connection was established. Included only if method is set to "websocket" . |
└── conduit_id | String | An ID that identifies the conduit to send notifications to. Included only if method is set to "conduit" . |
└── cost | Real | The amount that the subscription counts against your limit. Learn More |
total | Real | The total number of subscriptions you've created. |
total_cost | Real | The sum of all of your subscription costs. Learn More |
max_total_cost | Real | The maximum total cost that you're allowed to incur for all subscriptions you create. |
This method is triggered on failure.
Twitch Endpoint: Delete EventSub Subscription
This function deletes an EventSub subscription.
If you use webhooks to receive events, the request must specify an app access token. The request will fail if you use a user access token.
If you use WebSockets to receive events, the request must specify a user access token. The request will fail if you use an app access token. The token may include any scopes.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Success Callback, or Failure Callback.
Syntax:
twitch_eventsub_delete_eventsub_subscription(id, callback_success, callback_failed)
Argument | Type | Description |
---|---|---|
id | String | The ID of the subscription to delete. |
callback_success | Function | Triggered if the request succeeded |
callback_failed | Function | Triggered if the request failed |
Returns:
N/A
Triggers:
This method is triggered on success. It has no response body.
This method is triggered on failure.
Twitch Endpoint: Get EventSub Subscriptions
This function gets a list of EventSub subscriptions that the client in the access token created.
If you use Webhooks or Conduits to receive events, the request must specify an app access token. The request will fail if you use a user access token.
If you use WebSockets to receive events, the request must specify a user access token. The request will fail if you use an app access token. The token may include any scopes.
Note
Use the status
, type
, and user_id
parameters to filter the list of subscriptions that are returned. The filters are mutually exclusive; the request fails if you specify more than one filter.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Success Callback, or Failure Callback.
Syntax:
twitch_eventsub_get_eventsub_subscriptions(optionals, callback_success, callback_failed)
Argument | Type | Description |
---|---|---|
optionals | Struct | The optional parameters to be passed into the function: - status : String : Filter subscriptions by its status. Possible values are: "enabled" — The subscription is enabled. "webhook_callback_verification_pending" — The subscription is pending verification of the specified callback URL. "webhook_callback_verification_failed" — The specified callback URL failed verification. "notification_failures_exceeded" — The notification delivery failure rate was too high. "authorization_revoked" — The authorization was revoked for one or more users specified in the *Condition object. "moderator_removed" — The moderator that authorized the subscription is no longer one of the broadcaster's moderators. "user_removed" — One of the users specified in the Condition object was removed. "chat_user_banned" - The user specified in the Condition object was banned from the broadcaster's chat. "version_removed" — The subscription to subscription type and version is no longer supported. "beta_maintenance" — The subscription to the beta subscription type was removed due to maintenance. "websocket_disconnected" — The client closed the connection. "websocket_failed_ping_pong" — The client failed to respond to a ping message. "websocket_received_inbound_traffic" — The client sent a non-pong message. Clients may only send pong messages (and only in response to a ping message). "websocket_connection_unused" — The client failed to subscribe to events within the required time. "websocket_internal_error" — The Twitch WebSocket server experienced an unexpected error. "websocket_network_timeout" — The Twitch WebSocket server timed out writing the message to the client. "websocket_network_error" — The Twitch WebSocket server experienced a network error writing the message to the client. "websocket_failed_to_reconnect" - The client failed to reconnect to the Twitch WebSocket server within the required time after a Reconnect Message.- type : String : Filter subscriptions by subscription type. For a list of subscription types, see Subscription Types.- user_id : String : Filter subscriptions by user ID. The response contains subscriptions where this ID matches a user ID that you specified in the Condition object when you created the subscription.- after : String : The cursor used to get the next page of results. The pagination struct in the response contains the cursor's value. |
callback_success | Function | Triggered if the request succeeded |
callback_failed | Function | Triggered if the request failed |
Returns:
N/A
Triggers:
These members are returned in the success callback:
Member | Type | Description |
---|---|---|
data | Array | The list of subscriptions. The list is ordered by the oldest subscription first. The list is empty if the client hasn't created subscriptions or there are no subscriptions that match the specified filter criteria. |
├── id | String | An ID that identifies the subscription. |
├── status | String | The subscription's status. The subscriber receives events only for enabled subscriptions. Possible values are: "enabled" — The subscription is enabled. "webhook_callback_verification_pending" — The subscription is pending verification of the specified callback URL. "webhook_callback_verification_failed" — The specified callback URL failed verification. "notification_failures_exceeded" — The notification delivery failure rate was too high. "authorization_revoked" — The authorization was revoked for one or more users specified in the Condition object. "moderator_removed" — The moderator that authorized the subscription is no longer one of the broadcaster's moderators. "user_removed" — One of the users specified in the Condition object was removed. "version_removed" — The subscription to subscription type and version is no longer supported. "beta_maintenance" — The subscription to the beta subscription type was removed due to maintenance. "websocket_disconnected" — The client closed the connection. "websocket_failed_ping_pong" — The client failed to respond to a ping message. "websocket_received_inbound_traffic" — The client sent a non-pong message. Clients may only send pong messages (and only in response to a ping message). "websocket_connection_unused" — The client failed to subscribe to events within the required time. "websocket_internal_error" — The Twitch WebSocket server experienced an unexpected error. "websocket_network_timeout" — The Twitch WebSocket server timed out writing the message to the client. "websocket_network_error" — The Twitch WebSocket server experienced a network error writing the message to the client. |
├── type | String | The subscription's type. See Subscription Types. |
├── version | String | The version number that identifies this definition of the subscription's data. |
├── condition | Struct | The subscription's parameter values. This is a string-encoded JSON object whose contents are determined by the subscription type. |
├── created_at | String | The date and time (in RFC3339 format) of when the subscription was created. |
├── transport | Struct | The transport details used to send the notifications. |
├── method | String | The transport method. Possible values are: "webhook" , "websocket"
|
├── callback | String | The callback URL where the notifications are sent. Included only if method is set to "webhook" . |
├── session_id | String | An ID that identifies the WebSocket that notifications are sent to. Included only if method is set to "websocket" . |
├── connected_at | String | The UTC date and time that the WebSocket connection was established. Included only if method is set to "websocket" . |
└── disconnected_at | String | The UTC date and time that the WebSocket connection was lost. Included only if method is set to "websocket" . |
└── cost | Real | The amount that the subscription counts against your limit. Learn More |
total | Real | The total number of subscriptions that you've created. |
total_cost | Real | The sum of all of your subscription costs. Learn More |
max_total_cost | Real | The maximum total cost that you're allowed to incur for all subscriptions that you create. |
pagination | Struct | a struct that contains the cursor used to get the next page of subscriptions. The struct is empty if there are no more pages to get. The number of subscriptions returned per page is undertermined. |
└── cursor | String | The cursor value that you set the after parameter to. |
This method is triggered on failure.
Twitch Endpoint: N / A
This function creates a connection to be used with the "websocket"
transport method of the EventSub functions.
The function takes a callback function with a single parameter: the Buffer that holds the received data.
eventsub_callback = function(_buffer)
{
var _eventsub_str = buffer_read(_buffer, buffer_string);
var _data = json_parse(_eventsub_str);
switch(_data.metadata.message_type)
{
// Process different message types in a switch statement
// ...
}
}
This connection receives several types of message that should be handled correctly. See Handling WebSocket Events. See the demo project for a complete code example.
Note
Ping-pong messages are handled automatically by GameMaker.
Syntax:
twitch_eventsub_live_connect(callback)
Argument | Type | Description |
---|---|---|
callback | Function | The callback function that's called when data is received on the network socket |
Returns:
Twitch Endpoint: N / A
This function disconnects from the connection set up earlier using twitch_eventsub_live_connect.
Note
This function frees the underlying web socket and must be called when you're finished using the connection to prevent a memory leak.
Syntax:
twitch_eventsub_live_disconnect()
Returns:
N/A