Team-TAU / tau

TAU- Twitch API Unifier, a containerized relay/proxy to unify the WebHook- and WebSocket-based real-time Twitch APIs under a single (local) WebSocket connection.
MIT License
153 stars 39 forks source link

[FEAT] Ability to send chat messages on behalf of a dedicated chat bot user that is a different account than the main account #103

Closed techygrrrl closed 1 year ago

techygrrrl commented 2 years ago

It would be great to be able to authorize a dedicated bot account for chat purposes so that it can be clear to my viewers when I am speaking and when my bot is speaking.

Instead of using the StreamElements bot, for example, I'd like to implement my own bot with chat commands but have my bot's code focus specifically on the business logic of the bot, and leave the heavy lifting around authenticating and Twitch API complexity to TAU.

Here are some examples how this could be applied:

Implementation ideas

I'm not sure exactly what the API for this could look like, perhaps leverage either the websockets functionality, or a new endpoint for the TAU REST API, e.g. POST /api/v1/twitch-chat with data { "message": "techygrrrl has been live for 1 hour, 30 minutes", "from_login": "techydrrroid" } or send a different auth token for the bot. I believe you also mentioned on Discord something about passing an IRC token. Not picky about the API.

Describe alternatives you've considered

Currently, I have a bot I built myself. I need to authorize it before every stream and it doesn't implement auto-refreshing of auth tokens. I'd like to take advantage of the auto-refreshing of auth tokens from TAU to simplify my bot implementation to have it be just the business logic and leverage TAU for the authentication and helix passthrough.

I also have some bot commands that use StreamElements and some serverless functions but these have limited functionality.

The ability to be able to send commands via my own branded bot and leverage TAU's functionality for authentication and Twitch API unifying would be great.

Additional context

Here is an example use case of my bot doing countdown functionality.

image

I could, for example, run my own bot server before every stream that connects via tmi.js, but when it needs to do something more than just read, I'd like to send it via TAU so that I don't have to deploy and implement refreshing tokens.

techygrrrl commented 2 years ago

Notes from the Discord conversation, for reference:

techygrrrl — 05/08/2022 I haven't tried yet but does TAU have a way to authenticate as one user and send messages and perform actions as that user on my channel? I have a separate bot user I use for bot-related things on my channel and it has mod abilities, wondering if I can use that user to post things and automate moderation with the help of TAU. FiniteSingularity [He/Him] — 05/09/2022 I assume you mean in terms of the Chatbot/IRC stuff? Currently, no, you can only send messages/perform actions as the user that is linked to the token you provided during setup. That said, I really need this functionality myself (so that I can move ChalkBoom bot from Comfy.js to using TAU), so it is on my priority "todos." FiniteSingularity [He/Him] — 05/09/2022 I think the way to do it, would be to provide an IRC token when the connection to the TAU IRC websocket is opened, if you want to use a different account. (so if you dont provide one, it will be your default user, but if you provide the login details, it will open a new IRC connection under that user account)

techygrrrl commented 2 years ago

Quick summary of our chats on Discord in a quick tech spec document that outlines how we can authenticate bot users with separate callback URLs, store the tokens, and authorize acting on behalf of bot users for helix passthrough endpoints.

Deliberately left out IRC stuff as I'm not too familiar with that protocol.

Feat_103_Acting_bot_users.pdf

FiniteSingularity commented 2 years ago

I've been working on a PR for this, and thought I'd put some notes here. In order for this to happen, a few tasks must be accomplished:

A couple things I am thinking about:

  1. Do we want the IRC chatbots to fire up when TAU launches? Or only when a client connects to its associated websocket? As I'm currently not planning on storing chat messages in the database, I was thinking we might check whenever someone subscribes to a bot's websocket, if that bot is connected already.. if not connect it. And when people unsub from the websocket, check if there are any more subs, and if not, disconnect.
  2. I'm thinking we should also add a ChatBotChannel model that defines what channels a given chatbot should connect to when it runs. That way, you could have your bot connect to multiple channels, and remember what it needs to reconnect to the next time it connects to IRC.
FiniteSingularity commented 2 years ago

Made some great progress today. All of the above tasks are now complete. A few more things need to be done before we're ready for a PR:

These tasks should be a bit more straightforward than the first set. We're getting there!

techygrrrl commented 2 years ago

This is so awesome! 🚀 I'm getting very excited for this feature!

💯 agree connecting to IRC only when the web socket is being listened to (rather than an always-on approach). This would also give devs more control to restart their local bots to re-connect if for whatever reason there was a connection error).

Looking forward to those features to add/remove bots and watched channels!

I'm also more than happy to pull down the PR and test it out and see if I can break anything.

FiniteSingularity commented 1 year ago

Closing this, as it was merged in with #120