xTaskjs 1.0 is live: role-based accounts, documentation, and a customizable interface.

Packages

@xtaskjs/bots

Unified bots runtime for Telegram, Slack, and WhatsApp adapters with gateway decorators.

npm install @xtaskjs/bots reflect-metadata Package path: packages/bots

Overview

What this package owns in the runtime

Bots adds a multi-platform messaging runtime to xtaskjs. It uses decorated gateway classes, adapter registration, and lifecycle-managed dispatch so bot workflows stay DI-friendly and consistent with the rest of the framework.

What it provides

  • BotGateway(), OnCommand(), OnMessage(), and OnCallbackQuery() declare bot handlers on DI-managed classes.
  • BotsModule registers platform adapters such as Telegram, Slack, and WhatsApp in a single runtime.
  • Injectable services can publish messages and inspect runtime adapter state through bot service tokens.
  • Lifecycle integration starts and stops bot adapters together with application bootstrap and shutdown.

How it fits

  • Pairs with @xtaskjs/security in webhook scenarios where signed payloads and protected audit routes are required.
  • Uses @xtaskjs/config in upstream samples for adapter credentials and runtime tuning.
  • Demonstrated by samples 26-bots_app and 27-bots_webhook_security_app.

Usage Chart

How strongly this package shapes the runtime

Bootstrap

4/5

Dependency Injection

5/5

Messaging

5/5

Security

4/5

Integrations

5/5

Package Flow

How this package moves through xtaskjs runtime phases

Before startup

Register bot adapters and decorate gateway handlers so dispatch metadata is available when the container initializes.

During CreateApplication()

Bots integration resolves handlers from DI-managed services, wires adapters, and starts runtime dispatch according to configuration.

During app.close()

Adapters and subscriptions are stopped with the rest of the lifecycle so webhook and polling resources shut down cleanly.

API Surface

Representative exports from the upstream package

Usage

Typical adoption flow

1. Register adapters

Use BotsModule and adapter registration helpers to connect Telegram, Slack, WhatsApp, or custom transports.

2. Decorate gateway handlers

Apply BotGateway and event decorators for commands, messages, and callback payloads in DI-managed classes.

3. Secure webhook edges

Combine bots with @xtaskjs/security and @xtaskjs/config when signed webhooks and protected audit endpoints are required.

Example

Reference snippet

Gateway-based bot handlers
import { Service } from "@xtaskjs/core";
import { BotGateway, OnCommand, OnMessage } from "@xtaskjs/bots";

@Service()
@BotGateway("telegram")
export class WelcomeGateway {
  @OnCommand("/start")
  async onStart(ctx: any) {
    await ctx.reply("Welcome to xtaskjs bots");
  }

  @OnMessage(/hello/i)
  async onHello(ctx: any) {
    await ctx.reply("Hello from xtaskjs");
  }
}

Samples

Official samples to inspect next

Reference samples: 26-bots_app and 27-bots_webhook_security_app