Download the PHP package laravel-notification-channels/telegram without Composer

On this page you can find all versions of the php package laravel-notification-channels/telegram. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package telegram

Telegram Notifications Channel for Laravel

Join PHP Chat Chat on Telegram Latest Version on Packagist Total Downloads

This package makes it easy to send Telegram notifications from Laravel via the Telegram Bot API.

Contents

Installation

You can install the package via composer:

Setting up your Telegram Bot

Talk to @BotFather and generate a Bot API token.

Then, configure your Telegram Bot API token:

[!NOTE] The package also supports the legacy services.telegram-bot-api.* config keys for backward compatibility, but services.telegram.* is the preferred configuration format.

Retrieving Chat ID

To send notifications to a Telegram user, channel, or group, you need its chat ID.

You can retrieve it by fetching your bot updates with the getUpdates method described in the Telegram Bot API docs.

An update is an object whose shape depends on the event type, such as message, callback_query, or poll. For the full list of fields, see the Telegram Bot API docs.

To make this easier, the package ships with TelegramUpdates, which lets you fetch updates and inspect the chat IDs you need.

Keep in mind that the user must interact with your bot first before you can obtain their chat ID and store it for future notifications.

Here's an example of fetching an update:

[!NOTE] This method will not work while an outgoing webhook is configured.

For the full list of supported options(), see the Telegram Bot API docs.

Proxy or Bridge Support

You may not be able to send notifications directly if the Telegram Bot API is blocked in your region. In that case, you can either configure a proxy by following the Guzzle instructions here or point the package at a bridge or self-hosted Bot API server by setting the base_uri config shown above.

You can also set HTTPS_PROXY in your .env file, or set the proxy key (or any other Guzzle request option, such as timeout) in the services.telegram.http config array shown above.

Usage

You can now return the channel from your notification's via() method.

Text Notification

Here's a screenshot preview of the above notification on Telegram Messenger:

Laravel Telegram Notification Example

Send with Keyboard

Preview:

Laravel Telegram Notification Keyboard

You can also request structured input from the keyboard:

Preview:

Laravel Telegram Notification Keyboard Request Number and Location

Send a Dice

Preview:

Laravel Telegram Dice Notification

Send a Poll

Preview:

Laravel Telegram Poll Example

Send a Rich Message

Rich messages (Bot API 10.1) let you send long-form, formatted posts built from blocks or from a single Markdown / HTML document.

The simplest way is to pass Markdown (or HTML) content, referencing any attached media with tg://photo?id=, tg://video?id= or tg://audio?id= links:

For full control over the layout, build the message out of blocks:

All the common methods (to(), button(), keyboard(), disableNotification(), replyParameters(), ...) work as usual and are sent alongside the encoded rich_message param.

[!NOTE] Block types without a dedicated builder (such as collage and slideshow) can be added with the block() escape hatch. Direct file uploads for rich message media are not supported: reference media by URL or file_id.

Streaming Drafts

Drafts (sendRichMessageDraft) are temporary messages shown to the user while they're still being written. Sending again with the same draftId() animates the replacement of the previous content, which makes TelegramRichMessageDraft a good fit for streaming an AI generated answer as it's produced:

Every content and block builder of TelegramRichMessage is available on the draft, so you can stream blocks instead of Markdown if you prefer.

[!IMPORTANT] Drafts can only be sent to private chats and the draft_id must be a non-zero integer. Batch your updates (roughly one send() every 0.5-1 seconds) instead of sending one per token, otherwise your bot will quickly hit the API rate limits. A draft that's never finalized simply disappears: only finalize() leaves a permanent message behind. The endpoint accepts chat_id, message_thread_id, draft_id, rich_message, can_stop and keep_on_stop only, so buttons and notification flags are applied when the draft is finalized.

Attach a Contact

Preview:

Laravel Telegram Contact Example

Attach an Audio

Preview:

Laravel Telegram Audio Notification Example

Attach a Photo

You can also use a helper method with a remote file or Telegram file ID:

If you already know whether you're dealing with a URL or a Telegram file ID, use the explicit methods instead — they validate the input and skip the detection heuristics:

Preview:

Laravel Telegram Photo Notification Example

Attach a Document

Preview:

Laravel Telegram Document Notification Example

If you want to control the filename, you need to upload the actual file contents instead of passing the remote URL directly:

Preview:

Laravel Telegram Document Notification Example with Custom Filename

Raw file contents are also supported when you provide a filename:

Preview:

Laravel Telegram Document On Fly

Attach a Location

Preview:

Laravel Telegram Location Notification Example

You can also send live location

Preview:

Laravel Telegram Live Location Notification Example

Attach a Venue

Preview:

Laravel Telegram Venue Notification Example

Attach a Video

Preview:

