Devzat plugin API client for Node.js
This NPM package allows you to build Devzat plugins/bots with JavaScript/TypeScript. See example/index.ts for a full example of a bot made with this package.
Getting started
Install the package:
yarn add devzat
Create an instance of the client:
import Devzat from "devzat";
const plugin = new Devzat({
address: "localhost:5556",
token: "my-token",
name: "Demo bot"
});
From there you can use various methods to send, receive, and intercept messages.
Devzat.sendMessage(message: Message): Promise<{}>
Send a message in a given room.
type Message = {
room: string,
from?: string | null,
msg: string,
ephemeralTo?: string
}
Devzat.onMessageSend(listener: Listener, callback: (e: Event) => string | void | Promise<string> | Promise<void>): () => void
Register an event listener to fire on every message send. Returns a function to remove the listener.
type Listener = {
middleware?: boolean,
once?: boolean,
regex?: RegExp | string
}
type Event = {
room: string,
from: string,
msg: string
}
Devzat.command(command: CmdDef, callback: (e: CmdInvocation) => string | void | Promise<string> | Promise<void>): () => void
Register a command to be handled by your bot. Returning a value from the callback will reply to the message.
type CmdDef = {
name: string,
argsInfo: string,
info: string
}
type CmdInvocation = {
room: string,
from: string,
args: string
}