I am pretty new to Twitch so I need basic help. I am modifying the JavaScript created via a “Custom Widget”. What I am trying to do is to gift certain users as they subscribe to my channel by making him/her a VIP (I assume trough the “isVIP” boolean). I am using Java Script created a Stream Elements (SE)custom widget but although I can get a notification when a user subscribes, SE does not give me access a user’s properties, so now I am at square one.
Based on what I described above, can anyone point me to a JS boilerplate where something similar may have been done. If not, what steps would I need to set this up and then gain access to a users to make him/her a VIP.
Thank you so much. This information greatly helps. I have played around with a simple bot previously, so that should get me started. A couple of quick questions about your comments
That will listen for a new subscriber and then VIP the subscriber. But it will need to be logged in as the broadcaster.
When you says “listen”, do you mean the “client.on” command. Will I just need to use something like: “client.on(‘sub’, (channel, tags, message, self) …” ? or is there some other method to listen for a new subsriber?
> You’d probably run out of VIP’s quick, since you only have a finite number of VIP Slots.
Thanks for this tip. I was not aware of this. The gifted VIP is only for 24 hours, so I plan to store the user’s info in a db and then each day run through it to clear out those who have expired. Do you see a problem with this approach?
Sorry for these basic questions but I am just getting started on this platform.
client.on sounds like you are using a library, so refer to that libraries documentation. I personally don’t use a library for my bots (beyond WS for connection handling) so to “listen” for a sub I parse the relevant message(s) in chat.
By “listen” I mean “listen/read in chat like how you would as a human reading chat”
So I “listen” for USERNOTICE messages for Subscriber events
Sounds similar to what I do elsewhere so that looks fine.
You don’t use account passwords to connect to chat. You need the broadcaster to go though your apps OAuth flow Getting OAuth Access Tokens | Twitch Developers and requesting the appropriate scopes to connect to chat and any others that your bot may need.
Thanks to your direction, I am making progress on this. I have successfully set up the Twitch API Authentication index.js using Node, Express, Passport and the requested Scopes. Based on the output from that, it seems it is correctly set up as it is returning the ACCESS and REFRESH tokens. I also have have an app.js file which is also monitoring Port 3000.
Because this is my first time doing this, I am stuck on where to go next. In particular, where should my js code go that will monitor chat and do what I need it to do. In app.js? In index.JS? neither? I don’t know how to connect all this together and start the bot so it does the appropriate interaction with chat. An pointer to an example app would be helpful if it exists.
Thank you for helping guide this “first timer” through this process