Laravel Telegram Video Notification Example

Attach a GIF File

Local files work the same way:

Preview:

Laravel Telegram Gif Notification Example

Attach a Sticker

Preview:

Laravel Telegram Sticker Notification Example

Send a Media Group

Use TelegramMediaGroup to send multiple items in a single group.

Uploaded files are also supported:

Preview:

Laravel Telegram Media Group Notification Example

Documents are also supported, including dynamically generated content:

Preview:

Laravel Telegram Media Group Documents Notification Example

Supported Input Types

Each media item can be provided as:

When uploading local files or raw content, the package automatically handles multipart uploads.

Media groups support albums of photo, video, audio, and document items.

[!NOTE] Telegram does not allow mixing certain media types within a single group. Documents cannot be combined with photos or videos. However, photos and videos can be sent together in the same media group.

Routing a Message

You can either send a notification by setting the recipient explicitly with to($chatId) as shown above, or define routeNotificationForTelegram() on your notifiable model:

Handling Response

You can use notification events to handle Telegram responses. On success, your listener receives a Message object with fields appropriate to the notification type.

For the full list of response fields, refer to the Telegram Bot API Message object docs.

Exception Handling

For failures, the package provides two exception-handling hooks.

Using NotificationFailed Event

You can listen to Illuminate\Notifications\Events\NotificationFailed, which provides a $data array containing to, request, and exception keys.

Listener example:

Using onError Callback

You can handle exceptions for an individual notification by attaching an onError callback:

In both methods, the $data array contains the following keys:

On-Demand Notifications

Sometimes you may want to send a Telegram notification to someone who is not stored as a notifiable model. With Notification::route, you can provide ad-hoc routing information before dispatching the notification. For more details, see the on-demand notifications docs.

Sending to Multiple Recipients

Using the notification facade, you can send a notification to multiple recipients at once.

[!WARNING] If you're sending bulk notifications to many users, the Telegram Bot API will not allow much more than 30 messages per second. Consider spreading out notifications over large intervals of 8—12 hours for best results.

Also note that your bot will not be able to send more than 20 messages per minute to the same group.

If you go over the limit, you'll start getting 429 errors. The package automatically waits for the retry_after duration reported by Telegram and retries once (skipped when retry_after exceeds 60 seconds), but sustained bursts will still fail. For more details, refer Telegram Bots FAQ.

Using the Telegram Client Directly

If you need lower-level Bot API access, you can use the Telegram facade:

Or resolve the Telegram client directly from the container:

Available direct client helpers currently include:

Available Methods

For more information on supported parameters, check out these docs.

Common Methods

These methods are optional and common across all the API methods.

Telegram Message Methods

Telegram message notifications are used to send text messages to the user. Supports Telegram formatting options

[!NOTE] A one second pause is added between chunks to comply with Telegram's rate limits.

A chunk boundary can still land inside a Markdown entity (e.g. an unclosed *bold*), which Telegram rejects. Prefer chunk-sized paragraphs, or disable the parse mode with normal() for machine-generated content.

Helper Methods:

Telegram Location Methods

Telegram location messages are used to share a geographical location with the user.

Telegram Venue Methods

Telegram venue messages are used to share a geographical location information about a venue.

Telegram File Methods

Telegram file messages are used to share various types of files with the user.

Helper Methods:

Telegram Media Group Methods

Telegram media groups are albums of photo, video, audio, document, or live_photo items sent as a single notification.

Each media item may be a Telegram file ID, a URL, a local path, a stream/resource, or raw file contents when paired with a filename.

Telegram Contact Methods

Telegram contact messages are used to share contact information with the user.

Telegram Dice Methods

Telegram dice messages are interactive emoji dice / darts / slots / bowling style messages.

Telegram Poll Methods

Telegram polls are a type of interactive message that allows users to vote on a question. Polls can be used to gather feedback, make decisions, or even run contests.

Telegram Rich Message Methods

Telegram rich messages are long-form posts built from an InputRichMessage. You can either provide Markdown / HTML content or compose the message out of blocks (or both). Every RichText parameter accepts a plain string or a rich text array, which is passed through to the API untouched.

Content Methods:

Block Methods:

Each of these appends an InputRichBlock to the message, in the order they are called.

Draft Methods:

TelegramRichMessageDraft extends TelegramRichMessage, so every content and block method above is available on a draft as well. See Streaming Drafts.

Alternatives

For advanced usage, please consider using telegram-bot-sdk instead.

Changelog

Please see CHANGELOG for details about recent changes.

Testing

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of telegram with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
guzzlehttp/guzzle Version ^7.8
illuminate/contracts Version ^12.0 || ^13.0
illuminate/notifications Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package laravel-notification-channels/telegram contains the following files

Loading the files please wait ...