Teact
Guides

Events

useOn and useEventData for Telegram updates — messages, callbacks, payments, and wildcards.

Both hooks come from @teactjs/core. Use them to react to raw Telegram updates that don't map cleanly to a screen.

useOn

Subscribe to an update type:

import { useOn } from "@teactjs/core";

useOn("message:text", (ctx) => {
  console.log("Text:", ctx.raw);
});

useEventData

Read the latest payload for an event type:

import { useEventData } from "@teactjs/core";

const photo = useEventData("message:photo");

Common event keys

  • message, message:text, message:photo, …
  • callback_query
  • pre_checkout_query, successful_payment
  • * — all events (use sparingly)

Raw Telegram update fields are snake_case — e.g. callback_query, pre_checkout_query, successful_payment. Match those names exactly, not camelCase.

On serverless/edge, an effect scheduled by useOn that runs after the first commit won't survive the isolate freeze — fine for long-running polling. See Streaming.

Pair with Hooks for chat id, text, and command accessors.

On this page