peertube-plugin-livechat icon indicating copy to clipboard operation
peertube-plugin-livechat copied to clipboard

Support customization and addition of features by other plugins

Open Poslovitch opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. I am currently working on Videogame Data Hub, a PeerTube plugin mainly aiming at experimenting the integration of Wikidata into PeerTube, and focusing on providing video game-related content.

I figured that the live-chat could be used in various ways (not all of them are related to my plugin in particular):

  • Livechat Integration in video games (similar to the Twitch Chat integration notably used in Clustertruck).
  • Viewers could submit video game suggestions
  • Near-real-time updates about speedruns
  • Game-related skinning/customization of the chat

Describe the solution you'd like I am new to the world of PeerTube plugin, so I don't know yet how things would need to be done in order to allow plugins to interact with the livechat.

However, I think I would need:

  • Provide an API/Wrapper to get messages from the chat before they are sent, with the ability to prevent them from being sent (this would allow me to hide messages that are "commands" and may spam the chat, such as !vote 1)
  • Use defined class names (or ids) to allow easy CSS theming of the live-chat.
  • An API to allow the PeerTube server (or a plugin) to interact with the chat backend as a "user", so that it can send messages too.
  • Hooks, maybe?

Describe alternatives you've considered None.

Additional context At the time of writing, I am unaware if PeerTube provides an API for plugins to interact with each other.

Poslovitch avatar Nov 07 '21 09:11 Poslovitch

Hello. Thanks for your submit.

The API/Wrapper to remove messages, and respond to commands, can be done at the XMPP level. This could be a simple Prosody module, that the plugin would add.

For CSS theming, see my response here: https://github.com/JohnXLivingston/peertube-plugin-livechat/issues/72#issuecomment-962436383

For the Peertube server to interact, the better way is to connect a bot to the XMPP room. For now, the Prosody server is «closed» to the outer world, but it is on my roadmap to try to open it. A first step was made here: https://github.com/JohnXLivingston/peertube-plugin-livechat/pull/57 . It can possibly help you to connect a bot.

For hooks, same response as above: Prosody modules.

Peertube does not provide API to communicate between plugins. But we are free to create our own mechanism. The livechat plugin could for example have a settings where you can add a path with Prosody modules to include. This would be pretty simple to implement. But it would be difficult to maintain. External plugins could break things, could add some extra work to me (test for backward compatibility), ... I'll have to take a step back before I decide anything.

JohnXLivingston avatar Nov 07 '21 11:11 JohnXLivingston

Is it already be possible for this plugin to add the Prosody module so we can use an API to respond to commands from localhost? Could you add it already so that it's automatically there when you install the plugin? I would really like to use commands from livestream chat.


