From 7d252384a934c6173e748efa49d0c30dc8a2f8c7 Mon Sep 17 00:00:00 2001 From: Daniel Sage Date: Thu, 14 Mar 2024 20:12:27 -0400 Subject: [PATCH] Update version for few handlers to correct values --- bindings/conditions.go | 3 +++ bindings/events.go | 5 +++-- handler.go | 8 ++++---- handler_test.go | 7 +++---- notification_handler.go | 8 ++++---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/bindings/conditions.go b/bindings/conditions.go index da37a92..83c92d4 100644 --- a/bindings/conditions.go +++ b/bindings/conditions.go @@ -38,6 +38,9 @@ type ConditionChannelUpdate struct { type ConditionChannelFollow struct { // The broadcaster user ID for the channel you want to get follow notifications for. BroadcasterUserID string `json:"broadcaster_user_id"` + // The ID of the moderator of the channel you want to get follow notifications for. If you have authorization from + // the broadcaster rather than a moderator, specify the broadcaster’s user ID here. + ModeratorUserID string `json:"moderator_user_id"` } type ConditionChannelUnban struct { diff --git a/bindings/events.go b/bindings/events.go index aa09870..b979b6b 100644 --- a/bindings/events.go +++ b/bindings/events.go @@ -82,8 +82,9 @@ type EventChannelUpdate struct { CategoryID string `json:"category_id"` // The category name. CategoryName string `json:"category_name"` - // A boolean identifying whether the channel is flagged as mature. Valid values are true and false. - IsMature bool `json:"is_mature"` + // Array of content classification label IDs currently applied on the Channel. To retrieve a list of all possible + // IDs, use the Get Content Classification Labels API endpoint. + ContentClassificationLabels []string `json:"content_classification_labels"` } type EventChannelUnban struct { diff --git a/handler.go b/handler.go index 924d05d..f1fdd96 100644 --- a/handler.go +++ b/handler.go @@ -42,8 +42,8 @@ type SubHandler struct { // EventSub notification as duplicate. OnDuplicateNotification func(ctx context.Context, h *bindings.NotificationHeaders) - HandleChannelUpdate EventHandler[bindings.EventChannelUpdate] `eventsub-type:"channel.update" eventsub-version:"1"` - HandleChannelFollow EventHandler[bindings.EventChannelFollow] `eventsub-type:"channel.follow" eventsub-version:"1"` + HandleChannelUpdate EventHandler[bindings.EventChannelUpdate] `eventsub-type:"channel.update" eventsub-version:"2"` + HandleChannelFollow EventHandler[bindings.EventChannelFollow] `eventsub-type:"channel.follow" eventsub-version:"2"` HandleChannelSubscribe EventHandler[bindings.EventChannelSubscribe] `eventsub-type:"channel.subscribe" eventsub-version:"1"` HandleChannelSubscriptionEnd EventHandler[bindings.EventChannelSubscriptionEnd] `eventsub-type:"channel.subscription.end" eventsub-version:"1"` HandleChannelSubscriptionGift EventHandler[bindings.EventChannelSubscriptionGift] `eventsub-type:"channel.subscription.gift" eventsub-version:"1"` @@ -52,8 +52,8 @@ type SubHandler struct { HandleChannelRaid EventHandler[bindings.EventChannelRaid] `eventsub-type:"channel.raid" eventsub-version:"1"` HandleChannelBan EventHandler[bindings.EventChannelBan] `eventsub-type:"channel.ban" eventsub-version:"1"` HandleChannelUnban EventHandler[bindings.EventChannelUnban] `eventsub-type:"channel.unban" eventsub-version:"1"` - HandleChannelUnbanRequestCreate EventHandler[bindings.EventChannelUnbanRequestCreate] `eventsub-type:"channel.unban_request.create" eventsub-version:"1"` - HandleChannelUnbanRequestResolve EventHandler[bindings.EventChannelUnbanRequestResolve] `eventsub-type:"channel.unban_request.resolve" eventsub-version:"1"` + HandleChannelUnbanRequestCreate EventHandler[bindings.EventChannelUnbanRequestCreate] `eventsub-type:"channel.unban_request.create" eventsub-version:"beta"` + HandleChannelUnbanRequestResolve EventHandler[bindings.EventChannelUnbanRequestResolve] `eventsub-type:"channel.unban_request.resolve" eventsub-version:"beta"` HandleChannelModeratorAdd EventHandler[bindings.EventChannelModeratorAdd] `eventsub-type:"channel.moderator.add" eventsub-version:"1"` HandleChannelModeratorRemove EventHandler[bindings.EventChannelModeratorRemove] `eventsub-type:"channel.moderator.remove" eventsub-version:"1"` HandleChannelPointsRewardAdd EventHandler[bindings.EventChannelPointsRewardAdd] `eventsub-type:"channel.channel_points_custom_reward.add" eventsub-version:"1"` diff --git a/handler_test.go b/handler_test.go index 26b5b0d..7d81977 100644 --- a/handler_test.go +++ b/handler_test.go @@ -153,26 +153,25 @@ func newVerificationRequestWithType(typ string) func() *http.Request { } func newNotificationRequest() *http.Request { - bodyData := []byte(`{"subscription":{"id":"ef7e8fba-6c32-4ead-965d-61f21660d095","status":"enabled","type":"channel.update","version":"1","condition":{"broadcaster_user_id":"132532813"},"transport":{"method":"webhook","callback":"https://testing.proxy.b.dnsge.org/webhooks"},"created_at":"2023-03-09T04:44:48.057734342Z","cost":0},"event":{"broadcaster_user_id":"132532813","broadcaster_user_login":"icelys","broadcaster_user_name":"icelys","title":"hello there!","language":"en","category_id":"509658","category_name":"Just Chatting","is_mature":false}}`) + bodyData := []byte(`{"subscription":{"id":"ef7e8fba-6c32-4ead-965d-61f21660d095","status":"enabled","type":"channel.update","version":"2","condition":{"broadcaster_user_id":"132532813","moderator_user_id":"132532813"},"transport":{"method":"webhook","callback":"https://testing.proxy.b.dnsge.org/webhooks"},"created_at":"2023-03-09T04:44:48.057734342Z","cost":0},"event":{"broadcaster_user_id":"132532813","broadcaster_user_login":"icelys","broadcaster_user_name":"icelys","title":"hello there!","language":"en","category_id":"509658","category_name":"Just Chatting","content_classification_labels":[]}}`) req := httptest.NewRequest("POST", "/", bytes.NewReader(bodyData)) req.Header = http.Header{ "Content-Type": {"application/json"}, "Twitch-Eventsub-Message-Id": {"eTOJ71BBQNXGNW8qPUNMRGIHH5yv4bBrvwl02DWgF0o="}, "Twitch-Eventsub-Message-Retry": {"0"}, - "Twitch-Eventsub-Message-Signature": {"sha256=e6e0d4bc8eb792d9081be6c4fa64416b9a756c5fa4675867f38487f94751f9a6"}, "Twitch-Eventsub-Message-Timestamp": {"2023-03-09T04:45:36.836089549Z"}, "Twitch-Eventsub-Message-Type": {"notification"}, "Twitch-Eventsub-Subscription-Is-Batching-Enabled": {"false"}, "Twitch-Eventsub-Subscription-Type": {"channel.update"}, - "Twitch-Eventsub-Subscription-Version": {"1"}, + "Twitch-Eventsub-Subscription-Version": {"2"}, } return req } func newNotificationRequestBadVersion() *http.Request { - bodyData := []byte(`{"subscription":{"id":"ef7e8fba-6c32-4ead-965d-61f21660d095","status":"enabled","type":"channel.update","version":"unknown","condition":{"broadcaster_user_id":"132532813"},"transport":{"method":"webhook","callback":"https://testing.proxy.b.dnsge.org/webhooks"},"created_at":"2023-03-09T04:44:48.057734342Z","cost":0},"event":{"broadcaster_user_id":"132532813","broadcaster_user_login":"icelys","broadcaster_user_name":"icelys","title":"hello there!","language":"en","category_id":"509658","category_name":"Just Chatting","is_mature":false}}`) + bodyData := []byte(`{"subscription":{"id":"ef7e8fba-6c32-4ead-965d-61f21660d095","status":"enabled","type":"channel.update","version":"unknown","condition":{"broadcaster_user_id":"132532813","moderator_user_id":"132532813"},"transport":{"method":"webhook","callback":"https://testing.proxy.b.dnsge.org/webhooks"},"created_at":"2023-03-09T04:44:48.057734342Z","cost":0},"event":{"broadcaster_user_id":"132532813","broadcaster_user_login":"icelys","broadcaster_user_name":"icelys","title":"hello there!","language":"en","category_id":"509658","category_name":"Just Chatting","content_classification_labels":[]}}`) req := httptest.NewRequest("POST", "/", bytes.NewReader(bodyData)) req.Header = http.Header{ diff --git a/notification_handler.go b/notification_handler.go index d9afd8c..06332f3 100644 --- a/notification_handler.go +++ b/notification_handler.go @@ -73,7 +73,7 @@ func (s *SubHandler) handleNotification(w http.ResponseWriter, bodyBytes []byte, case "channel.cheer_1": err = deserializeAndCallHandler(h, notification.Event, s.HandleChannelCheer) - case "channel.follow_1": + case "channel.follow_2": err = deserializeAndCallHandler(h, notification.Event, s.HandleChannelFollow) case "channel.goal.begin_1": @@ -139,13 +139,13 @@ func (s *SubHandler) handleNotification(w http.ResponseWriter, bodyBytes []byte, case "channel.unban_1": err = deserializeAndCallHandler(h, notification.Event, s.HandleChannelUnban) - case "channel.unban_request.create_1": + case "channel.unban_request.create_beta": err = deserializeAndCallHandler(h, notification.Event, s.HandleChannelUnbanRequestCreate) - case "channel.unban_request.resolve_1": + case "channel.unban_request.resolve_beta": err = deserializeAndCallHandler(h, notification.Event, s.HandleChannelUnbanRequestResolve) - case "channel.update_1": + case "channel.update_2": err = deserializeAndCallHandler(h, notification.Event, s.HandleChannelUpdate) case "drop.entitlement.grant_1":