diff --git a/cmd/events/retrigger.go b/cmd/events/retrigger.go index a2942d41..eebe56ba 100644 --- a/cmd/events/retrigger.go +++ b/cmd/events/retrigger.go @@ -19,7 +19,7 @@ func RetriggerCommand() (command *cobra.Command) { } command.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event (webhook only).") - command.Flags().StringVarP(&eventID, "id", "i", "", "ID of the event to be refired.") + command.Flags().StringVarP(&eventMessageID, "id", "i", "", "ID of the event to be refired.") command.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be 10-100 characters in length.") command.Flags().BoolVarP(&noConfig, "no-config", "D", false, "Disables the use of the configuration, if it exists.") command.MarkFlagRequired("id") @@ -49,7 +49,8 @@ func retriggerCmdRun(cmd *cobra.Command, args []string) error { forwardAddress = defaults.ForwardAddress } - res, err := trigger.RefireEvent(eventID, trigger.TriggerParameters{ + //color.New().Add(color.FgGreen).Println(fmt.Sprintf(`Refire %v`, eventMessageID)); + res, err := trigger.RefireEvent(eventMessageID, trigger.TriggerParameters{ ForwardAddress: forwardAddress, Secret: secret, Timestamp: util.GetTimestamp().Format(time.RFC3339Nano), diff --git a/cmd/events/trigger.go b/cmd/events/trigger.go index d7fd4616..af8811da 100644 --- a/cmd/events/trigger.go +++ b/cmd/events/trigger.go @@ -47,7 +47,7 @@ func TriggerCommand() (command *cobra.Command) { command.Flags().StringVarP(&description, "description", "d", "", "Title the stream should be updated with.") command.Flags().StringVarP(&gameID, "game-id", "G", "", "Sets the game/category ID for applicable events.") command.Flags().StringVarP(&tier, "tier", "", "", "Sets the subscription tier. Valid values are 1000, 2000, and 3000.") - command.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") + command.Flags().StringVarP(&subscriptionID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") command.Flags().StringVarP(&eventMessageID, "event-id", "I", "", "Manually set the Twitch-Eventsub-Message-Id header value for the event.") command.Flags().StringVar(×tamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.") command.Flags().IntVar(&charityCurrentValue, "charity-current-value", 0, "Only used for \"charity-*\" events. Manually set the current dollar value for charity events.") @@ -94,7 +94,7 @@ func triggerCmdRun(cmd *cobra.Command, args []string) error { for i := 0; i < count; i++ { res, err := trigger.Fire(trigger.TriggerParameters{ Event: args[0], - EventID: eventID, + SubscriptionID: subscriptionID, EventMessageID: eventMessageID, Transport: transport, ForwardAddress: forwardAddress, diff --git a/cmd/events/variables.go b/cmd/events/variables.go index 187a9990..24cb596a 100644 --- a/cmd/events/variables.go +++ b/cmd/events/variables.go @@ -10,7 +10,7 @@ var ( fromUser string toUser string giftUser string - eventID string + subscriptionID string eventMessageID string secret string eventStatus string diff --git a/cmd/events/verify_subscription.go b/cmd/events/verify_subscription.go index f27b149e..cea4adeb 100644 --- a/cmd/events/verify_subscription.go +++ b/cmd/events/verify_subscription.go @@ -33,7 +33,7 @@ func VerifySubscriptionCommand() (command *cobra.Command) { command.Flags().StringVarP(&transport, "transport", "T", "webhook", fmt.Sprintf("Preferred transport method for event. Defaults to EventSub.\nSupported values: %s", events.ValidTransports())) command.Flags().StringVarP(&secret, "secret", "s", "", "Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be 10-100 characters in length.") command.Flags().StringVar(×tamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.") - command.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") + command.Flags().StringVarP(&subscriptionID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") command.Flags().StringVarP(&eventMessageID, "event-id", "I", "", "Manually set the Twitch-Eventsub-Message-Id header value for the event.") command.Flags().StringVarP(&version, "version", "v", "", "Chooses the EventSub version used for a specific event. Not required for most events.") command.Flags().BoolVarP(&noConfig, "no-config", "D", false, "Disables the use of the configuration, if it exists.") @@ -91,8 +91,8 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event` ForwardAddress: forwardAddress, Secret: secret, Timestamp: timestamp, - EventID: eventID, EventMessageID: eventMessageID, + SubscriptionID: subscriptionID, BroadcasterUserID: toUser, Version: version, }) diff --git a/internal/events/event.go b/internal/events/event.go index fc56866e..43967245 100644 --- a/internal/events/event.go +++ b/internal/events/event.go @@ -5,7 +5,8 @@ package events // MockEventParameters are used to craft the event; most of this data is prepopulated by lower services, such as the from/to users to avoid // replicating logic across files type MockEventParameters struct { - ID string + EventMessageID string + SubscriptionID string Transport string Trigger string FromUserID string diff --git a/internal/events/trigger/forward_event.go b/internal/events/trigger/forward_event.go index 893bcf48..eee6099f 100644 --- a/internal/events/trigger/forward_event.go +++ b/internal/events/trigger/forward_event.go @@ -68,7 +68,7 @@ func ForwardEvent(p ForwardParamters) (*http.Response, error) { switch p.Transport { case models.TransportWebhook: - req.Header.Set("Twitch-Eventsub-Message-Id", p.EventMessageID) + req.Header.Set("Twitch-Eventsub-Message-Id", p.ID) req.Header.Set("Twitch-Eventsub-Subscription-Type", p.Event) req.Header.Set("Twitch-Eventsub-Subscription-Version", p.SubscriptionVersion) switch p.Type { diff --git a/internal/events/trigger/retrigger_event_test.go b/internal/events/trigger/retrigger_event_test.go index 86866fe3..b93504c4 100644 --- a/internal/events/trigger/retrigger_event_test.go +++ b/internal/events/trigger/retrigger_event_test.go @@ -24,8 +24,11 @@ func TestRefireEvent(t *testing.T) { })) defer ts.Close() + var eventMessageID = "testtriggereventid"; + params := TriggerParameters{ Event: "gift", + EventMessageID: eventMessageID, Transport: models.TransportWebhook, IsAnonymous: false, FromUser: "", @@ -47,7 +50,7 @@ func TestRefireEvent(t *testing.T) { err = json.Unmarshal([]byte(response), &body) a.Nil(err) - json, err := RefireEvent(body.Subscription.ID, params) + json, err := RefireEvent(eventMessageID, params) a.Nil(err) a.Equal(response, json) } diff --git a/internal/events/trigger/trigger_event.go b/internal/events/trigger/trigger_event.go index aeb65c25..3d3f7da8 100644 --- a/internal/events/trigger/trigger_event.go +++ b/internal/events/trigger/trigger_event.go @@ -42,7 +42,7 @@ type TriggerParameters struct { GameID string Tier string Timestamp string - EventID string + SubscriptionID string EventMessageID string CharityCurrentValue int CharityTargetValue int @@ -99,10 +99,16 @@ func Fire(p TriggerParameters) (string, error) { "Valid values are 1000, 2000 or 3000") } + // the header twitch-eventsub-message-id if p.EventMessageID == "" { p.EventMessageID = util.RandomGUID() } + // the body subscription.id + if p.SubscriptionID == "" { + p.SubscriptionID = util.RandomGUID() + } + if p.Timestamp == "" { p.Timestamp = util.GetTimestamp().Format(time.RFC3339Nano) } else { @@ -117,7 +123,8 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event` } eventParamaters := events.MockEventParameters{ - ID: p.EventID, + SubscriptionID: p.SubscriptionID, + EventMessageID: p.EventMessageID, Trigger: p.Event, Transport: p.Transport, FromUserID: p.FromUser, @@ -162,6 +169,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event` return "", err } + //color.New().Add(color.FgGreen).Println(fmt.Sprintf(`Insert into DB with %v`, resp.ID)); err = db.NewQuery(nil, 100).InsertIntoDB(database.EventCacheParameters{ ID: resp.ID, Event: p.Event, diff --git a/internal/events/types/_template/_event_name.go b/internal/events/types/_template/_event_name.go index cab2638d..ac9de604 100644 --- a/internal/events/types/_template/_event_name.go +++ b/internal/events/types/_template/_event_name.go @@ -62,7 +62,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/ad_break/ad_break_begin.go b/internal/events/types/ad_break/ad_break_begin.go index 91a7d7b1..4143eaf9 100644 --- a/internal/events/types/ad_break/ad_break_begin.go +++ b/internal/events/types/ad_break/ad_break_begin.go @@ -37,7 +37,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -89,7 +89,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/authorization_grant/grant.go b/internal/events/types/authorization_grant/grant.go index f51c2f0b..c08cea45 100644 --- a/internal/events/types/authorization_grant/grant.go +++ b/internal/events/types/authorization_grant/grant.go @@ -33,7 +33,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook: body := &models.AuthorizationRevokeEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -79,7 +79,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/authorization_revoke/revoke.go b/internal/events/types/authorization_revoke/revoke.go index d0da37d4..4467ca77 100644 --- a/internal/events/types/authorization_revoke/revoke.go +++ b/internal/events/types/authorization_revoke/revoke.go @@ -36,7 +36,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.AuthorizationRevokeEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -87,7 +87,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/ban/ban.go b/internal/events/types/ban/ban.go index 8d71ff00..a204958d 100644 --- a/internal/events/types/ban/ban.go +++ b/internal/events/types/ban/ban.go @@ -110,7 +110,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -152,7 +152,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/channel_points_redemption/redemption_event.go b/internal/events/types/channel_points_redemption/redemption_event.go index 42adf911..dcec0639 100644 --- a/internal/events/types/channel_points_redemption/redemption_event.go +++ b/internal/events/types/channel_points_redemption/redemption_event.go @@ -55,7 +55,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.RedemptionEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -70,7 +70,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven CreatedAt: params.Timestamp, }, Event: models.RedemptionEventSubEvent{ - ID: params.ID, + ID: util.RandomGUID(), BroadcasterUserID: params.ToUserID, BroadcasterUserLogin: params.ToUserName, BroadcasterUserName: params.ToUserName, @@ -114,7 +114,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/channel_points_reward/reward_event.go b/internal/events/types/channel_points_reward/reward_event.go index 589ed815..45ef42e0 100644 --- a/internal/events/types/channel_points_reward/reward_event.go +++ b/internal/events/types/channel_points_reward/reward_event.go @@ -8,6 +8,7 @@ import ( "github.com/twitchdev/twitch-cli/internal/events" "github.com/twitchdev/twitch-cli/internal/models" + "github.com/twitchdev/twitch-cli/internal/util" ) var transportsSupported = map[string]bool{ @@ -48,7 +49,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -63,7 +64,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven CreatedAt: params.Timestamp, }, Event: models.RewardEventSubEvent{ - ID: params.ID, + ID: util.RandomGUID(), BroadcasterUserID: params.ToUserID, BroadcasterUserLogin: params.ToUserName, BroadcasterUserName: params.ToUserName, @@ -128,7 +129,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.ToUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/channel_update_v1/channel_update.go b/internal/events/types/channel_update_v1/channel_update.go index 9bbb2241..64ca229e 100644 --- a/internal/events/types/channel_update_v1/channel_update.go +++ b/internal/events/types/channel_update_v1/channel_update.go @@ -49,7 +49,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := &models.EventsubResponse{ // make the eventsub response (if supported) Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -99,7 +99,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/channel_update_v2/channel_update.go b/internal/events/types/channel_update_v2/channel_update.go index d0f6d3ac..57972246 100644 --- a/internal/events/types/channel_update_v2/channel_update.go +++ b/internal/events/types/channel_update_v2/channel_update.go @@ -49,7 +49,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := &models.EventsubResponse{ // make the eventsub response (if supported) Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -102,7 +102,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/charity/charity_event.go b/internal/events/types/charity/charity_event.go index ec178054..aa68331e 100644 --- a/internal/events/types/charity/charity_event.go +++ b/internal/events/types/charity/charity_event.go @@ -139,7 +139,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), Status: params.SubscriptionStatus, @@ -199,7 +199,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, ToUser: params.ToUserID, }, nil diff --git a/internal/events/types/cheer/cheer_event.go b/internal/events/types/cheer/cheer_event.go index ab359f13..1db7f16f 100644 --- a/internal/events/types/cheer/cheer_event.go +++ b/internal/events/types/cheer/cheer_event.go @@ -45,7 +45,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -97,7 +97,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/drop/drop.go b/internal/events/types/drop/drop.go index ab8c470d..589d90d6 100644 --- a/internal/events/types/drop/drop.go +++ b/internal/events/types/drop/drop.go @@ -78,7 +78,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } body := &models.DropsEntitlementEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -121,7 +121,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/extension_transaction/transaction_event.go b/internal/events/types/extension_transaction/transaction_event.go index 66ff267d..61e129ee 100644 --- a/internal/events/types/extension_transaction/transaction_event.go +++ b/internal/events/types/extension_transaction/transaction_event.go @@ -8,6 +8,7 @@ import ( "github.com/twitchdev/twitch-cli/internal/events" "github.com/twitchdev/twitch-cli/internal/models" + "github.com/twitchdev/twitch-cli/internal/util" ) var transportsSupported = map[string]bool{ @@ -44,7 +45,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook: body := &models.TransactionEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -59,7 +60,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven CreatedAt: params.Timestamp, }, Event: models.TransactionEventSubEvent{ - ID: params.ID, + ID: util.RandomGUID(), ExtensionClientID: params.ClientID, BroadcasterUserID: params.ToUserID, BroadcasterUserLogin: "testBroadcaster", @@ -100,7 +101,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/follow/follow_event.go b/internal/events/types/follow/follow_event.go index 93eb4398..0edf4b87 100644 --- a/internal/events/types/follow/follow_event.go +++ b/internal/events/types/follow/follow_event.go @@ -35,7 +35,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -86,7 +86,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/gift/channel_gift.go b/internal/events/types/gift/channel_gift.go index 7f3a5cba..c71d4388 100644 --- a/internal/events/types/gift/channel_gift.go +++ b/internal/events/types/gift/channel_gift.go @@ -48,7 +48,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.GiftEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -103,7 +103,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/goal/goal_event.go b/internal/events/types/goal/goal_event.go index 410041a9..4273c10d 100644 --- a/internal/events/types/goal/goal_event.go +++ b/internal/events/types/goal/goal_event.go @@ -71,7 +71,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -86,7 +86,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven CreatedAt: params.Timestamp, }, Event: models.GoalEventSubEvent{ - ID: params.ID, + ID: util.RandomGUID(), BroadcasterUserID: params.ToUserID, BroadcasterUserLogin: params.ToUserName, BroadcasterUserName: params.ToUserName, @@ -125,7 +125,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/hype_train/hype_train_event.go b/internal/events/types/hype_train/hype_train_event.go index 266c2e00..0ea30394 100644 --- a/internal/events/types/hype_train/hype_train_event.go +++ b/internal/events/types/hype_train/hype_train_event.go @@ -51,7 +51,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.HypeTrainEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -66,7 +66,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven CreatedAt: params.Timestamp, }, Event: models.HypeTrainEventSubEvent{ - ID: params.ID, + ID: util.RandomGUID(), BroadcasterUserID: params.ToUserID, BroadcasterUserLogin: params.ToUserName, BroadcasterUserName: params.ToUserName, @@ -136,7 +136,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven return events.MockEventResponse{}, nil } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/moderator_change/moderator_change_event.go b/internal/events/types/moderator_change/moderator_change_event.go index 3cab76ea..5c38565a 100644 --- a/internal/events/types/moderator_change/moderator_change_event.go +++ b/internal/events/types/moderator_change/moderator_change_event.go @@ -39,7 +39,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -88,7 +88,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/poll/poll.go b/internal/events/types/poll/poll.go index 6dc6d918..0a77da30 100644 --- a/internal/events/types/poll/poll.go +++ b/internal/events/types/poll/poll.go @@ -61,7 +61,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := &models.PollEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -128,7 +128,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/prediction/prediction.go b/internal/events/types/prediction/prediction.go index c83df9cf..642ee83b 100644 --- a/internal/events/types/prediction/prediction.go +++ b/internal/events/types/prediction/prediction.go @@ -92,7 +92,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := &models.PredictionEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -154,7 +154,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/raid/raid.go b/internal/events/types/raid/raid.go index 21bdbe6f..04672e45 100644 --- a/internal/events/types/raid/raid.go +++ b/internal/events/types/raid/raid.go @@ -37,7 +37,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.RaidEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -86,7 +86,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/shield_mode/shield_mode.go b/internal/events/types/shield_mode/shield_mode.go index b87e59cc..e0274ed7 100644 --- a/internal/events/types/shield_mode/shield_mode.go +++ b/internal/events/types/shield_mode/shield_mode.go @@ -54,7 +54,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := models.ShieldModeEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -97,7 +97,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, ToUser: params.ToUserID, FromUser: params.FromUserID, diff --git a/internal/events/types/shoutout/shoutout.go b/internal/events/types/shoutout/shoutout.go index 39c2e3b7..2cad5f05 100644 --- a/internal/events/types/shoutout/shoutout.go +++ b/internal/events/types/shoutout/shoutout.go @@ -45,7 +45,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven if params.Trigger == "shoutout-create" { body := models.ShoutoutCreateEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -84,7 +84,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } else if params.Trigger == "shoutout-received" { body := models.ShoutoutReceivedEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -137,7 +137,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, ToUser: params.ToUserID, FromUser: params.FromUserID, diff --git a/internal/events/types/streamdown/streamdown.go b/internal/events/types/streamdown/streamdown.go index c84bab22..ac81a6ba 100644 --- a/internal/events/types/streamdown/streamdown.go +++ b/internal/events/types/streamdown/streamdown.go @@ -36,7 +36,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -81,7 +81,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/streamup/streamup.go b/internal/events/types/streamup/streamup.go index 991b5520..8d7292a7 100644 --- a/internal/events/types/streamup/streamup.go +++ b/internal/events/types/streamup/streamup.go @@ -45,7 +45,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -93,7 +93,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/subscribe/sub_event.go b/internal/events/types/subscribe/sub_event.go index 6f8d21b2..80d6e8f8 100644 --- a/internal/events/types/subscribe/sub_event.go +++ b/internal/events/types/subscribe/sub_event.go @@ -51,7 +51,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -102,7 +102,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/subscription_message/subscription_message.go b/internal/events/types/subscription_message/subscription_message.go index bb75dc99..7a9a993c 100644 --- a/internal/events/types/subscription_message/subscription_message.go +++ b/internal/events/types/subscription_message/subscription_message.go @@ -41,7 +41,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := &models.SubscribeMessageEventSubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -107,7 +107,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/unban/unban.go b/internal/events/types/unban/unban.go index 0daa787d..20fb0fca 100644 --- a/internal/events/types/unban/unban.go +++ b/internal/events/types/unban/unban.go @@ -49,7 +49,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -91,7 +91,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, FromUser: params.FromUserID, ToUser: params.ToUserID, diff --git a/internal/events/types/unban_requests/unban_requests.go b/internal/events/types/unban_requests/unban_requests.go index 06ec3540..4105d2fe 100644 --- a/internal/events/types/unban_requests/unban_requests.go +++ b/internal/events/types/unban_requests/unban_requests.go @@ -75,7 +75,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), Status: params.SubscriptionStatus, @@ -118,7 +118,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, ToUser: params.ToUserID, }, nil diff --git a/internal/events/types/user/user_update.go b/internal/events/types/user/user_update.go index 2f4528d9..20b82317 100644 --- a/internal/events/types/user/user_update.go +++ b/internal/events/types/user/user_update.go @@ -35,7 +35,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven case models.TransportWebhook, models.TransportWebSocket: body := models.EventsubResponse{ Subscription: models.EventsubSubscription{ - ID: params.ID, + ID: params.SubscriptionID, Status: params.SubscriptionStatus, Type: triggerMapping[params.Transport][params.Trigger], Version: e.SubscriptionVersion(), @@ -84,7 +84,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven } return events.MockEventResponse{ - ID: params.ID, + ID: params.EventMessageID, JSON: event, ToUser: params.ToUserID, }, nil diff --git a/internal/events/verify/subscription_verify.go b/internal/events/verify/subscription_verify.go index 61933ea7..65956b80 100644 --- a/internal/events/verify/subscription_verify.go +++ b/internal/events/verify/subscription_verify.go @@ -24,7 +24,7 @@ type VerifyParameters struct { Event string ForwardAddress string Secret string - EventID string + SubscriptionID string EventMessageID string Version string BroadcasterUserID string @@ -53,15 +53,21 @@ func VerifyWebhookSubscription(p VerifyParameters) (VerifyResponse, error) { } } + // the header twitch-eventsub-message-id if p.EventMessageID == "" { p.EventMessageID = util.RandomGUID() } + // the body subscription.id + if p.SubscriptionID == "" { + p.SubscriptionID = util.RandomGUID() + } + if p.BroadcasterUserID == "" { p.BroadcasterUserID = util.RandomUserID() } - body, err := generateWebhookSubscriptionBody(p.Transport, p.EventID, event.GetTopic(p.Transport, p.Event), event.SubscriptionVersion(), p.BroadcasterUserID, challenge, p.ForwardAddress) + body, err := generateWebhookSubscriptionBody(p.Transport, p.EventMessageID, p.SubscriptionID, event.GetTopic(p.Transport, p.Event), event.SubscriptionVersion(), p.BroadcasterUserID, challenge, p.ForwardAddress) if err != nil { return VerifyResponse{}, err } @@ -139,7 +145,7 @@ func VerifyWebhookSubscription(p VerifyParameters) (VerifyResponse, error) { return r, nil } -func generateWebhookSubscriptionBody(transport string, eventID string, event string, subscriptionVersion string, broadcaster string, challenge string, callback string) (trigger.TriggerResponse, error) { +func generateWebhookSubscriptionBody(transport string, messageID string, subscriptionID string, event string, subscriptionVersion string, broadcaster string, challenge string, callback string) (trigger.TriggerResponse, error) { var res []byte var err error ts := util.GetTimestamp().Format(time.RFC3339Nano) @@ -148,7 +154,7 @@ func generateWebhookSubscriptionBody(transport string, eventID string, event str body := models.EventsubSubscriptionVerification{ Challenge: challenge, Subscription: models.EventsubSubscription{ - ID: eventID, + ID: subscriptionID, Status: "webhook_callback_verification_pending", Type: event, Version: subscriptionVersion, @@ -170,7 +176,7 @@ func generateWebhookSubscriptionBody(transport string, eventID string, event str res = []byte("") } return trigger.TriggerResponse{ - ID: eventID, + ID: messageID, JSON: res, Timestamp: ts, }, nil