This seems directly contradictory based on what the webhook API says, since I’ve been testing this locally for a while now and everything seems to work fine
So when I create an eventsub subscription with helix
resp, err := client.CreateEventSubSubscription(&helix.EventSubSubscription{
Type: helix.EventSubTypeChannelFollow,
Version: "2",
Condition: helix.EventSubCondition{
BroadcasterUserID: os.Getenv("BROADCASTER_ID"),
ModeratorUserID: os.Getenv("BOT_ID"),
},
Transport: helix.EventSubTransport{
Method: "webhook",
Callback: "https://localhost:443",
Secret: os.Getenv("EVENTSUB_SECRET"),
},
})
And then call that with a twitch API command and it works
twitch event trigger subscribe -f 57810555 -t 5678 -F http://localhost:3000/eventsub -s xxxxx
✔ Request Sent. Received Status Code: 200
✔ Server Said: ok
{"subscription":{"id":"xxxx","status":"enabled","type":"channel.subscribe","version":"1","condition":{"broadcaster_user_id":"5678"},"transport":{"method":"webhook","callback":"null"},"created_at":"2024-08-30T17:57:24.168707519Z","cost":0},"event":{"user_id":"57810555","user_login":"testFromUser","user_name":"testFromUser","broadcaster_user_id":"5678","broadcaster_user_login":"testBroadcaster","broadcaster_user_name":"testBroadcaster","tier":"1000","is_gift":false}}
and my program gets the notification
# my print statements
Got Sub event!
testFromUser subbed to testBroadcaster, and was it gift? false
User exists!
Does user exist? true
This isn’t the intended pattern?
I tried setting up NGROK and got some progress, after setting up eventsub with the code above and the callback set to the ngrok endpoint, I got some POST commands with verification pending after trying to start some eventsub subscriptions, what do I need to change to get the challenge verification working?
# callback line in the above helix subscription code
Callback: "https://my-temp-domain.ngrok-free.app",
# eventsub listener
func startTwitchListeners() {
http.HandleFunc("/eventsub", eventSubHandler)
http.ListenAndServe(":3000", nil)
}
# eventsub handler
func eventSubHandler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Got some sort of eventsub thing\n")
body, err := io.ReadAll(r.Body)
if err != nil {
fmt.Printf("%s\n",err)
return
}
defer r.Body.Close()
// verify that the notification came from twitch using the secret.
if !helix.VerifyEventSubNotification(os.Getenv("EVENTSUB_SECRET"), r.Header, string(body)) {
fmt.Printf("no valid signature on subscription")
return
} else {
fmt.Printf("verified signature for subscription\n")
}
var vals eventSubNotification
err = json.NewDecoder(bytes.NewReader(body)).Decode(&vals)
if err != nil {
fmt.Printf("%d\n",err)
return
}
// this line prints the whole notif if we wanna see it, but we probably don't every time
// fmt.Printf("\n\n\n%+v\n\n\n",vals)
// if there's a challenge in the request,
// respond with only the challenge to verify your eventsub.
if vals.Challenge != "" {
w.Write([]byte(vals.Challenge))
return
}
# 502 Bad Gateway error in NGROK inspect
{
"subscription": {
"id": "subscription-id",
"status": "webhook_callback_verification_pending",
"type": "channel.follow",
"version": "2",
"condition": {
"broadcaster_user_id": "57810555",
"moderator_user_id": "123645880"
},
"transport": {
"method": "webhook",
"callback": "https://my-temporary-domain.ngrok-free.app"
},
"created_at": "2024-08-30T18:02:44.454559311Z",
"cost": 0
},
"challenge": "challenge"
}