Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Telegram Bot Laravel Package

longman/telegram-bot

longman/telegram-bot is a mature PHP library for building Telegram bots with a clean object-oriented API. It supports commands, inline keyboards, conversations, admin tools, webhooks and long polling, with extensive docs and examples for rapid bot development. Suitable for simple scripts and large b...

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • longman/telegram-bot is a framework-agnostic Telegram Bot API client plus an opinionated command-routing layer (command classes extending Longman\TelegramBot\Commands\Command, split into system/user/admin command namespaces). It is an application skeleton as much as a library, which fits well when the bot is the product and less well when Telegram is a side channel inside an existing Laravel app.
  • There is no first-party Laravel service provider, facade, or publishable config. Integration means writing a thin adapter in app/ that owns the Telegram instance, config, and route — acceptable, but it becomes our code to maintain.
  • The package leans on static/global state (Telegram:: setters, static command registry, static Request/Response helpers). That is fine for classic PHP-FPM request lifecycles, but it is a real consideration under Laravel Octane/Swoole and it makes container-based DI into command classes awkward. Expect to resolve dependencies via app() inside execute() or to override the command factory. The 0.83.1 fix for setCustomBotApiUri — configuration set after the Telegram object exists now takes effect — is a direct example of this fragility: ordering dependence in static state was a live bug, not a hypothetical.
  • Database expectations are the biggest architectural mismatch: the bundled bot-manager/admin features assume a MySQL schema. Core webhook handling can run without a DB, but conversation state, admin commands, and any "manager"-style workflow should be treated as bring-your-own-persistence in a Laravel stack (Eloquent/Redis) rather than adopting the shipped schema. Note that 0.83.1 also patches a migration script (0.82.0-0.83.0.sql) — the shipped schema is versioned and needs upgrade scripts applied in order, which is another reason to keep it out of our critical path.

Integration feasibility

  • High for the common case: install via Composer, point a POST route at the package, feed the raw JSON body into Request::fromJson(), dispatch via Telegram::run(), return 200. A working echo bot is an afternoon.
  • Polling (getUpdates) is supported but is a poor fit for Laravel request/response hosting; it implies a supervised long-running worker or an artisan daemon.
  • No Laravel-idiomatic competitor lock-in problem, but note the alternative irazasyed/telegram-bot-sdk is materially more Laravel-native if container DI, facades, and queued jobs are priorities.

Technical risk

  • Bus factor / maintenance cadence: still effectively a one-primary-maintainer project, but the recent 0.83.0 → 0.83.1 sequence shows the project responding quickly to regressions — 0.83.1 is a same-cycle critical-error fastfix plus two targeted fixes, authored in part by a first-time contributor. That is a modest positive signal for responsiveness and a reminder that patch releases can land without warning. MIT license means we can fork, but we should still budget for self-patching against Telegram API changes.
  • Patch-release quality: 0.83.0 shipped a "critical error" that 0.83.1 corrects. We should not pin 0.83.0 under any circumstances, and we should not auto-bump patch versions of this dependency without a smoke test — the changelog is thin and regressions reach a release candidate stage.
  • PHP/Laravel compatibility drift: verify the package's PHP constraint against our runtime (8.2/8.3/8.4) and against Laravel 11/12 before committing. Guzzle is a transitive dependency; confirm it resolves cleanly with the version Laravel ships. Re-verify on every minor bump; 0.83.x carries no declared breaking changes from the notes, but the notes are short.
  • Ecosystem signal: 4k stars but dependents: 0 on Packagist indicates almost nobody consumes it as a library — its audience runs it as a standalone app. That is a weak proxy for library-grade API stability and semver discipline, and the 0.83.1 changelog reflects application-level concerns (SQL migrations) more than library-level API guarantees.
  • Webhook correctness is on us: duplicate delivery (Telegram retries on non-2xx or timeout), out-of-order updates, and 429 retry_after backoff are not "solved" by the package at the application level. Idempotency on update_id and fast-ack + async processing must be designed in.
  • Static state + long-lived workers: under Octane, static command registries and last-update state can leak between requests. The setCustomBotApiUri fix confirms that global configuration is only applied at specific points in the object lifecycle — a class of bug that is materially harder to reason about in a long-lived worker.
  • Scope of this release: 0.83.1 is a patch release. No breaking changes, no deprecations, no new feature surface. It does not change our integration approach.

