Skip to content

Commit

Permalink
Merge pull request #197 from twitchdev/eventsub-updates-nov-22
Browse files Browse the repository at this point in the history
Eventsub updates nov 22
  • Loading branch information
Xemdo authored Dec 2, 2022
2 parents fca40a4 + c6a31cf commit b7b7fb7
Show file tree
Hide file tree
Showing 22 changed files with 1,228 additions and 814 deletions.
82 changes: 44 additions & 38 deletions cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,29 @@ import (
const websubDeprecationNotice = "Halt! It appears you are trying to use WebSub, which has been deprecated. For more information, see: https://discuss.dev.twitch.tv/t/deprecation-of-websub-based-webhooks/32152"

var (
isAnonymous bool
forwardAddress string
event string
transport string
fromUser string
toUser string
giftUser string
eventID string
secret string
eventStatus string
subscriptionStatus string
itemID string
itemName string
cost int64
count int
description string
gameID string
timestamp string
debug bool
wssReconnectTest int
sslEnabled bool
isAnonymous bool
forwardAddress string
event string
transport string
fromUser string
toUser string
giftUser string
eventID string
secret string
eventStatus string
subscriptionStatus string
itemID string
itemName string
cost int64
count int
description string
gameID string
timestamp string
charityCurrentValue int
charityTargetValue int
debug bool
wssReconnectTest int
sslEnabled bool
)

var eventCmd = &cobra.Command{
Expand Down Expand Up @@ -121,6 +123,8 @@ func init() {
triggerCmd.Flags().StringVarP(&gameID, "game-id", "G", "", "Sets the game/category ID for applicable events.")
triggerCmd.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
triggerCmd.Flags().StringVar(&timestamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.")
triggerCmd.Flags().IntVar(&charityCurrentValue, "charity-current-value", 0, "Only used for \"charity-*\" events. Manually set the current dollar value for charity events.")
triggerCmd.Flags().IntVar(&charityTargetValue, "charity-target-value", 1500000, "Only used for \"charity-*\" events. Manually set the current dollar value for charity events")

// retrigger flags
retriggerCmd.Flags().StringVarP(&forwardAddress, "forward-address", "F", "", "Forward address for mock event.")
Expand Down Expand Up @@ -170,23 +174,25 @@ func triggerCmdRun(cmd *cobra.Command, args []string) {

for i := 0; i < count; i++ {
res, err := trigger.Fire(trigger.TriggerParameters{
Event: args[0],
EventID: eventID,
Transport: transport,
ForwardAddress: forwardAddress,
FromUser: fromUser,
ToUser: toUser,
GiftUser: giftUser,
Secret: secret,
IsAnonymous: isAnonymous,
EventStatus: eventStatus,
ItemID: itemID,
Cost: cost,
Description: description,
ItemName: itemName,
GameID: gameID,
SubscriptionStatus: subscriptionStatus,
Timestamp: timestamp,
Event: args[0],
EventID: eventID,
Transport: transport,
ForwardAddress: forwardAddress,
FromUser: fromUser,
ToUser: toUser,
GiftUser: giftUser,
Secret: secret,
IsAnonymous: isAnonymous,
EventStatus: eventStatus,
ItemID: itemID,
Cost: cost,
Description: description,
ItemName: itemName,
GameID: gameID,
SubscriptionStatus: subscriptionStatus,
Timestamp: timestamp,
CharityCurrentValue: charityCurrentValue,
CharityTargetValue: charityTargetValue,
})

if err != nil {
Expand Down
38 changes: 20 additions & 18 deletions internal/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ 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
Transport string
Trigger string
FromUserID string
FromUserName string
ToUserID string
ToUserName string
IsAnonymous bool
IsGift bool
EventStatus string
SubscriptionStatus string
ItemID string
ItemName string
Cost int64
IsPermanent bool
Description string
GameID string
Timestamp string
ID string
Transport string
Trigger string
FromUserID string
FromUserName string
ToUserID string
ToUserName string
IsAnonymous bool
IsGift bool
EventStatus string
SubscriptionStatus string
ItemID string
ItemName string
Cost int64
IsPermanent bool
Description string
GameID string
Timestamp string
CharityCurrentValue int
CharityTargetValue int
}

type MockEventResponse struct {
Expand Down
198 changes: 99 additions & 99 deletions internal/events/mock_wss_server/message_types.go
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
package mock_wss_server

// Generic response message Metadata; Always the same

type MessageMetadata struct {
MessageID string `json:"message_id"`
MessageType string `json:"message_type"`
MessageTimestamp string `json:"message_timestamp"`
}

/* ** Welcome message **
{ // <1>
"metadata": { // <MessageMetadata>
"message_id": "befa7b53-d79d-478f-86b9-120f112b044e",
"message_type": "session_welcome",
"message_timestamp": "2019-11-16T10:11:12.123Z"
},
"payload": { // <2>
"session": { // <3>
"id": "AQoQexAWVYKSTIu4ec_2VAxyuhAB",
"status": "connected",
"keepalive_timeout_seconds": 10,
"reconnect_url": null,
"connected_at": "2019-11-16T10:11:12.123Z"
}
}
}
*/

type WelcomeMessage struct { // <1>
Metadata MessageMetadata `json:"metadata"`
Payload WelcomeMessagePayload `json:"payload"`
}

type WelcomeMessagePayload struct { // <2>
Session WelcomeMessagePayloadSession `json:"session"`
}

type WelcomeMessagePayloadSession struct { // <3>
ID string `json:"id"`
Status string `json:"status"`
KeepaliveTimeoutSeconds int `json:"keepalive_timeout_seconds"`
ReconnectUrl *string `json:"reconnect_url"`
ConnectedAt string `json:"connected_at"`
}

/* ** Reconnect message **
{ // <1>
"metadata": { // <MessageMetadata>
"message_id": "84c1e79a-2a4b-4c13-ba0b-4312293e9308",
"message_type": "session_reconnect",
"message_timestamp": "2019-11-18T09:10:11.234Z"
},
"payload": { // <2>
"session": { // <3>
"id": "AQoQexAWVYKSTIu4ec_2VAxyuhAB",
"status": "reconnecting",
"keepalive_timeout_seconds": null,
"reconnect_url": "wss://eventsub-experimental.wss.twitch.tv?...",
"connected_at": "2019-11-16T10:11:12.123Z"
}
}
}
*/

type ReconnectMessage struct { // <1>
Metadata MessageMetadata `json:"metadata"`
Payload ReconnectMessagePayload `json:"payload"`
}

type ReconnectMessagePayload struct { // <2>
Session ReconnectMessagePayloadSession `json:"session"`
}

type ReconnectMessagePayloadSession struct { // <3>
ID string `json:"id"`
Status string `json:"status"`
KeepaliveTimeoutSeconds *int `json:"keepalive_timeout_seconds"`
ReconnectUrl string `json:"reconnect_url"`
ConnectedAt string `json:"connected_at"`
}

/* ** Keepalive message **
{ // <1>
"metadata": { // <MessageMetadata>
"message_id": "84c1e79a-2a4b-4c13-ba0b-4312293e9308",
"message_type": "session_keepalive",
"message_timestamp": "2019-11-16T10:11:12.123Z"
},
"payload": {} // struct{}
}
*/

type KeepaliveMessage struct { // <1>
Metadata MessageMetadata `json:"metadata"`
Payload KeepaliveMessagePayload `json:"payload"`
}

type KeepaliveMessagePayload struct{}
package mock_wss_server

// Generic response message Metadata; Always the same

type MessageMetadata struct {
MessageID string `json:"message_id"`
MessageType string `json:"message_type"`
MessageTimestamp string `json:"message_timestamp"`
}

/* ** Welcome message **
{ // <1>
"metadata": { // <MessageMetadata>
"message_id": "befa7b53-d79d-478f-86b9-120f112b044e",
"message_type": "session_welcome",
"message_timestamp": "2019-11-16T10:11:12.123Z"
},
"payload": { // <2>
"session": { // <3>
"id": "AQoQexAWVYKSTIu4ec_2VAxyuhAB",
"status": "connected",
"keepalive_timeout_seconds": 10,
"reconnect_url": null,
"connected_at": "2019-11-16T10:11:12.123Z"
}
}
}
*/

type WelcomeMessage struct { // <1>
Metadata MessageMetadata `json:"metadata"`
Payload WelcomeMessagePayload `json:"payload"`
}

type WelcomeMessagePayload struct { // <2>
Session WelcomeMessagePayloadSession `json:"session"`
}

type WelcomeMessagePayloadSession struct { // <3>
ID string `json:"id"`
Status string `json:"status"`
KeepaliveTimeoutSeconds int `json:"keepalive_timeout_seconds"`
ReconnectUrl *string `json:"reconnect_url"`
ConnectedAt string `json:"connected_at"`
}

/* ** Reconnect message **
{ // <1>
"metadata": { // <MessageMetadata>
"message_id": "84c1e79a-2a4b-4c13-ba0b-4312293e9308",
"message_type": "session_reconnect",
"message_timestamp": "2019-11-18T09:10:11.234Z"
},
"payload": { // <2>
"session": { // <3>
"id": "AQoQexAWVYKSTIu4ec_2VAxyuhAB",
"status": "reconnecting",
"keepalive_timeout_seconds": null,
"reconnect_url": "wss://eventsub-experimental.wss.twitch.tv?...",
"connected_at": "2019-11-16T10:11:12.123Z"
}
}
}
*/

type ReconnectMessage struct { // <1>
Metadata MessageMetadata `json:"metadata"`
Payload ReconnectMessagePayload `json:"payload"`
}

type ReconnectMessagePayload struct { // <2>
Session ReconnectMessagePayloadSession `json:"session"`
}

type ReconnectMessagePayloadSession struct { // <3>
ID string `json:"id"`
Status string `json:"status"`
KeepaliveTimeoutSeconds *int `json:"keepalive_timeout_seconds"`
ReconnectUrl string `json:"reconnect_url"`
ConnectedAt string `json:"connected_at"`
}

/* ** Keepalive message **
{ // <1>
"metadata": { // <MessageMetadata>
"message_id": "84c1e79a-2a4b-4c13-ba0b-4312293e9308",
"message_type": "session_keepalive",
"message_timestamp": "2019-11-16T10:11:12.123Z"
},
"payload": {} // struct{}
}
*/

type KeepaliveMessage struct { // <1>
Metadata MessageMetadata `json:"metadata"`
Payload KeepaliveMessagePayload `json:"payload"`
}

type KeepaliveMessagePayload struct{}
Loading

0 comments on commit b7b7fb7

Please sign in to comment.