2.0.0 • Published 10 months ago

msgroom-bot-api v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Certainly! Here's an updated version of the README file that includes the description of the endpoints provided by the dashboard:


msgroom-bot-api Module

The msgroom-bot-api module provides a class for interacting with a bot through a client. It allows you to connect to a server, send messages, change the bot's name, and manage the bot's dashboard.

Installation

To use the msgroom-bot-api module, you need to have Node.js installed. You can then install the module using npm or yarn:

npm install msgroom-bot-api

or

yarn add msgroom-bot-api

Usage

import Bot from 'msgroom-bot-api';

// Create a new instance of the Bot
const bot = new Bot();

// Connect to the bot server
bot.connect('BotUser', 'APIKey').then(() => {
  // Connected successfully, perform actions
  bot.send('Hello, bot!');
  bot.setName('NewBotName');
}).catch((error) => {
  // Error occurred during connection
  console.error('Error connecting to the bot:', error);
});

API

command(cmd,func)

Creates a command in the bot.

  • cmd (string) : The command name including the prefix
  • func (function) : The function for the command The arguments passed to func:
  • first argument - args of the command
  • second argument - the message event

connect(nick, apikey, url)

Connects the bot client to the server.

  • nick (string): The username or nickname of the bot.
  • apikey (string): The API key for authentication.
  • url (string | URL): (Optional) The URL of the server to connect to. Defaults to wss://windows96.net:4096.

Returns a promise that resolves when the connection is successful or rejects with an error if there is an issue.

send(msg)

Sends a message from the bot client to the server.

  • msg (string): The message content to send.

setName(nick)

Changes the bot's name to the specified value.

  • nick (string): The new name for the bot.

disconnect()

Disconnects the bot client from the server.

dashboard(rootresponse, authkey)

Starts the bot's admin dashboard on an Express server.

  • rootresponse (string): The response for the root endpoint ("/").
  • authkey (string): (Optional) The authentication key for accessing the dashboard. Defaults to a random value.

The dashboard provides the following endpoints:

  • / (GET): Renders the root response provided in the rootresponse parameter.

  • /chat/sendmessage (GET): Accepts a query parameter message to send a message from the bot. Requires authentication using the authkey parameter.

  • /chat/name (GET): Accepts a query parameter name to change the bot's name. Requires authentication using the authkey parameter.

  • /bot/disconnect (GET): Disconnects the bot from the server. Requires authentication using the authkey parameter.

  • /bot/connect (GET): Reconnects the bot to the server with the previous connection status. Requires authentication using the authkey parameter.

  • /bot/eval (GET): Accepts a query parameter code to evaluate and execute JavaScript code on the bot. Requires authentication using the authkey parameter.

  • /bot/constatus (GET): Retrieves the connection preferences of the bot. Requires authentication using the authkey parameter.

username

The bot's user name

SOCKET

The Websocket connection to the msgroom server

userId

The bot's userID

constatus

The bot's connection preferences

app

The Express app for dashboards

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.

License

This module is released under the MIT License.

2.0.0

10 months ago

1.1.8

10 months ago

1.1.7

10 months ago

1.1.6

10 months ago

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago