This is only a proof of concept.
-
Start ngrok server and note URL (preferably the HTTPS one)
-
Rename
config.py.example
toconfig.py
and fill out the relevent keys / URL.UIDS
should be a list of user IDs as strings, orNone
to automatically get some User IDs from the 'Get Stream' endpoint. -
Run
python server.py
leave this running to monitor requests coming back from twitch. -
Run
python notify.py
in another terminal, and output should look like:
{'access_token': '_REDACTED_', 'expires_in': 4852660, 'token_type': 'bearer'}
---------
<Response [202]>
---------
b'{"total":1,"data":[{"topic":"https://api.twitch.tv/helix/streams?user_id=5678","callback":"https://_REDACTED_.ngrok.io/","expires_at":"2019-10-02T11:26:33Z"}],"pagination":{}}'
---------
- Subsequent runs of
notify.py
should add further items to the responsedata
list of the third request.
## Notes to self
A stream offline event looks like this in the server console:
Host: __REDACTED__.ngrok.io
User-Agent: Go-http-client/1.1
Connection: close
Content-Length: 11
Content-Type: application/json; charset=utf-8
Link: <https://api.twitch.tv/helix/webhooks/hub>; rel="hub", <https://api.twitch.tv/helix/streams?user_id=40017619>; rel="self"
Twitch-Notification-Id: __REDACTED__
Twitch-Notification-Timestamp: 2019-10-03T00:09:45Z
Accept-Encoding: gzip
X-Forwarded-Proto: https
X-Forwarded-For: __REDACTED__
b'{"data":[]}'
A stream change event looks like this in the server console:
Host: __REDACTED__.ngrok.io
User-Agent: Go-http-client/1.1
Connection: close
Content-Length: 353
Content-Type: application/json; charset=utf-8
Link: <https://api.twitch.tv/helix/webhooks/hub>; rel="hub", <https://api.twitch.tv/helix/streams?user_id=26301881>; rel="self"
Twitch-Notification-Id: __REDACTED__
Twitch-Notification-Timestamp: 2019-10-03T01:07:55Z
Accept-Encoding: gzip
X-Forwarded-Proto: https
X-Forwarded-For: __REDACTED__
b'{"data":[{"game_id":"505705","id":"35849957184","language":"en","started_at":"2019-10-02T19:08:56Z","tag_ids":["6ea6bca4-4712-4ab9-a906-e3336a9d8039"],"thumbnail_url":"https://static-cdn.jtvnw.net/previews-ttv/live_user_sodapoppin-{width}x{height}.jpg","title":"Stream","type":"live","user_id":"26301881","user_name":"sodapoppin","viewer_count":18798}]}'
Some info on hub.secret
which is so far misterious:
https://discuss.dev.twitch.tv/t/how-to-use-the-hub-secret-with-web-hooks/13356