Bot (Telegram / Discord / Slack)
Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.
For agents
- A bot is a public entry point into your system: anyone on the platform may talk to it. Typical class: S or M.
- Rule 1: the token is secret and replaceable; incoming webhooks are verified with the platform’s signature or secret.
- Rule 2: request the smallest scopes and intents; check who is asking before sensitive commands.
- Rule 3: respect platform rate limits, handle duplicate updates, and minimize and delete stored messages.
Which class?
- S: a hobby bot in one group with no stored personal data.
- M: it stores user data, calls paid APIs, or runs commands with effects.
- L: many servers or workspaces, payments, sensitive data.
- XL: a very large public bot.
Audit checklist
Every project
- Facts are verified from current official documentation
- What: Commands, libraries, APIs and platform policies in the project come from current official documents, not from memory.
- How to check: Open the dependency list and the platform configuration; for each non-trivial choice find the official page it relies on (link in a comment or a decision note).
- Evidence: Decision note or code comment with the official URL and the date it was checked.
- Packages come from official sources, stable versions only
- What: Packages and versions are chosen from official sources; the current stable release is used, not alpha or beta.
- How to check: Read the dependency file for pre-release tags (alpha, beta, rc, next); check each package on its official registry page.
- Evidence: Dependency file without pre-release versions.
- No secrets in code, chat, commits or logs
- What: Passwords, keys and tokens live in environment variables or a secret manager;
.envis ignored by git; the repository has only.env.example. - How to check: Check
.gitignorefor.env; run a secret scanner (for example gitleaks) over the full history; search for key-like strings. - Evidence:
.gitignoreline, scanner report with zero findings,.env.examplepath.
- What: Passwords, keys and tokens live in environment variables or a secret manager;
- Reports separate “written”, “tested” and “works end to end”
- What: Status reports say clearly whether something is written, passed its tests, or was run end to end; skipped or failed steps are stated.
- How to check: Read the last HANDOFF or release notes; look for features reported as done that have no test or run record.
- Evidence: HANDOFF lines or a test log for each feature marked done.
- Project memory files exist and are current
- What: The repository has CLAUDE.md or AGENTS.md (permanent rules) and HANDOFF.md (where we stopped), updated at the end of every work round.
- How to check: Look in the repository root for both files; compare the HANDOFF date with the latest commit date.
- Evidence: File paths and the date of the last HANDOFF update.
- The bot token is secret and replaceable
- What: The token is stored in the environment, never in code or chat; there is a documented way to rotate it.
- How to check: Search the repository for the token pattern; read the rotation note.
- Evidence: Scan report; rotation note.
- Incoming requests are verified
- What: Webhooks and events are verified with the platform’s signature or secret token before processing; old or repeated requests are rejected.
- How to check: Read the webhook handler for signature checks and timestamp/duplicate handling.
- Evidence: Handler code; forged-request test.
- Scopes and intents are minimal
- What: The bot requests only the scopes, intents and permissions it needs, and server-level permissions are not given by default.
- How to check: Read the installation permissions or OAuth scopes.
- Evidence: Scope list with reasons.
+ If it has users, personal data or API keys (M)
- One package manager, lockfile committed
- What: Exactly one package manager is used and enforced; the lockfile is committed; installs are done from the lockfile (for example
--frozen-lockfile). - How to check: Look for a lockfile in the repository and a rule that forbids other managers; check the CI and Docker install commands.
- Evidence: Lockfile path; install command lines.
- What: Exactly one package manager is used and enforced; the lockfile is committed; installs are done from the lockfile (for example
- Sensitive commands check who is asking
- What: Admin or costly commands check the user’s identity or role on the server; chat membership alone is not proof.
- How to check: List commands and their permission checks.
- Evidence: Command table; denied-call test.
- Platform rate limits are respected
- What: The bot reads rate limit responses and backs off; bulk sending is queued.
- How to check: Read the sending code for retry and backoff.
- Evidence: Code; test with a simulated 429.
- Message data is minimized and deleted on schedule
- What: The bot stores only what it needs from conversations, has a retention period, and a way for users to ask for deletion or to stop.
- How to check: List stored fields; read the retention and stop/delete commands.
- Evidence: Field list; command text.
- Duplicate or out-of-order updates are handled
- What: Replays and retried deliveries do not cause double actions.
- How to check: Send the same update twice.
- Evidence: Test showing one effect.
- All input is validated on the server with a schema
- What: Every request body, query and parameter is checked on the server against a schema; the client check is only a convenience.
- How to check: For each endpoint find the schema or validator; send invalid, oversized and unexpected fields and see the response.
- Evidence: Validator files per endpoint; test cases for invalid input.
- External API keys stay on the server
- What: Third-party API keys (including LLM keys) are kept on the server and never shipped to the browser or app.
- How to check: Search the client bundle and app package for key-like strings; check that client calls go to your own server.
- Evidence: Search result with zero keys in the client build.
- Logs contain no personal data or secrets
- What: Logs do not record passwords, tokens, keys or personal data; if needed they are masked.
- How to check: Read the logging setup; trigger a login and a form and inspect the log lines; search for e-mail and token patterns.
- Evidence: Sample log lines after a test run showing masking.
- Personal data fields are documented
- What: For every personal data field the purpose, retention time and legal basis (KVKK, GDPR) are written down.
- How to check: List the database columns and form fields with personal data; find the matching entries in the data note.
- Evidence: Data note listing each field with purpose, period and basis.
- One deletion schedule covers all data
- What: Every kind of data has a deletion period, collected in one deletion schedule document, and the code implements it.
- How to check: Find the document; for each row find the job or code that deletes the data.
- Evidence: Schedule document and the matching job names.
- Automatic backups with a tested restore
- What: The database is backed up automatically, retention is written down, and a restore has actually been tried.
- How to check: Find the backup job and its schedule; find the record of the last restore test.
- Evidence: Backup schedule, retention setting and dated restore-test record.
- Critical flows have automated tests and a local check
- What: Login, saving data, payment (if any) and permission checks have automated tests; one local command runs the checks before pushing.
- How to check: List the test files; run the check command; look for a git hook that runs it.
- Evidence: Test names and a passing run log.
- Secret scanning runs before push and in CI
- What: A scanner (for example gitleaks or secretlint) runs before code is pushed and in CI.
- How to check: Find the hook or CI step that runs the scanner.
- Evidence: Hook file or CI step; latest clean run.
- Every external call has a time limit
- What: Database queries, storage, e-mail, notifications, AI calls and external processes all have an upper time limit.
- How to check: Search for HTTP client and process calls without a timeout setting.
- Evidence: Configuration or code lines with timeouts.
+ If it has an admin panel, file uploads, many users or a store app (L)
Items for class L: see Bot: classes L–XL checklist.
+ If it targets millions of users (XL)
Items for class XL: see Bot: classes L–XL checklist.
Common mistakes
- Posting the bot token in a chat or committing it.
- Not verifying webhook signatures, so anyone can post fake events.
- Requesting administrator permission when a few scopes would do.
- Treating chat membership as proof that a user is allowed to run a command.
- Ignoring 429 responses and being blocked by the platform.
- Double-processing the same update after a retry.
- Storing full chat logs with no retention period.
- No way for users to stop the bot or delete their data.
Example projects
- Group moderation bot: bot, S or M.
- Reminder bot with stored messages: bot, M, personal data.
- Slack app that posts alerts: bot, S.
- Discord music bot: bot, M.
- Customer support bot connected to a ticket system: bot, M.
- Telegram shop bot with payments: bot, L.
- Workspace admin bot that can change settings: bot, L.
- Trivia game bot: bot, S.
- Expense bot for a team: bot, M, financial data.
- Bot used by tens of thousands of servers: bot, XL.
- AI chat bot on Telegram: bot, M, see AI assistant.
- Notification bridge between systems: bot, S.
Sources
- Telegram Bot API — Telegram
- Telegram Bots FAQ — Telegram
- Telegram Bot Features — Telegram
- Discord Developer Platform: Intro — Discord
- Discord: Rate Limits — Discord
- Discord: OAuth2 — Discord
- Slack: Security best practices — Slack
- Slack: Verifying requests from Slack — Slack
- Slack: Rate limits — Slack
- Secrets Management Cheat Sheet — OWASP Cheat Sheet Series
- Pro Build Guide v1.2: compiled team practices — Pro Build Guide