Key questions

  1. Is this bot a single-tenant side channel, or do we need multi-bot / multi-tenant token management (one Telegram instance per token, lifecycle, secret storage)?
  2. Webhook or polling? If polling, do we have a worker/supervisor story, and do we accept single-consumer-per-token semantics?
  3. Which Bot API surface do we actually need — inline queries, callback queries, media groups, payments, file downloads? Coverage of edge features should be validated against the pinned version, not the README.
  4. Do we need the built-in admin/manager and its MySQL schema, or will we own persistence in Eloquent/Redis? If any part of the shipped schema is adopted, who owns applying and testing its migration scripts on upgrade?
  5. What is our acceptable upstream-abandonment posture — fork-and-maintain, or migrate to a more Laravel-native SDK later? That answer should drive how thick our adapter boundary is.
  6. Are we prepared to own idempotency, rate limiting, retry/backoff, and observability, or were we implicitly expecting the package to?
  7. Do we have a patch-bump policy (pin exact, smoke test, then advance), given 0.83.0 → 0.83.1 shows a regression fix landing in the same minor line?

Integration Approach

Stack fit

  • Composer/PSR-4, no framework coupling: it drops into Laravel, Symfony, or plain PHP. The natural Laravel shape is a small internal package: TelegramServiceProvider, config/telegram.php (token, webhook secret, command paths, allowed chats), a TelegramClient wrapper, and an Http/Controllers/TelegramWebhookController excluded from CSRF.
  • Keep business logic in framework-native services/jobs; let the package own only transport, update parsing, and command dispatch. That preserves the option to swap SDKs later.
  • If container injection into commands matters, implement a container-aware command factory (or a base AppCommand that pulls collaborators via app()), and write one test proving it works before scaling the pattern.
  • Apply any global configuration (custom API URI, token, command paths) via the service provider at boot, before any Telegram instance is constructed. The 0.83.1 fix makes late configuration work, but relying on construction-order semantics is a trap we should not design around.

Migration path

  • If replacing an existing SDK, define an internal BotHandler interface first (handleUpdate(array $payload): void) and implement it twice — once over the old SDK, once over this package. Route and controller stay stable; handlers are swappable.
  • Map existing slash-command handlers 1:1 to command classes, but move side effects (DB writes, third-party calls) out of execute() into queued jobs so the migration does not also migrate latency problems.
  • Rollback is cheap and should be explicit: deleteWebhook (or repoint the route) plus a feature flag on the controller. Telegram retains updates for 24h, so a botched cutover is recoverable.

Compatibility

  • Pin an exact version and commit the lockfile; pin 0.83.1 or later, never 0.83.0. Verify PHP constraint, Guzzle constraint, and required extensions (json, mbstring, curl; PDO/MySQL only if the manager is used).
  • Confirm behavior on our deployment target (PHP-FPM vs Octane vs queue worker). If Octane is in play, run a spike that sends two sequential updates through one worker and asserts no state bleed.
  • Validate the webhook secret-token header check and IP allowlist strategy in staging before production exposure.
  • Re-run the compatibility spike on each minor bump of 0.83.x; the release notes are too terse to serve as a change-impact assessment.

