Skip to content

Commit 30cf222

Browse files
authored
Merge pull request #322 from SputNikPlop/event-message-id
fix: split event message id
2 parents fb0262e + 0160d80 commit 30cf222

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

cmd/events/trigger.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func TriggerCommand() (command *cobra.Command) {
4747
command.Flags().StringVarP(&description, "description", "d", "", "Title the stream should be updated with.")
4848
command.Flags().StringVarP(&gameID, "game-id", "G", "", "Sets the game/category ID for applicable events.")
4949
command.Flags().StringVarP(&tier, "tier", "", "", "Sets the subscription tier. Valid values are 1000, 2000, and 3000.")
50-
command.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") // TODO: This description will need to change with https://github.com/twitchdev/twitch-cli/issues/184
50+
command.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.")
51+
command.Flags().StringVarP(&eventMessageID, "event-id", "I", "", "Manually set the Twitch-Eventsub-Message-Id header value for the event.")
5152
command.Flags().StringVar(&timestamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.")
5253
command.Flags().IntVar(&charityCurrentValue, "charity-current-value", 0, "Only used for \"charity-*\" events. Manually set the current dollar value for charity events.")
5354
command.Flags().IntVar(&charityTargetValue, "charity-target-value", 1500000, "Only used for \"charity-*\" events. Manually set the target dollar value for charity events.")
@@ -94,6 +95,7 @@ func triggerCmdRun(cmd *cobra.Command, args []string) error {
9495
res, err := trigger.Fire(trigger.TriggerParameters{
9596
Event: args[0],
9697
EventID: eventID,
98+
EventMessageID: eventMessageID,
9799
Transport: transport,
98100
ForwardAddress: forwardAddress,
99101
FromUser: fromUser,

cmd/events/variables.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var (
1111
toUser string
1212
giftUser string
1313
eventID string
14+
eventMessageID string
1415
secret string
1516
eventStatus string
1617
subscriptionStatus string

cmd/events/verify_subscription.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func VerifySubscriptionCommand() (command *cobra.Command) {
3333
command.Flags().StringVarP(&transport, "transport", "T", "webhook", fmt.Sprintf("Preferred transport method for event. Defaults to EventSub.\nSupported values: %s", events.ValidTransports()))
3434
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.")
3535
command.Flags().StringVar(&timestamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.")
36-
command.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") // TODO: This description will need to change with https://github.com/twitchdev/twitch-cli/issues/184
36+
command.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.")
37+
command.Flags().StringVarP(&eventMessageID, "event-id", "I", "", "Manually set the Twitch-Eventsub-Message-Id header value for the event.")
3738
command.Flags().StringVarP(&version, "version", "v", "", "Chooses the EventSub version used for a specific event. Not required for most events.")
3839
command.Flags().BoolVarP(&noConfig, "no-config", "D", false, "Disables the use of the configuration, if it exists.")
3940
command.Flags().StringVarP(&toUser, "broadcaster", "b", "", "User ID of the broadcaster for the verification event.")
@@ -91,6 +92,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
9192
Secret: secret,
9293
Timestamp: timestamp,
9394
EventID: eventID,
95+
EventMessageID: eventMessageID,
9496
BroadcasterUserID: toUser,
9597
Version: version,
9698
})

internal/events/trigger/forward_event.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type ForwardParamters struct {
2424
Timestamp string
2525
Secret string
2626
Event string
27+
EventMessageID string
2728
Method string
2829
Type string
2930
SubscriptionVersion string
@@ -67,7 +68,7 @@ func ForwardEvent(p ForwardParamters) (*http.Response, error) {
6768

6869
switch p.Transport {
6970
case models.TransportWebhook:
70-
req.Header.Set("Twitch-Eventsub-Message-Id", p.ID)
71+
req.Header.Set("Twitch-Eventsub-Message-Id", p.EventMessageID)
7172
req.Header.Set("Twitch-Eventsub-Subscription-Type", p.Event)
7273
req.Header.Set("Twitch-Eventsub-Subscription-Version", p.SubscriptionVersion)
7374
switch p.Type {
@@ -83,10 +84,10 @@ func ForwardEvent(p ForwardParamters) (*http.Response, error) {
8384
// Twitch only supports IPv4 currently, so we will force this TCP connection to only use IPv4
8485
var dialer net.Dialer
8586
transport := http.DefaultTransport.(*http.Transport).Clone()
86-
transport.DialContext = func (ctx context.Context, network, addr string) (net.Conn, error) {
87+
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
8788
return dialer.DialContext(ctx, "tcp4", addr)
8889
}
89-
90+
9091
if p.Secret != "" {
9192
getSignatureHeader(req, p.ID, p.Secret, p.Transport, p.Timestamp, p.JSON)
9293
}

internal/events/trigger/retrigger_event.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func RefireEvent(id string, p TriggerParameters) (string, error) {
4848
Secret: p.Secret,
4949
JSON: []byte(res.JSON),
5050
Event: topic,
51+
EventMessageID: "",
5152
Type: EventSubMessageTypeNotification,
5253
SubscriptionVersion: e.SubscriptionVersion(),
5354
})

internal/events/trigger/trigger_event.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type TriggerParameters struct {
4242
GameID string
4343
Tier string
4444
Timestamp string
45-
EventID string // Also serves as subscription ID. See https://github.com/twitchdev/twitch-cli/issues/184
45+
EventID string
46+
EventMessageID string
4647
CharityCurrentValue int
4748
CharityTargetValue int
4849
ClientID string
@@ -98,8 +99,8 @@ func Fire(p TriggerParameters) (string, error) {
9899
"Valid values are 1000, 2000 or 3000")
99100
}
100101

101-
if p.EventID == "" {
102-
p.EventID = util.RandomGUID()
102+
if p.EventMessageID == "" {
103+
p.EventMessageID = util.RandomGUID()
103104
}
104105

105106
if p.Timestamp == "" {
@@ -194,6 +195,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
194195
Secret: p.Secret,
195196
ForwardAddress: p.ForwardAddress,
196197
Event: topic,
198+
EventMessageID: p.EventMessageID,
197199
Type: messageType,
198200
SubscriptionVersion: e.SubscriptionVersion(),
199201
})

internal/events/verify/subscription_verify.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type VerifyParameters struct {
2525
ForwardAddress string
2626
Secret string
2727
EventID string
28+
EventMessageID string
2829
Version string
2930
BroadcasterUserID string
3031
}
@@ -52,8 +53,8 @@ func VerifyWebhookSubscription(p VerifyParameters) (VerifyResponse, error) {
5253
}
5354
}
5455

55-
if p.EventID == "" {
56-
p.EventID = util.RandomGUID()
56+
if p.EventMessageID == "" {
57+
p.EventMessageID = util.RandomGUID()
5758
}
5859

5960
if p.BroadcasterUserID == "" {

0 commit comments

Comments
 (0)