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.

Using in Lumen

If you're using this notification channel in your Lumen project, you will have to add the below code in your bootstrap/app.php file.

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.

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

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:

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. For more details, refer Telegram Bots FAQ.

Using the Telegram Client Directly

If you need lower-level Bot API access, you can 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] Chunked messages will be rate limited to one message per second to comply with rate limitation requirements from Telegram.

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, or document 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.

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 ...