Sequencing

  1. Spike (1–2 days): echo/health bot in staging on 0.83.1, webhook route, secret-token validation, one real command. Confirms PHP/Laravel compatibility empirically.
  2. Adapter layer: service provider, config, TelegramClient wrapper, base command class, error handling contract.
  3. Golden path: 2–3 real commands end-to-end, including one with an outbound API call moved to a queued job.
  4. Hardening: idempotency store keyed on update_id, 429/retry_after backoff, structured logging with update_id/chat_id correlation, alerting on webhook 5xx rate.
  5. Production cutover: feature-flagged route, webhook registration, smoke tests, documented rollback.
  6. Decommission old path only after a stable observation window.

Operational Impact

Maintenance

  • Low ongoing code volume but non-zero ownership: the package is a dependency we do not control, released infrequently and in bursts. Budget a recurring review (quarterly, plus a triggered review whenever a release lands) of upstream releases and the Telegram Bot API changelog, plus an internal policy for pinning and patching.
  • Treat upgrades as small change-managed events rather than routine dependency bumps: read the diff, run the golden-path suite, and advance the pin. The 0.83.1 critical-error fastfix is the justification.
  • MIT + PHP means forking is viable if upstream stalls; that is a real mitigation but only if our adapter boundary is thin and our command classes contain no framework-specific cleverness.

Support

  • Community-only: GitHub issues and a Telegram community chat, no SLA. Responsiveness looks reasonable on recent evidence (a fastfix landed quickly), but it is goodwill, not a commitment.
  • Internal runbook is mandatory — webhook URL/token rotation, how to re-register a webhook, how to replay a dropped update, how to disable a runaway broadcast, and how to roll forward/back a package version.
  • Secrets handling (bot token, webhook secret) should live in the existing secret manager, not .env committed to a deploy repo; token rotation should be a rehearsed procedure.

Scaling

  • Webhook mode scales horizontally if the handler is stateless and fast — externalize conversation state (Redis/Eloquent) and keep the request path to parse-ack-enqueue. Ack within Telegram's timeout window (order of seconds) or expect retries.
  • Polling does not scale: one consumer per token, no horizontal fan-out. If chosen, it belongs in a single supervised worker with restart policy and offset-loss handling.
  • Outbound throughput is bounded by Telegram limits (roughly 30 messages/sec globally, ~1 msg/sec per chat). Broadcasts and fan-outs must go through a rate-limited queue with per-chat spacing, not a foreach in a command.
  • Static state in the package is the scaling footgun under Octane/Swoole; validate before standardizing on a long-lived worker runtime.

Failure modes

  • Duplicate update processing from webhook retries → user-visible double actions (double charges, double confirmations) unless update_id is deduplicated.
  • 429 without backoff → cascading failures during a broadcast; Telegram may temporarily restrict the bot.
  • Token leakage in logs or command exceptions → full bot takeover; scrub payloads and never log the token.
  • Blocking webhook handler (sync HTTP call, slow DB, large file download) → retries, reordering, duplicate side effects.
  • Media/file handling limits (bot download caps, 4096-char message limit) → silent truncation or hard errors that look like bugs to users.
  • Upstream drift: an occasionally-maintained dependency against a moving Bot API; new update types may be silently dropped by the parser.
  • Static-state bleed in long-lived workers → cross-request contamination that is hard to reproduce and easy to dismiss as "flaky."
  • Version regression: pulling a fresh patch without smoke testing reintroduces an upstream critical error into our production path.

Ramp-up

  • A mid-level Laravel developer is productive in 1–2 days: command-class pattern, Request/Response helpers, and /command naming are conventional and well documented. The entity/validation layer (Longman\TelegramBot\Entities) and edge cases (callback queries, inline mode, media groups) take longer — roughly a week to fluency.
  • The genuine learning curve is operational, not API-level: idempotency, rate limits, webhook semantics, and Telegram's update model. Plan for the first bot to take 1–2 weeks to production-grade including hardening, and treat the second one as the cheap one.
  • Documentation examples are somewhat dated relative to recent Bot API versions and the changelog is terse; expect to verify behavior against the API docs and the actual diff rather than the release notes, and to encode those findings in the internal runbook.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console