#5996 (In Topic #1431)
2-way chat bridge between Composr and IRCGreetings! I wasn't sure if this should go in Deploying or Developing, but I made it in the process of deploying, so I'm sticking it here.
I love Composr's built-in chat system. It was one of the things that drew me toward ocPortal/Composr in the first place. It doesn't require any client-side plugins, the authentication is integrated with the rest of the website, and the default logging works perfectly for my needs.
On my website, I have a Composr chat room that I use to interact with live viewers during video streams. I don't only stream to my website, however; I multi-stream to Twitch, Mixer, and several other platforms. This gives me a wider potential audience, but it also has the effect of splitting my audience between several different chat rooms. To rectify this, I have set up an IRC server to use as a relay, and am standing up bridges between that IRC server and all of the individual chat rooms.
Hence, OcIrcBridge is a command-line Java application that will forward messages between a Composr chat room and an IRC channel! It's a little rough around the edges (I'm an operations/administration guy, not a developer), but it's working great so far. Here are some of the key points:
- The Composr-side listener continuously polls your MySQL/MariaDB database and checks for any new messages. When it sees new messages, it forwards them to IRC via the PircBotX library.
- This means you will need to set up a MySQL user for OcIrcBot, with read-only access to your Composr chat messages table.
- The IRC-side listener (PircBotX) fires events when new messages are received. Upon receipt, they are forwarded to Composr via an authenticated HTTP POST request.
- This means you will need to create an account on your Composr website for OcIrcBot; the bot also requires the use of TLS (as the HTTPS protocol is hardcoded.)
One of the biggest challenges was that the Composr web session would expire after a certain amount of inactivity, causing forwarded messages to show up as "guest posts" in the Composr chat room (which I haven't figured out how to disable entirely yet without affecting view permissions.) To get around this, the bot checks if it is still logged into Composr every time it sends a message. If it is still logged in, it will forward the message right away; if it's not logged in, it will re-login before forwarding the message. This is probably the clunkiest part of the program right now (and it does add a little more delay in forwarding), but it allows the bot to function indefinitely without having to manually restart the program, and it's still faster than re-logging every time a message is forwarded.
Composr, IRC, and chat bridges are all fairly niche, so I'm not sure if anyone else will have a use for this, but I wanted to put it out there just in case anyone was looking for something like this. The source code is on GitLab as well as GitHub, and compiled releases are hosted on GitHub for now.
FYI systems integrating with Composr should be able to log in using regular HTTP authentication to establish their session. i.e. you don't need to simulate any kind of login via a web form, just submit HTTP authentication headers.
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
1 guest and 0 members have just viewed this.