I also have 2 feature ideas:

  1. It would also be nice to recognize events like subscribing to the channel and receiving raids. (raids aren't implemented yet: https://github.com/Chocobozzz/PeerTube/issues/4146)

  2. Add some kind of channelpoints system from Twitch so you can get points and use them to activate stream events or mark your comment in chat, etc. Setup idea:

  • The streamer creates a button panel
  • When a button is pressed on this panel, the API sends a value
  • The bot checks the user's point values and allows and activates the event or denies it
  • The bot removes a certain number of points (and maybe sets a timeout)

In this example, the bot would store all user points to allow custom calculation and programming in the streamer's preferred language. The plugin would have to tell the bot if a user joins or leaves the stream and if it is a known user (logged in) or an anonymous user ( self chosen username). (To enable and disable point counting for this user)

Please tell me what you think of these ideas.

Gamemap avatar Apr 23 '22 16:04 Gamemap

Thanks for your ideas @Gamemap . Actually, since the @Poslovitch issue, I made some progress. There is a setting called Enable custom Prosody external components. By enabling it, you can then connect «external components». See here: https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/prosody.md#enable-external-xmpp-components And here: https://prosody.im/doc/components

I also begin to work on a XMPP bot written in NodeJS, so it can be included in a peertube plugin! For now:

  • the bot is only a proof of concept, it has some bugs (sometimes crashes)
  • the bot must be manually installed, configured and launched on the server
  • the bot can randomly pick a quote in a list every X seconds
  • the bot can respond «hello» when someone mention him

This bot was a quickly-written Proof Of Concept. I have in mind to add these features:

  • moderation (list of forbidden words => warn, kick, ban actions)
  • keyword actions (for example «!help» would list commands, «!support» would print information to support the streamer, ...)
  • an API for the streamer and for Peertube to provoque some messages in the chat.

Here is the code for the bot: https://github.com/JohnXLivingston/xmppjs-chat-bot

Here is an example configuration file for the bot:

{
        "type": "component",
        "name": "DemoBot",
        "logger": "ConsoleLogger",
        "connection": {
                "service": "xmpp://127.0.0.1:53470",
                "domain": "bots.videos.john-livingston.fr",
                "password": "xxxxxxxxxxx"
        },
        "rooms": [
                {
                        "local": "c5d20adf-1088-4d40-bbfc-1abb42d20b05",
                        "domain": "room.videos.john-livingston.fr"
                }
        ],
        "handlers": [
                {
                        "type": "hello"
                },
                {
                        "type": "respond"
                },
                {
                        "type": "quotes_random",
                        "delay": 30000,
                        "quotes": [
                          "Hi, I'm the bot",
                          "Yeay"
                       ]
                }
        ]
}

Then you can run the bot in background with: npx xmppjs-chat-bot run -f bot.json &.

Unfortunately I don't have time to work on that right now. If people want to contribute, they are welcome (contact me first, so we can organize the code). Otherwise, if you have any ideas about how to finance this project, don't hesitate to tell me.

JohnXLivingston avatar Apr 25 '22 08:04 JohnXLivingston

@JohnXLivingston I'm trying to create an own implementation of an chatbot for your livechat system but I need help with the authentication process for the prosody server. (I searched in the Internet, but didn't find anything answering my questions, so I hope you can help me)

  1. Does the prosody server disconnect the client after answering the request? (And I get an ID which I have to sent in every request, so the server know the client?)
  2. Could you create (or link) a list what I have to send the server and what the server sends to the client? (How does for example the <handshake> function work? Do I need it only with a ssl encryption ?)

Gamemap avatar Jul 30 '22 22:07 Gamemap

  • Does the prosody server disconnect the client after answering the request? (And I get an ID which I have to sent in every request, so the server know the client?)

How do you connect to the server? Are you using an External Component, as for my bot? If so, the connection is not closed.

  • Could you create (or link) a list what I have to send the server and what the server sends to the client? (How does for example the <handshake> function work? Do I need it only with a ssl encryption ?)

The XMPP protocol is very very well documented, you can easily find documentation on the web. But it can be difficult to use if you are not familiar with it (there are a lot of concept behind XMPP). You should use an existing library. What language are you using? If you are using Javascript (or Typescript), you can check xmpp.js. And also check the code of my proof of concept xmpp-chat-bot. If you are using another language, you should search for XMPP libraries. There are plenty of them (this is a very used standard, for more than 20 years).

Please note that there are different ways to connect to a XMPP chat room (XMPP client, Prosody external component, BOSH protocol, Websocket, ... ; with a local authenticated account, a local anonymous account, a remote account, ...). For now, the plugin does not allow all of them. There are plans to open the server a little bit much, but I have to find time and funding for that. How are you trying to connect with your bot?

What are the features you are trying to achieve? I made my proof of concept bot having in mind to include it in a peertube plugin, so you can make interactions between Peertube and the chat. The only reason why I haven't finished it, is the lack of time. Maybe we can discuss how you could use it to implement your needs?

JohnXLivingston avatar Aug 01 '22 10:08 JohnXLivingston

Thank you for your answer. Yes, I'm also connecting with an external component. I'm using a python like scripting language (GDScript from the Godot engine). I want to create a chatbot with an easy configurable scripting language and editable configurations through a GUI.

I tried connecting to the openfire xmpp server to test my program and I connected successfully, so I think I configured prosody wrong. (I wanted to program on windows and used therefore an old unsupported version of prosody. That is probably the problem. ) I will try to set up a virtual machine with Linux and test it with the newest version of prosody. (But I have a problem with virtualbox not booting any os, so I need some time to fix it)

Gamemap avatar Aug 04 '22 09:08 Gamemap