Documentation of WebSocket API

Connection URL

  • Endpoint: ws://localhost:3000/ws


Introduction

This WebSocket API allows for interaction between a client and a server through JSON messages. Communication begins with a connection to the WebSocket, followed by sending JSON-formatted messages. Each message must include a mandatory "action" field that specifies the operation to execute. The other fields in the message depend on the requested action.


How It Works

  1. Connect to the WebSocket using the connection URL: ws://localhost:3000/ws.

  2. Send JSON messages to call API routes. Each message must contain an "action" field.

    • Example:

      {
        "action": "Register"
      }
  3. Server responses are received as JSON messages. These messages may include information such as tokens or execution statuses.


Available Actions

1. Register

  • Description: Registers a user on the server.

  • JSON Message:

    {
      "action": "Register",
      "API_KEY": "API_KEY1234"
      "checksum": "azerty",
      "name": "tom",
      "prompt": "juste le boss"
    }
  • Expected Response:

    {
      "token": "TOKEN1234"
    }
    • data: The unique token assigned to the registered user.


2. Connection

  • Description: Connects an already registered user.

  • JSON Message:

    {
      "action": "Connection",
      "checksum": "azerty"
    }
  • Expected Response:

    {
      "token": "TOKEN5678"
    }
    • data: The connection token.


3. TakeDecision

  • Description: Sends a decision or message to the server. Requires a valid token.

  • JSON Message:

    {
      "action": "TakeDecision",
      "token": "<TOKEN>",
      "message": "Hello World"
    }
  • Conditions:

    • The token field must contain a valid value obtained during registration or connection.

  • Possible Error:

    • If no token is available, the client must register or connect before using this action.


4. Disconnect

  • Description: Disconnects a user using their token.

  • JSON Message:

    {
      "action": "Disconnect",
      "token": "<TOKEN>"
    }
  • Conditions:

    • The token field is mandatory and must contain a valid value.

  • Expected Response: Confirmation of disconnection.


Server Message Handling

Message Reception

  • Server messages are received in JSON format.

  • Example of a received message:

    {
      "data": "TOKEN1234"
    }
  • Messages may include information such as tokens or statuses related to an action.

Error Handling

  • If the server sends a message that is not JSON-compliant, an error will be raised.

    • Example:

      JSON decoding error in the received message.
  • Actions requiring a token will display an error if no valid token is available.

Additional Notes

  1. Token:

    • The token is a key element for actions requiring authentication.

    • The token is obtained either through the Register or Connection actions.

  2. Unrecognized Actions:

    • If an invalid command is sent, the server will not process it.

    • The client will display an error message.

Last updated