# telegram

A Telegram bot from the back end, over the Bot API, and its updates by a
webhook or by long polling, each done once. The whole of it is
[docs/telegram.md](../../docs/telegram.md).

```text
use "pkg:telegram/updates.mote"      // takes telegram.mote

telegramSend(chat, "Pick one", {keyboard: telegramInline([[telegramButton("Yes", "yes")]])}, "")?
telegramSendFile(chat, "photo", {data: png, name: "lamp.png", type: "image/png"}, "A lamp", {}, "")?
fn telegramMessage(m: TelegramMessage): bool          // the program's hooks
fn telegramPressed(c: TelegramCallback): string
```

Settings: `TELEGRAM_TOKEN`, `TELEGRAM_WEBHOOK_SECRET` (secrets);
`TELEGRAM_POLL`, `TELEGRAM_API`, `TELEGRAM_WAIT`.

| File | |
|---|---|
| `telegram.mote` | The calls, keyboards, the shapes, refusals and the 429. |
| `updates.mote` | `POST /telegram/webhook` (the secret token), long polling in a job, each update once, the hooks. |
| `tests.mote` | Its tests (tests/svc_code/unit.mote). |

**Covered:** messages (HTML or MarkdownV2, replies, topics, silent, no
preview, protected), inline and reply keyboards, forced replies; photos,
documents, sounds, videos, voice, animations and stickers by id, address or
bytes; edits, keyboards changed, deletes; presses answered; "typing";
files' paths and bytes; the bot, its commands, its webhook set, deleted and
read; updates (messages, edits, channel posts, presses) by webhook or long
polling, the place reached kept; commands read with their `@botname` left
off; a 429's `retry_after` waited out.

**Left out on purpose:** inline mode, payments, games, Web Apps' initData
check, business connections, stories, polls, media groups (by
`telegramCall`), files over 20 MB, MTProto.

**Not yet run against Telegram**: only against a stand-in (`tests/all.sh
real_svc_code`).
