Initial commit: NestJS meshtastic bridge bot
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { BROADCAST_ADDR } from './codec.js';
|
||||
import { MeshService } from './mesh.service.js';
|
||||
|
||||
@Controller()
|
||||
export class MeshController {
|
||||
constructor(private readonly mesh: MeshService) {}
|
||||
|
||||
@Get('status')
|
||||
status() {
|
||||
return this.mesh.status();
|
||||
}
|
||||
|
||||
@Post('send')
|
||||
async send(@Body() body: { to?: string | number; text: string }) {
|
||||
if (typeof body?.text !== 'string' || body.text.length === 0) {
|
||||
throw new BadRequestException('text must be a non-empty string');
|
||||
}
|
||||
let to = BROADCAST_ADDR;
|
||||
const t = body.to;
|
||||
if (t !== undefined && t !== '!b' && t !== 'broadcast') {
|
||||
const n = typeof t === 'number' ? t : Number(String(t));
|
||||
if (!Number.isFinite(n))
|
||||
throw new BadRequestException(
|
||||
'to must be a decimal node number, "!b", or "broadcast"',
|
||||
);
|
||||
to = n;
|
||||
}
|
||||
return { id: await this.mesh.sendText(to, body.text) };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user