Not sure if this will be of any use to you MountainRiderAK, it seems you have some issue with the Oauth logic and implementation with Python.
I got an open PR with a WIP Twitch connector for opsdroid, perhaps you could have a look at the code and see what I am doing, bear in mind that this is a WIP PR so I am probably going to change things around still.
opsdroid:master ← FabioRosado:twitch
opened 01:05PM - 25 May 20 UTC
# Description
This is the initial commit for the Twitch connector, there … is still a lot to be done like writing the tests and create the documentation for it. I'm raising this draft PR to get some feedback on the word done and if I can improve things a bit more.
This connector is pretty big because I'm using a lot of things. Twitch has different ways to do stuff so we are using webhooks to get 3 events, then calling the API to update channel titles and websockets to listen to the chat.
I thought about what other bots do and what could be cool to include and that's the reason this connector grew so much haha
## Things still to be done
- [x] Update documentation
- [x] Write tests for the whole connector
- [x] Test most of the features on Twitch (did some but still need further testing)
- [x] Write the `skill-twitch` to handle different events and actions
- [x] Figure out why websockets throw exception when exiting opsdroid
- [ ] Add ssl support to connect to websockets - still need to figure out how to do that.
- [x] Check if every logger contains `_()`
- [x] Figure out and implement `hub.secret` check when handling webhook response - prevent folks from sending data that wasn't sent by Twitch.
- [x] Connect to the chat service only when streamer went online.
- [x] Handle aiohttp status code != 200. Currently I'm assuming everything works fine - that is BAAAAAD
## Notes
- `config['forward-url'] - Added this so we can still run opsdroid on localhost and use ngrok or serveo forwarding urls as a callback when subscribing to webhooks.
- `token` expires after 24 hours so we will refresh token when it expires and will re-subscribe to webhooks
- `twitch.json` - saved data on appdir `data` to keep the oauth token and refresh token saved so we can get/set
- We should really only connect to the twitch irc whenever a streamer goes live, it's unlikely that we will do anything with the chat until we are online. I need to check if the webhook will still receive data from Twitch after the oauth token expired (but the webhook lease is still going), that way we can keep the 'refresh' token code on the websockets connect method
Every time we send something through websocket the command is very similar, should we just create a helper method to send messages to the websocket? Will this improve readability?
## Status
~~**READY**~~ | **UNDER DEVELOPMENT** | ~~**ON HOLD**~~
## Type of change
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
- This change requires a documentation update
- Documentation (fix or adds documentation)
# How Has This Been Tested?
- Test A
- Test B
# Checklist:
- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation (if applicable)
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
Let me also mention that in the PR we are using async code and I am using aiohttp.websockets support - if everything that you need is to listen to the chat server then the code that you want is the connect_websocket.
Also I am currently using user oauth tokens instead of app one and will change things around in the very near future. In regards to getting the access_token and how I am getting my access token locally you can have a quick look at the documentation on that PR it should explain things a bit - this will be removed in the future.
Hope this helps