You cannot get the total by a WebSocket but you can get new chat subscriber events as they occur.
Either
- connect to chat and consume the events - Twitch IRC Tags | Twitch Developers - an example https://github.com/BarryCarlyon/twitch_misc/tree/main/chat
- connect to pubsub and consume the events - PubSub | Twitch Developers - an example https://github.com/BarryCarlyon/twitch_misc/tree/main/pubsub
- wait for EventSub to have WebSocket Support and consume the events. - RFC 0016 - EventSub WebSockets - #7 by BarryCarlyon
This looks like you are connecting to chat and this looks correct. You will need to preceend the channel name with a ‘#’ and needs it a;; to be lowser case. In theory you could use the anon login. saves juggily tokens.
Then just parse for messages of type USERSTATE
instead of PRIVMSG
then you’ll get (re)subscriptions shared in chat.
You cannot get the total subs from a WebSocket, you’ll need to poll the API for the current count. Reference | Twitch Developers which will need the token