meshcore.js

Getting started

Install @meshcorejs/client and run a first bot over USB, WiFi or Bluetooth.

Install

The packages depend on how the radio is connected.

npm install @meshcorejs/client serialport

A first bot

Two files. main.ts connects to the radio, logs in and loads every brick found in the folders next to it. commands/hello.ts is the first command.

main.ts
const serial = new Client({
  transport: new SerialTransport({ path: '/dev/ttyACM0' }), // COM3 on Windows
  load: import.meta.dirname,
});
commands/hello.ts
import { CommandBuilder } from '@meshcorejs/client';

export default new CommandBuilder()
  .setName('hello')
  .setDescription('Say hello')
  .setHandler((ctx) => ctx.reply(`Hello ${ctx.author.name}, I am ${ctx.client.self.name}`));

Send /hello to the bot in a DM. On a channel, send @ClubBot hello, with the name the radio advertises.

Every brick is one file with a default export, in a folder named after its kind. commands/, events/, jobs/, permissions/, roles/ and plugins/ are scanned at login.

A radio message carries 160 UTF-8 bytes. The library refuses a message that does not fit with MessageTooLongError instead of truncating it. See Sending messages.

Next

Reference

On this page