{"id":20002803,"url":"https://github.com/babenkoivan/telegram-notifications","last_synced_at":"2025-05-04T15:34:31.782Z","repository":{"id":62491004,"uuid":"82410661","full_name":"babenkoivan/telegram-notifications","owner":"babenkoivan","description":"Telegram notifications for Laravel","archived":false,"fork":false,"pushed_at":"2021-11-10T08:38:20.000Z","size":22,"stargazers_count":38,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T08:05:21.071Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/babenkoivan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-18T19:25:43.000Z","updated_at":"2025-01-03T04:39:10.000Z","dependencies_parsed_at":"2022-11-02T11:16:13.338Z","dependency_job_id":null,"html_url":"https://github.com/babenkoivan/telegram-notifications","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Ftelegram-notifications","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Ftelegram-notifications/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Ftelegram-notifications/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Ftelegram-notifications/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babenkoivan","download_url":"https://codeload.github.com/babenkoivan/telegram-notifications/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252357142,"owners_count":21735086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T05:23:08.529Z","updated_at":"2025-05-04T15:34:31.519Z","avatar_url":"https://github.com/babenkoivan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram Notifications For Laravel\n\n[![Packagist](https://img.shields.io/packagist/v/babenkoivan/telegram-notifications.svg)](https://packagist.org/packages/babenkoivan/telegram-notifications)\n[![Packagist](https://img.shields.io/packagist/dt/babenkoivan/telegram-notifications.svg)](https://packagist.org/packages/babenkoivan/telegram-notifications)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://packagist.org/packages/babenkoivan/telegram-notifications)\n\n\nThe package provides easy way to send [Telegram](https://telegram.org/) notifications to any [notifiable entity](https://laravel.com/docs/5.3/notifications#sending-notifications) in your project.\nIt uses official [Telegram Bot API](https://core.telegram.org/bots/api) to deliver your message directly to a user.\nYou can send any information you want: text, media, location or contact. \n\n## Contents\n\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Set up your model](#set-up-your-model)\n* [Usage example](#usage-example)\n* [Advanced Usage](#advanced-usage)\n    * [Single Message](#singlemessage)\n        * [TelegramMessage](#telegrammessage)\n        * [TelegramPhoto](#telegramphoto)\n        * [TelegramAudio](#telegramaudio)\n        * [TelegramDocument](#telegramdocument)\n        * [TelegramSticker](#telegramsticker)\n        * [TelegramVideo](#telegramvideo)\n        * [TelegramVoice](#telegramvoice)\n        * [TelegramLocation](#telegramlocation)\n        * [TelegramVenue](#telegramvenue)\n        * [TelegramContact](#telegramcontact)\n    * [Message Collection](#message-collection)\n\n## Requirements\n\nThe package has been tested on following configuration: \n\n* PHP version \u0026gt;= 7.3\n* Laravel Framework version \u0026gt;= 5.5\n\n## Installation\n\nTo install the package you can use composer:\n\n```\ncomposer require babenkoivan/telegram-notifications\n```\n\nIf the package discovery is disabled, you need to register the service provider in `config/app.php` file:\n\n```php\n'providers' =\u003e [\n    TelegramNotifications\\TelegramServiceProvider::class    \n]\n``` \n\nTo copy the package settings to `config` directory run:\n\n```\nphp artisan vendor:publish --provider='TelegramNotifications\\TelegramServiceProvider'\n```\n\nNow you're ready to set up a bot token for your application. \nIf you haven't created a bot you can make new one using [BotFather](https://telegram.me/botfather). \nFor more information, visit [Bots: An introduction for developers](https://core.telegram.org/bots) page.\n \nLet's move on and assume you have a token. \nYou can configure the token either in `.env` file:\n\n```\nTELEGRAM_BOT_TOKEN=335237666:FFF45pYTYm9HkKWByaepSpcKAUWMo2uMF_9\n```\n\nor in `config/telegram.php` file:\n\n```php\n\u003c?php\n\nreturn [\n    'bot_token' =\u003e '335237666:FFF45pYTYm9HkKWByaepSpcKAUWMo2uMF_9',\n];\n```\n\nOf course, the token above is just an example, you have to specify your own token.\n\n## Set up your model\n\nTo notify user or any other notifiable entity you need to use `Notifiable` trait with your model and define `routeNotificationForTelegram` method, which will return a `chat_id`:\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable\n{\n    use Notifiable;\n\n    // ...\n\n    public function routeNotificationForTelegram()\n    {\n        return 993344556;\n    }\n}\n```\n\nAt this point, you may wonder where to get a `chat_id`. The answer is it's up to you! \nYou can create a [webhook](https://core.telegram.org/bots/api#setwebhook) to receive updates for your bot and collect chat ids, or you can specify ids manually for certain users.\n\nTo get started, you can send `Hello!` message to your bot and then get message details by requesting [API method](https://core.telegram.org/bots/api#getupdates):\n\n```\ncurl https://api.telegram.org/bot\u003cyour_token_here\u003e/getUpdates\n```\n\nYou will receive a JSON in return:\n\n```\n{\n    \"ok\": true,\n    \"result\": [\n        {\n            \"message\": {\n                \"chat\": {\n                    \"id\": 993344556 // this is what we were looking for \n                    // ...\n                }\n            }\n        }\n    ]\n}\n```\n\n## Usage example\n\nif you [installed the package](#installation) and [configured a model](#set-up-your-model) you're ready to make your first Telegram notification.\nYou can create a new notification using `artisan` command:\n\n```\nphp artisan make:notification TelegramNotification\n```\n\nAnd again, `TelegramNotification` here is just an example, you can specify any name you want.\n\nNow, you can go to `app/Notifications` folder and you'll see `TelegramNotification.php` file. \nIn `via` method specify `TelegramChannel::class` and initialize a new `TelegramMessage` instance in `toTelegram` method:\n\n```php\n\u003c?php\n\nnamespace App\\Notifications;\n\nuse Illuminate\\Bus\\Queueable;\nuse Illuminate\\Notifications\\Notification;\n\nuse TelegramNotifications\\TelegramChannel;\nuse TelegramNotifications\\Messages\\TelegramMessage;\n\nclass TelegramNotification extends Notification\n{\n    use Queueable;\n\n    public function via()\n    {\n        return [TelegramChannel::class];\n    }\n\n    public function toTelegram()\n    {\n        return (new TelegramMessage())-\u003etext('Hello, world!');\n    }\n}\n```\n\nTo send the notification use `notify` method with notifiable entity. \n\nLet's say we have an authenticated user and we want to send a message from a route callback.\nWe can do it like this:\n\n```php\n\u003c?php\n\nuse \\App\\Notifications\\TelegramNotification;\n\nRoute::post('/', function () {\n    Auth::user()-\u003enotify(new TelegramNotification());\n});\n```\n\n## Advanced Usage\n\nYou can send either a single message or a message collection at once.\n \n### Single Message\n\nEach message class represents certain type of information you can deliver to a user.\nTo send a message return a new instance of necessary type from `toTelegram` method:\n\n```php\n\u003c?php\n\nnamespace App\\Notifications;\n\nuse Illuminate\\Bus\\Queueable;\nuse Illuminate\\Notifications\\Notification;\n\nuse TelegramNotifications\\TelegramChannel;\nuse TelegramNotifications\\Messages\\TelegramMessage;\n\nclass TelegramNotification extends Notification\n{\n    use Queueable;\n\n    public function via()\n    {\n        return [TelegramChannel::class];\n    }\n\n    public function toTelegram()\n    {\n        // to set any required or optional field use\n        // setter, which name is field name in camelCase\n        return (new TelegramMessage())\n            -\u003etext('Hello, world!')\n            -\u003edisableNotification(true);\n    }\n}\n```\n\nYou can also pass parameters to the constructor, to be more explicit:\n\n```php\n\u003c?php\n\nnew TelegramMessage([\n    'text' =\u003e 'Hello, world!',\n    'disable_notification' =\u003e true\n]);\n```\n\nAvailable message types are listed below.\n\n\n#### TelegramMessage\n\n`TelegramNotifications\\Messages\\TelegramMessage`\n\nField | Type | Description | Required\n--- | --- | --- | ---\ntext | String | Text of the message to be sent | Yes\nparse_mode | String | Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or [HTML](https://core.telegram.org/bots/api#html-style), if you want Telegram apps to show [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message | Optional\ndisable_web_page_preview | Boolean | Disables link previews for links in this message | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramPhoto\n\n`TelegramNotifications\\Messages\\TelegramPhoto`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nphoto | String | Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a photo from the Internet. [More about sending files](https://core.telegram.org/bots/api#sending-files) | Yes\ncaption | String | Photo caption, 0-200 characters | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramAudio\n\n`TelegramNotifications\\Messages\\TelegramAudio`\n\nField | Type | Description | Required\n--- | --- | --- | ---\naudio | String | Audio file to send. Pass a file_id as String to send a photo that exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a photo from the Internet. [More about sending files](https://core.telegram.org/bots/api#sending-files) | Yes\ncaption | String | Audio caption, 0-200 characters | Optional\nduration | Integer | Duration of the audio in seconds | Optional\nperformer | String | Performer | Optional\ntitle | String | Track name | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramDocument\n\n`TelegramNotifications\\Messages\\TelegramDocument`\n\nField | Type | Description | Required\n--- | --- | --- | ---\ndocument | String | File to send. Pass a file_id as String to send a photo that exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a photo from the Internet. [More about sending files](https://core.telegram.org/bots/api#sending-files) | Yes\ncaption | String | Document caption, 0-200 characters | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramSticker\n\n`TelegramNotifications\\Messages\\TelegramSticker`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nsticker | String | Sticker to send. Pass a file_id as String to send a photo that exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a photo from the Internet. [More about sending files](https://core.telegram.org/bots/api#sending-files) | Yes\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramVideo\n\n`TelegramNotifications\\Messages\\TelegramVideo`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nvideo | String | Video to send. Pass a file_id as String to send a photo that exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a photo from the Internet. [More about sending files](https://core.telegram.org/bots/api#sending-files) | Yes\nduration | Integer | Duration of sent video in seconds | Optional\nwidth | Integer | Video width | Optional\nheight | Integer | Video height | Optional\ncaption | String | Video caption, 0-200 characters | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramVoice\n\n`TelegramNotifications\\Messages\\TelegramVoice`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nvoice | String | Audio file to send. Pass a file_id as String to send a photo that exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a photo from the Internet. [More about sending files](https://core.telegram.org/bots/api#sending-files) | Yes\ncaption | String | Voice message caption, 0-200 characters | Optional\nduration | Integer | Duration of the voice message in seconds | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramLocation\n\n`TelegramNotifications\\Messages\\TelegramLocation`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nlatitude | Float number | Latitude of location | Yes\nlongitude | Float number | Longitude of location | Yes\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramVenue\n\n`TelegramNotifications\\Messages\\TelegramVenue`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nlatitude | Float number | Latitude of the venue | Yes\nlongitude | Float number | Longitude of the venue | Yes\ntitle | String | Name of the venue | Yes\naddress | String | Address of the venue | Yes\nfoursquare_id | String | Foursquare identifier of the venue | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n#### TelegramContact\n\n`TelegramNotifications\\Messages\\TelegramContact`\n\nField | Type | Description | Required\n--- | --- | --- | ---\nphone_number | String | Contact's phone number | Yes\nfirst_name | String | Contact's first name | Yes\nlast_name | String | Contact's last name | Optional\ndisable_notification | Boolean | Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound | Optional\n\n### Message Collection\n\nInstead of sending one message at once you can send bunch of messages using `TelegramCollection`:\n\n```php\n\u003c?php\n\nnamespace App\\Notifications;\n\nuse Illuminate\\Bus\\Queueable;\nuse Illuminate\\Notifications\\Notification;\n\nuse TelegramNotifications\\TelegramChannel;\nuse TelegramNotifications\\Messages\\TelegramCollection;\n\nclass TelegramNotification extends Notification\n{\n    use Queueable;\n\n    public function via()\n    {\n        return [TelegramChannel::class];\n    }\n\n    public function toTelegram()\n    {\n        return (new TelegramCollection())\n            -\u003emessage(['text' =\u003e 'Hello, world!'])\n            -\u003elocation(['latitude' =\u003e 55.755768, 'longitude' =\u003e 37.617671])\n            // ...\n            -\u003esticker(['sticker' =\u003e 'CAADBQADJwEAAl7ylwK4Q0M5P7UxhQI']);\n    }\n}\n```\n\nEach method of the collection creates corresponding message instance and puts it in the collection.\nAvailable methods are listed below:\n\nMethod | Corresponding entity\n--- | ---\nmessage | [TelegramMessage](#telegrammessage)\nphoto | [TelegramPhoto](#telegramphoto)\naudio | [TelegramAudio](#telegramaudio)\ndocument | [TelegramDocument](#telegramdocument)\nsticker | [TelegramSticker](#telegramsticker)\nvideo | [TelegramVideo](#telegramvideo)\nvoice | [TelegramVoice](#telegramvoice)\nlocation | [TelegramLocation](#telegramlocation)\nvenue | [TelegramVenue](#telegramvenue)\ncontact | [TelegramContact](#telegramcontact)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabenkoivan%2Ftelegram-notifications","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabenkoivan%2Ftelegram-notifications","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabenkoivan%2Ftelegram-notifications/lists"}