Skip to content
← Public packages

@kody/telegram

Read Telegram chats the bot can see and send confirmed messages through the Bot API using telegramBotToken.

AGENTS.md

94 lines · 3.1 KB · Markdown
Raw

@kody/telegram — agent notes

Human setup and intent live in README.md. This file is for agents: imports, smoke/dryRun execute snippets, and edge cases. Secrets by name only — never paste bot tokens. Do not use Telegram Login Widget OAuth for this package. Do not disable live webhooks or jobs (this package has none).

Secrets

NamePurpose
telegramBotTokenDefault Bot API token from @BotFather; host api.telegram.org
telegramBotToken-<slug>Extra bot via secretName (lowercase letters and digits)

Never open /connect/oauth?provider=telegram for Bot API work — that is Login Widget identity only.

Import paths

ExportImport
root overviewkody:@kody/telegram
guidekody:@kody/telegram/guide
smoke-testkody:@kody/telegram/smoke-test
get-mekody:@kody/telegram/get-me
get-updateskody:@kody/telegram/get-updates
get-chatkody:@kody/telegram/get-chat
get-webhook-infokody:@kody/telegram/get-webhook-info
send-messagekody:@kody/telegram/send-message
requestkody:@kody/telegram/request

Prefer static kody:@kody/telegram/... imports from execute. Do not lead with packages.invoke.

Smoke test (read-only)

import smokeTest from 'kody:@kody/telegram/smoke-test'

export default async function main() {
	return await smokeTest()
	// Without telegramBotToken: { ok: true, live: false, setup URL }
	// With token: getMe identity — isBot: true; no messages sent
}

dryRun / confirm

Pass dryRun: true on sends and mutating request calls. Live sends also require confirm: true after the user approves chat and text.

import sendMessage from 'kody:@kody/telegram/send-message'

export default async function main() {
	return await sendMessage({
		chatId: 123456789,
		text: 'Hello from Kody',
		dryRun: true,
	})
}

Read-only updates / webhook check:

import getUpdates from 'kody:@kody/telegram/get-updates'
import getWebhookInfo from 'kody:@kody/telegram/get-webhook-info'

export default async function main() {
	const webhook = await getWebhookInfo()
	const updates = await getUpdates({ limit: 10 })
	return { webhook, updates }
}

Errors

Telegram responseWhat to do
404 Not FoundtelegramBotToken missing or empty — save at README secret URL; approve api.telegram.org
401 UnauthorizedSave/replace telegramBotToken; approve api.telegram.org
403 kicked / not a memberAdd the bot to that chat (admin for channels)
403 not enough rightsGrant the named chat permission — no OAuth scopes to reconnect
400 chat not foundUser must /start the bot, or add it to the group/channel
409 ConflictWebhook set or another poller running — see get-webhook-info; preview deleteWebhook with dryRun: true

Edge cases

  • Bots cannot fetch arbitrary chat history — only getUpdates / webhook deliveries.
  • Privacy mode (/setprivacy) or admin rights control group message visibility.
  • Fork/adapt: save the caller's own telegramBotToken; keep dryRun / confirm guards. Never paste tokens into chat.