Telegrams your agent answers in seconds

Text your agent on Telegram. Your agent is a bot you make with BotFather, and it answers you and the groups you share it with.

lnk agent start               # your agent, unless it runs already
lnk agent connect telegram    # paste the bot token, then send it the code

Connect it

Make a bot with BotFather and paste its token when lnk asks, then send the bot the one-time code lnk prints, within 10 minutes.

lnk agent connect telegram

Without prompts

From a script, give the token in its variable. It keeps the token off the command line, which other users of this machine can see while lnk runs, and no flag takes it.

LNK_TELEGRAM_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u lnk agent connect telegram   # the token from the variable

Photos and documents

For a harness that takes images and documents (Link Harness), the photos, documents and voice notes a message holds go to the agent with its text: PNG, JPEG, GIF or WebP images, PDF or text documents and Ogg voice notes, up to 10 MiB each and 8 a message, downloaded through the Bot API (a photo at its largest).

What it leaves out

Anything else, a video, is named to the agent as left out; sent alone, it's answered with what the agent reads. For another harness, a message holding only them is answered "I can read text only, for now."

In a group

Mention the bot in a group, or reply to it, and it answers there, as a reply. Each group is a conversation of its own, apart from your direct chat. In a group with topics (a forum), each topic is a conversation of its own too, answered in its topic: the agent keeps what was said in one topic out of the others.

Share a group

Mention the bot with the one-time code share prints, in the group, within ten minutes. Members can then mention it or reply to it, and the agent knows their names and who sent each message.

lnk agent share add telegram
lnk agent share list
lnk agent share remove research --connection telegram

Who stays out

Their direct messages stay private to you. Only a paired user's code shares a group, and bots and anonymous senders stay out.

What it gives them

Everyone in a shared group can use everything the agent reaches, including its files and memory, on your bill: make a separate agent for separate files. Sharing needs a harness that reads who is speaking, and group answers on.

Pushed to a webhook

On this computer, your agent's bot is polled: lnk asks Telegram for its messages. A machine that packs agents, which runs one only while it answers, has the messages pushed to it instead, with four commands of lnk-telegram.

Set the webhook

lnk-telegram hook sets the bot's webhook, outside every sandbox, where the token is: Telegram pushes the bot's messages to an https:// address, each carrying a secret (secret_token). Messages waiting are kept. A harness in a sandbox can't set the webhook itself: its proxy refuses setWebhook, logOut and close.

Sift each push

lnk-telegram sift reads each push without the token. One without the secret is refused (Security has how, and how the secret rolls), one from anyone you didn't allow is dropped, and yours or a shared group's member's is kept, as the bridge keeps it (in a group, only a mention of the bot or a reply to it).

Answer it

lnk-telegram take answers your message as the bridge does: the agent shown typing, its answer written in as it comes.

When Telegram refuses

When Telegram refuses the bot's token (revoked with BotFather, say), take and lnk-telegram send each say so as a failure of its own, apart from any other. So does an answer Telegram refuses, the chat gone or the bot blocked in it.

Poll it again

lnk-telegram unhook deletes the webhook, so the bot is polled again. While the webhook is set, Telegram won't let anything poll the bot, and lnk says so:

this bot's messages are pushed to a webhook (the agent moved to a machine that packs agents?): lnk agent move brings it back

Disconnect

disconnect forgets Telegram's tokens and restarts your agent if it runs. The bot stays yours, so delete it with BotFather (/deletebot) if you no longer want it.

lnk agent disconnect telegram

Docs

  • Security: How a push from Telegram is checked on a machine that packs agents (Pushed to a webhook), beyond what every webhook's secret gets (Link's Credentials page)
  • Decisions: Why the Telegram plugin gives each agent a bot of its own