Skip to content

Commit 2b10cc2

Browse files
authored
Merge pull request #330 from BarryCarlyon/fix329
Fixes #329
2 parents 89451e5 + 64a102e commit 2b10cc2

39 files changed

Lines changed: 103 additions & 82 deletions

File tree

cmd/events/retrigger.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func RetriggerCommand() (command *cobra.Command) {
1919
}
2020

2121
command.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event (webhook only).")
22-
command.Flags().StringVarP(&eventID, "id", "i", "", "ID of the event to be refired.")
22+
command.Flags().StringVarP(&eventMessageID, "id", "i", "", "ID of the event to be refired.")
2323
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.")
2424
command.Flags().BoolVarP(&noConfig, "no-config", "D", false, "Disables the use of the configuration, if it exists.")
2525
command.MarkFlagRequired("id")
@@ -49,7 +49,8 @@ func retriggerCmdRun(cmd *cobra.Command, args []string) error {
4949
forwardAddress = defaults.ForwardAddress
5050
}
5151

52-
res, err := trigger.RefireEvent(eventID, trigger.TriggerParameters{
52+
//color.New().Add(color.FgGreen).Println(fmt.Sprintf(`Refire %v`, eventMessageID));
53+
res, err := trigger.RefireEvent(eventMessageID, trigger.TriggerParameters{
5354
ForwardAddress: forwardAddress,
5455
Secret: secret,
5556
Timestamp: util.GetTimestamp().Format(time.RFC3339Nano),

cmd/events/trigger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ 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.")
50+
command.Flags().StringVarP(&subscriptionID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.")
5151
command.Flags().StringVarP(&eventMessageID, "event-id", "I", "", "Manually set the Twitch-Eventsub-Message-Id header value for the event.")
5252
command.Flags().StringVar(&timestamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.")
5353
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 {
9494
for i := 0; i < count; i++ {
9595
res, err := trigger.Fire(trigger.TriggerParameters{
9696
Event: args[0],
97-
EventID: eventID,
97+
SubscriptionID: subscriptionID,
9898
EventMessageID: eventMessageID,
9999
Transport: transport,
100100
ForwardAddress: forwardAddress,

cmd/events/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var (
1010
fromUser string
1111
toUser string
1212
giftUser string
13-
eventID string
13+
subscriptionID string
1414
eventMessageID string
1515
secret string
1616
eventStatus string

cmd/events/verify_subscription.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ 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.")
36+
command.Flags().StringVarP(&subscriptionID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.")
3737
command.Flags().StringVarP(&eventMessageID, "event-id", "I", "", "Manually set the Twitch-Eventsub-Message-Id header value for the event.")
3838
command.Flags().StringVarP(&version, "version", "v", "", "Chooses the EventSub version used for a specific event. Not required for most events.")
3939
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`
9191
ForwardAddress: forwardAddress,
9292
Secret: secret,
9393
Timestamp: timestamp,
94-
EventID: eventID,
9594
EventMessageID: eventMessageID,
95+
SubscriptionID: subscriptionID,
9696
BroadcasterUserID: toUser,
9797
Version: version,
9898
})

internal/events/event.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ package events
55
// MockEventParameters are used to craft the event; most of this data is prepopulated by lower services, such as the from/to users to avoid
66
// replicating logic across files
77
type MockEventParameters struct {
8-
ID string
8+
EventMessageID string
9+
SubscriptionID string
910
Transport string
1011
Trigger string
1112
FromUserID string

internal/events/trigger/forward_event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func ForwardEvent(p ForwardParamters) (*http.Response, error) {
6868

6969
switch p.Transport {
7070
case models.TransportWebhook:
71-
req.Header.Set("Twitch-Eventsub-Message-Id", p.EventMessageID)
71+
req.Header.Set("Twitch-Eventsub-Message-Id", p.ID)
7272
req.Header.Set("Twitch-Eventsub-Subscription-Type", p.Event)
7373
req.Header.Set("Twitch-Eventsub-Subscription-Version", p.SubscriptionVersion)
7474
switch p.Type {

internal/events/trigger/retrigger_event_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ func TestRefireEvent(t *testing.T) {
2424
}))
2525
defer ts.Close()
2626

27+
var eventMessageID = "testtriggereventid";
28+
2729
params := TriggerParameters{
2830
Event: "gift",
31+
EventMessageID: eventMessageID,
2932
Transport: models.TransportWebhook,
3033
IsAnonymous: false,
3134
FromUser: "",
@@ -47,7 +50,7 @@ func TestRefireEvent(t *testing.T) {
4750
err = json.Unmarshal([]byte(response), &body)
4851
a.Nil(err)
4952

50-
json, err := RefireEvent(body.Subscription.ID, params)
53+
json, err := RefireEvent(eventMessageID, params)
5154
a.Nil(err)
5255
a.Equal(response, json)
5356
}

internal/events/trigger/trigger_event.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type TriggerParameters struct {
4242
GameID string
4343
Tier string
4444
Timestamp string
45-
EventID string
45+
SubscriptionID string
4646
EventMessageID string
4747
CharityCurrentValue int
4848
CharityTargetValue int
@@ -99,10 +99,16 @@ func Fire(p TriggerParameters) (string, error) {
9999
"Valid values are 1000, 2000 or 3000")
100100
}
101101

102+
// the header twitch-eventsub-message-id
102103
if p.EventMessageID == "" {
103104
p.EventMessageID = util.RandomGUID()
104105
}
105106

107+
// the body subscription.id
108+
if p.SubscriptionID == "" {
109+
p.SubscriptionID = util.RandomGUID()
110+
}
111+
106112
if p.Timestamp == "" {
107113
p.Timestamp = util.GetTimestamp().Format(time.RFC3339Nano)
108114
} else {
@@ -117,7 +123,8 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
117123
}
118124

119125
eventParamaters := events.MockEventParameters{
120-
ID: p.EventID,
126+
SubscriptionID: p.SubscriptionID,
127+
EventMessageID: p.EventMessageID,
121128
Trigger: p.Event,
122129
Transport: p.Transport,
123130
FromUserID: p.FromUser,
@@ -162,6 +169,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
162169
return "", err
163170
}
164171

172+
//color.New().Add(color.FgGreen).Println(fmt.Sprintf(`Insert into DB with %v`, resp.ID));
165173
err = db.NewQuery(nil, 100).InsertIntoDB(database.EventCacheParameters{
166174
ID: resp.ID,
167175
Event: p.Event,

internal/events/types/_template/_event_name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
6262
}
6363

6464
return events.MockEventResponse{
65-
ID: params.ID,
65+
ID: params.EventMessageID,
6666
JSON: event,
6767
FromUser: params.FromUserID,
6868
ToUser: params.ToUserID,

internal/events/types/ad_break/ad_break_begin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
3737
case models.TransportWebhook, models.TransportWebSocket:
3838
body := models.EventsubResponse{
3939
Subscription: models.EventsubSubscription{
40-
ID: params.ID,
40+
ID: params.SubscriptionID,
4141
Status: params.SubscriptionStatus,
4242
Type: triggerMapping[params.Transport][params.Trigger],
4343
Version: e.SubscriptionVersion(),
@@ -89,7 +89,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
8989
}
9090

9191
return events.MockEventResponse{
92-
ID: params.ID,
92+
ID: params.EventMessageID,
9393
JSON: event,
9494
FromUser: params.FromUserID,
9595
ToUser: params.ToUserID,

0 commit comments

Comments
 (0)