Skip to content

Repository files navigation

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:

importDevzatfrom"devzat";constplugin=newDevzat({address: "localhost:5556",// The address to the Devzat server's plugin API (different than the SSH port)token: "my-token",// The token to authenticate with the servername: "Demo bot"// Name of your bot (can be overridden later)});

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.

typeMessage={room: string,// The room name (including the `#`) to send tofrom?: string|null,// The name of the user sending the message (defaults to the bot's name),// can be set to null to not have any name attached to the messagemsg: string,// Message text (in Markdown)ephemeralTo?: string// Username of user to send the message to (if not set, the message will be visible by all users in the room)}

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.

typeListener={middleware?: boolean,// If true, the listener can edit the user's message before it is sentonce?: boolean,// Remove the listener after the first eventregex?: RegExp|string// If set, the listener will only fire if the message matches the regex (doesn't include slashes or flags}typeEvent={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.

typeCmdDef={name: string,// Name of the command (triggers when a message starts with it)argsInfo: string,// Summary of arguments (like <name>)info: string// Description of the command}typeCmdInvocation={room: string,// Room the command was issued infrom: string,// User who issued the commandargs: string// Everything after the command name}

About

Official Node.js client library for Devzat plugin API

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Contributors

Languages