-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
35 lines (29 loc) · 1.03 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"log"
"net/http"
eventsub "github.com/dnsge/twitch-eventsub-framework/v2"
"github.com/dnsge/twitch-eventsub-framework/v2/bindings"
)
const (
// Key for verifying webhook requests
secretKey = `hey this is really secret`
)
func main() {
handler := eventsub.NewHandler([]byte(secretKey))
handler.HandleChannelUpdate = func(h bindings.NotificationHeaders, sub bindings.Subscription, event bindings.EventChannelUpdate) {
fmt.Println("Got a channel.update notification!")
fmt.Printf("Message id: %s\n", h.MessageID)
fmt.Printf("Subscription id: %s\n", sub.ID)
fmt.Printf("Channel: %s Title: %s\n", event.BroadcasterUserName, event.Title)
}
// Listen on port 8080. In a real application, you would pass your mux with
// a route that uses the handler.
err := http.ListenAndServe("127.0.0.1:8080", handler)
if err != nil {
log.Fatalf("Failed to listen: %v\n", err)
}
// Test it with the Twitch CLI!
// $ twitch event trigger channel.update -v 2 -F http://127.0.0.1:8080 -s "hey this is really secret"
}