chloejsnpm i chloejs

Docs

Channels

Putting an agent on Telegram, and writing a way in that chloe does not ship.


A channel is how an agent is reached, and how a job's question gets to a person. An agent is on one because its own agent.ts says so.

Telegram

  1. In Telegram, message @BotFather, send /newbot, and pick a name and a username. It replies with a token. One bot per agent.
  2. Put it in .env beside the repo as TELEGRAM_BOT_TOKEN=..., or pass credentials: { botToken } in the file below.
  3. Write the agent's own channels/telegram.ts and name it in agent.ts as channels: { telegram }:
// This agent on Telegram. Its token is TELEGRAM_BOT_TOKEN in .env beside the
// repo, from @BotFather, and without one the reader says so and does not start.
//
// allowFrom is Telegram user ids, and an empty list answers nobody, which is
// the safe way for this to arrive. Put your own id in it: message the bot, read
// the id out of the log line, and restart.
import { telegramChannel } from "chloejs/channels/telegram";

export default telegramChannel({ allowFrom: [] });
  1. Restart, and send the bot a private message. With nobody allowed yet it answers with your Telegram user id. Put that in allowFrom. An allowed person is answered in any chat, groups included, and nobody else is.
Option What it does
allowFrom Telegram user ids that may reach the agent. The first is who its jobs ask when they name nobody.
mode "polling", the default: chloe fetches messages and nothing of yours is exposed. "webhook": Telegram posts them to publicUrl + /chloe/v1/<agent>/telegram, which then has to be exempt from whatever login is in front of the port, and checks its secret on every call.
credentials The bot token, instead of the environment variable.

Do not add another path past a login without a secret and an allowlist of its own.

Writing one

A channel is a file in the agent's own channels/ folder, exporting a Channel as its default. One chloe ships is bound there, and one it does not is written right there, without editing anything in the runtime.

A channel may say its own name, and nothing else may say it for it. A job's question goes out to an address, channel:who, and the runtime looks the channel half up in a registry that each running channel fills for its own agent. So an agent's question goes out through its own bot, and the runtime reaches somebody without knowing how.