@innerlife/channel-nestjs
v0.0.2
Published
NestJS adapter for @innerlife/channel — a DynamicModule that wires ChannelHost into the Nest lifecycle.
Readme
@innerlife/channel-nestjs
NestJS adapter for @innerlife/channel. A DynamicModule that
builds a ChannelHost from DI and ties it to the Nest lifecycle
(start on bootstrap, stop on shutdown). The host itself stays
framework-neutral — this package only assembles and supervises it.
Usage
import { Module } from "@nestjs/common";
import { ChannelModule } from "@innerlife/channel-nestjs";
import { createInnerlifeEngine } from "@innerlife/channel-engine-adapter";
import { weixin } from "@innerlife/channel-weixin";
@Module({
imports: [
ChannelModule.forRootAsync({
imports: [AgentModule],
inject: [Runner, AgentPoolService, ACCOUNT_STORAGE],
useFactory: (runner, pool, storage) => ({
channels: [weixin()],
storage,
engine: createInnerlifeEngine({
runner,
resolveAgent: async (addr) => ({ agent: await pool.get(addr.peerId), source: addr.peerId }),
}),
}),
}),
],
})
export class AppModule {}ChannelHost is exported (and the module is @Global()), so any service can
inject it — e.g. to drive QR login:
constructor(private readonly host: ChannelHost) {}
async startLogin() {
const { qr, done } = await this.host.login("weixin");
// render qr.url / qr.image; then:
const { accountId } = await done;
}- Enable shutdown hooks (
app.enableShutdownHooks()) sostop()runs on exit. - Set
autoStart: falseto start the host manually. - Logs default to a
NestLoggerAdapter; pass your ownloggerto override.
