From 0bb6a052109f8bde5009a01732ac155670fd046a Mon Sep 17 00:00:00 2001 From: Daniel Sage Date: Fri, 26 Jan 2024 17:44:50 -0500 Subject: [PATCH] Add support for channel.chat.message --- go.mod | 2 +- go.sum | 4 ++-- handler.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b408d9b..d04eebd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/dnsge/twitch-eventsub-framework go 1.17 require ( - github.com/dnsge/twitch-eventsub-bindings v1.2.0 + github.com/dnsge/twitch-eventsub-bindings v1.2.1 github.com/mozillazg/go-httpheader v0.3.0 github.com/stretchr/testify v1.8.2 ) diff --git a/go.sum b/go.sum index 4f02c3f..b6fb485 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dnsge/twitch-eventsub-bindings v1.2.0 h1:iqIwGf8MLXPHKZZorvvMaiCvSf6iftdKar5SXPeAojY= -github.com/dnsge/twitch-eventsub-bindings v1.2.0/go.mod h1:Zbj+TpgcdNu4Gj6+6KG/+A7EvWMDbzQ+UGm35P918pc= +github.com/dnsge/twitch-eventsub-bindings v1.2.1 h1:PTn3o8ctiH9rdzXPGqSG5iIqIvGKV9EZ9pU54zDUjp4= +github.com/dnsge/twitch-eventsub-bindings v1.2.1/go.mod h1:Zbj+TpgcdNu4Gj6+6KG/+A7EvWMDbzQ+UGm35P918pc= github.com/mozillazg/go-httpheader v0.3.0 h1:3brX5z8HTH+0RrNA1362Rc3HsaxyWEKtGY45YrhuINM= github.com/mozillazg/go-httpheader v0.3.0/go.mod h1:PuT8h0pw6efvp8ZeUec1Rs7dwjK08bt6gKSReGMqtdA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/handler.go b/handler.go index 56368d2..79e99f5 100644 --- a/handler.go +++ b/handler.go @@ -122,6 +122,7 @@ type SubHandler struct { event *esb.EventUserAuthorizationRevoke, ) + HandleChannelChatMessage func(h *esb.ResponseHeaders, event *esb.EventChannelChatMessage) HandleChannelChatClear func(h *esb.ResponseHeaders, event *esb.EventChannelChatClear) HandleChannelChatClearUserMessages func( h *esb.ResponseHeaders, @@ -594,6 +595,15 @@ func (s *SubHandler) handleNotification( if s.HandleUserUpdate != nil { go s.HandleUserUpdate(h, &data) } + case "channel.chat.message": + var data esb.EventChannelChatMessage + if err := json.Unmarshal(event, &data); err != nil { + http.Error(w, "Invalid JSON body", http.StatusBadRequest) + return + } + if s.HandleChannelChatMessage != nil { + go s.HandleChannelChatMessage(h, &data) + } case "channel.chat.clear": var data esb.EventChannelChatClear if err := json.Unmarshal(event, &data); err != nil {