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 notification using Telegram Bot API with Laravel.

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:

Retrieving Chat ID

For us to send notifications to your Telegram Bot user/channel or group, we need to know their Chat ID.

This can be done by fetching the updates for your Bot using the getUpdates method as per Telegram Bot API docs.

An update is an object containing relevant fields based on the type of update it represents, some examples of an update object are message, callback_query, and poll. For a complete list of fields, see Telegram Bot API docs.

To make things easier, the library comes with a handy method that can be used to get the updates from which you can parse the relevant Chat ID.

Please keep in mind the user has to first interact with your bot for you to be able to obtain their Chat ID which you can then store in your database for future interactions or notifications.

Here's an example of fetching an update:

[!NOTE] This method will not work if an outgoing webhook is set up.

For a complete list of available parameters for the options, see 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 if Telegram Bot API is not accessible in your country, you can either set a proxy by following the instructions here or use a web bridge by setting the base_uri config above with the bridge uri.

You can set HTTPS_PROXY in your .env file.

Usage

You can now use the channel in your via() method inside the Notification class.

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

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

Preview:

Laravel Telegram Photo Notification Example

Attach a Document

Preview:

Laravel Telegram Document Notification Example

Attach a Location

Preview:

Laravel Telegram Location Notification Example

Attach a Video

Preview:

Laravel Telegram Video Notification Example

Attach a GIF File

Preview:

Laravel Telegram Gif Notification Example

Routing a Message

You can either send the notification by providing with the chat ID of the recipient to the to($chatId) method like shown in the previous examples or add a routeNotificationForTelegram() method in your notifiable model:

Handling Response

You can make use of the notification events to handle the response from Telegram. On success, your event listener will receive a Message object with various fields as appropriate to the notification type.

For a complete list of response fields, please refer the Telegram Bot API's Message object docs.

Exception Handling

In case of failures, the package provides two ways to handle exceptions.

Using NotificationFailed Event

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

Listener example:

Using onError Callback

You can handle exceptions for individual notifications using the onError method in your notification:

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

On-Demand Notifications

Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification. For more details, you can check out 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 multiple users, the Telegram Bot API will not allow more than 30 messages per second or so. 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.

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.

Telegram Location Methods

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

Telegram File Methods

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

Helper Methods:

Telegram Contact Methods

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

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 advance usage, please consider using telegram-bot-sdk instead.

Changelog

Please see CHANGELOG for more information what has changed recently.

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.1
ext-json Version *
guzzlehttp/guzzle Version ^7.2
illuminate/contracts Version ^10 || ^11.0
illuminate/notifications Version ^10 || ^11.0
illuminate/support Version ^10 || ^11.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 ....