@yoctotta/base-channel
v1.0.1
Published
Base library for creating Kaman Agent communication channels
Readme
Base Channel Library
A library for creating communication channels that connect to the Kaman Agent via Socket.IO.
Installation
yarn add @yoctotta/base-channelUsage
To create a new channel implementation:
npx @yoctotta/base-channel create my-channelThis will create a stub structure with all the necessary files to implement your own channel.
Creating a Custom Channel
- Extend the
BaseChannelclass - Implement the required abstract methods:
receiveMessage(callback: string, msg: any): Promise<any>startCron(): Promise<void>messageBack(msg: string): void
- Define your channel's configuration using the
configDefinitionstatic property - Implement the
initialize()static method
Example
import { BaseChannel, Field } from '@yoctotta/base-channel';
class MyChannel extends BaseChannel {
static configDefinition: Field[] = [
{
name: "apiKey",
type: "string",
description: "API key for the service",
required: true,
}
];
async receiveMessage(callback: string, msg: any): Promise<any> {
// Handle incoming messages
const response = await this.callDownStream(msg);
this.messageBack(response);
return { status: "success" };
}
async startCron(): Promise<void> {
// Initialize any periodic tasks
}
messageBack(msg: string): void {
// Send message back through your channel
}
static initialize() {
return {
id: "my-channel",
name: "My Channel",
description: "Description of my channel",
configDefinition: MyChannel.configDefinition,
type: "my-channel",
};
}
}
export default MyChannel;