neko icon indicating copy to clipboard operation
neko copied to clipboard

Send message in chat or clipboard progrmmaticaly

Open ricou84 opened this issue 2 years ago • 12 comments

Hello.

Thanks you for this great tools. It would make m'y lifetime as a trainer easier.

Context: i would pop UP a bunch of neko/xfce on each traînee lab. I have some command to share with my traînee that they would have to exécute on the neko dektop.

I would like to broadcast this command on the chat or on thé clipboard of each traînee if possible programmaticaly.

Can neko-rooms be used for that ?

Thanks

ricou84 avatar Oct 07 '23 06:10 ricou84

Yeah you could technically use neko rooms for that

yesBad avatar Oct 07 '23 06:10 yesBad

Thanks you i would test it.

ricou84 avatar Oct 07 '23 06:10 ricou84

I was not aware that neko-rooms launch rooms localy.

For network reason , I need that neko:xfce desktop have to been executed somewhere , one for each trainee.

The need to share command . each trainee will have to execute this command in the contect of their VDI.

thanks for your advice

Scality-EmerikNicole avatar Oct 07 '23 09:10 Scality-EmerikNicole

I was not aware that neko-rooms launch rooms localy.

Neko-rooms is only orchestrator and can launch/manage rooms on the docker socket that you assign to them. It does not matter if that docker daemon is running locally or not.

For network reason , I need that neko:xfce desktop have to been executed somewhere , one for each trainee.

So you have dedicated server that hosts all neko rooms? And you want to only start it from remote computer?

m1k1o avatar Oct 07 '23 09:10 m1k1o

hello thanks for your answer and the interest for my use case.

I will explain a little bit the context and what i would like.

Each trainee have a lab with a bunch of ec2 instances in the same private network per lab. One of this ec2 instance have a Public ip and it been used to jump on other machines of the lab.

today i execute neko:xfce on it and i'm happy with that. i can connect through neko with ssh and http on all machine of my lab.

The trainer have also a lab on which i would execute neko-rooms to be able to manage each neko:xfce and send some command that each trainee will have to execute on their xfce.

Thanks for your comment and help

Scality-EmerikNicole avatar Oct 07 '23 10:10 Scality-EmerikNicole

That is really interesting use-case. Neko rooms is currently meant to manage multiple rooms on a single sever, not on multiple servers. But there is plan to add support for that.

But if you want to send any command to existing neko instances, you can just connect to the websocket and send any message to the chat or fill clipboard.

m1k1o avatar Oct 07 '23 11:10 m1k1o

Hello thanks for this answer.

I 'm a complete newbie in websocket. If you Can point me to thé right direction and some technical Reading i will bé very happy.

Thanks

ricou84 avatar Oct 08 '23 17:10 ricou84

What language would you like to use to send to the websocket?

yesBad avatar Oct 08 '23 17:10 yesBad

Python is the one i know thé best

ricou84 avatar Oct 08 '23 17:10 ricou84

Python is the one i know thé best

then I suggest checking out the https://pypi.org/project/websockets/

yesBad avatar Oct 08 '23 18:10 yesBad

Hello. I tried with this code.

import asyncio
from websockets.sync.client import connect
import json

endpoint='127.0.0.1:30000'
username='user'
password='neko'

def hello():
    with connect(f"ws://{endpoint}/neko/ws?password={password}") as websocket:
        
        message = "Hello world!"
        events = {"event":"chat/message","content": message }
        websocket.send(json.dumps(events))
        message = websocket.recv()
        print(f"Received: {message}")
try:
    hello()
except Exception as e:
    print(e)

but it seems that something is missing. May be an offer. can you point me in the right direction?

Scality-EmerikNicole avatar Oct 10 '23 07:10 Scality-EmerikNicole

I can see the WebSocket event "chat/message" received on the neko session, but the message content is not posted on the Chat. any Idea?

Here is a simple Python script for sending a WebSocket chat event :

## pip install websockets

import asyncio
import websockets
import json


async def send_message():
    nekoURL = ""
    nekoRoomID = ""
    nekoRoomPassword = ""
    url = f"{nekoURL}/{nekoRoomID}/ws?password={nekoRoomPassword}"
    event = "chat/message"
    message = "Hi there ¯\_(ツ)_/¯"

    payload = {
        "event": event,
        "content": message,
    }

    try:
        async with websockets.connect(url) as websocket:

            await websocket.send(json.dumps(payload))

    except websockets.exceptions.InvalidStatusCode as e:
        print(f"Failed to connect: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    asyncio.run(send_message())


image

mtami-zoor avatar May 23 '24 13:05 mtami-zoor