File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Base } from './base'
33
44export interface WebhookEvent {
55 messageId : string
6+ subscriptionId : string
67 timestamp : string
78 type : string
89 version : string
@@ -19,6 +20,11 @@ export class EventBase extends Base<WebhookEvent> {
1920 */
2021 messageId : string
2122
23+ /**
24+ * The subscription ID associated with the event
25+ */
26+ subscriptionId : string
27+
2228 /**
2329 * The event's timestamp
2430 */
@@ -32,6 +38,14 @@ export class EventBase extends Base<WebhookEvent> {
3238 this . webhookEvent = {
3339 messageId : data . messageId ,
3440 timestamp : new Date ( data . timestamp ) ,
41+ subscriptionId : data . subscriptionId ,
3542 }
3643 }
44+
45+ /**
46+ * The unsubscribes the client from this subscription type using the associated subscription ID in the event
47+ */
48+ unsubscribe ( ) {
49+ this . kient . api . webhook . unsubscribe ( [ this . webhookEvent . subscriptionId ] )
50+ }
3751}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export class WebhookServer {
1717 this . instance . post ( '/webhook' , async ( c ) => {
1818 if ( this . kient . _kickPublicKey ) {
1919 const messageId = c . req . header ( 'Kick-Event-Message-Id' )
20+ const subscriptionId = c . req . header ( 'Kick-Event-Subscription-Id' )
2021 const signature = c . req . header ( 'Kick-Event-Signature' )
2122 const timestamp = c . req . header ( 'Kick-Event-Message-Timestamp' )
2223 const body = await c . req . text ( )
@@ -40,13 +41,14 @@ export class WebhookServer {
4041 const eventType = c . req . header ( 'Kick-Event-Type' )
4142 const eventVersion = c . req . header ( 'Kick-Event-Version' )
4243
43- if ( ! eventType || ! eventVersion ) {
44+ if ( ! eventType || ! eventVersion || ! subscriptionId ) {
4445 console . error ( 'Missing required event type or version' )
4546 return c . body ( null , 400 )
4647 }
4748
4849 this . kient . handleWebhookEvent ( {
4950 messageId,
51+ subscriptionId,
5052 timestamp,
5153 type : eventType ,
5254 version : eventVersion ,
You can’t perform that action at this time.
0 commit comments