laravel-notification-channels / Telegram

Licence: mit
✈️ Telegram Notifications Channel for Laravel

Projects that are alternatives of or similar to Telegram

Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+391.56%)
Mutual labels:  telegram-bot, laravel, laravel-package, laravel-5-package, telegram
Laravel Gamp
📊 Laravel Google Analytics Measurement Protocol Package
Stars: ✭ 271 (-39.78%)
Mutual labels:  hacktoberfest, laravel, laravel-package, laravel-5-package
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+58.22%)
Mutual labels:  hacktoberfest, laravel, laravel-package, laravel-5-package
Groupbutler
This bot can help you in managing your group with rules, anti-flood, description, custom triggers, and much more!
Stars: ✭ 399 (-11.33%)
Mutual labels:  telegram-bot, hacktoberfest, telegram
Core
PHP Telegram Bot based on the official Telegram Bot API
Stars: ✭ 2,899 (+544.22%)
Mutual labels:  bot-api, telegram-bot, telegram
Laravel Achievements
Achievements for Laravel 5.3+
Stars: ✭ 279 (-38%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Telegram Api
Complete async capable Telegram bot API implementation for PHP7
Stars: ✭ 650 (+44.44%)
Mutual labels:  bot-api, telegram-bot, telegram
Trashemail
A hosted disposable email telegram bot; Extremely privacy friendly; Proudly hosted for community.
Stars: ✭ 408 (-9.33%)
Mutual labels:  telegram-bot, hacktoberfest, telegram
Administrator
a fork from Frozennode/Administrator
Stars: ✭ 296 (-34.22%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Pytelegrambotapi
Python Telegram bot api.
Stars: ✭ 4,986 (+1008%)
Mutual labels:  bot-api, telegram-bot, telegram
Generator
Laravel 5.3+ Scaffold Generator, Support both bootstrap and Semantic UI
Stars: ✭ 327 (-27.33%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Mattata
A powerful, plugin-based, multi-purpose Telegram bot designed to serve a wide variety of purposes
Stars: ✭ 107 (-76.22%)
Mutual labels:  bot-api, telegram-bot, telegram
Botogram
Just focus on your bots.
Stars: ✭ 106 (-76.44%)
Mutual labels:  bot-api, hacktoberfest, telegram
Mypackbot
🤖 Your own unlimited pack of Telegram-stickers
Stars: ✭ 18 (-96%)
Mutual labels:  bot-api, telegram-bot, telegram
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (-29.11%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Validator Docs
Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.
Stars: ✭ 334 (-25.78%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravel Starter
A CMS like modular starter application project built with Laravel 8.x.
Stars: ✭ 299 (-33.56%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Bagisto
An easy to use, free and open source laravel eCommerce platform to build your online shop in no time.
Stars: ✭ 4,140 (+820%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Tlg joincaptchabot
Telegram Bot to verify if users that join a group, are humans. The Bot send an image captcha for each new user, and kick any of them that can't solve the captcha in a specified time.
Stars: ✭ 226 (-49.78%)
Mutual labels:  telegram-bot, hacktoberfest, telegram
Telegraf
Modern Telegram Bot Framework for Node.js
Stars: ✭ 5,178 (+1050.67%)
Mutual labels:  bot-api, telegram-bot, telegram

Telegram Notifications Channel for Laravel

Join PHP Chat Chat on Telegram Latest Version on Packagist Software License SensioLabsInsight Quality Score 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:

composer require laravel-notification-channels/telegram

Setting up your Telegram Bot

Talk to @BotFather and generate a Bot API Token.

Then, configure your Telegram Bot API Token:

// config/services.php
'telegram-bot-api' => [
    'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
],

(Optional) 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.

Usage

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

Text Notification

use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use Illuminate\Notifications\Notification;

class InvoicePaid extends Notification
{
    public function via($notifiable)
    {
        return [TelegramChannel::class];
    }

    public function toTelegram($notifiable)
    {
        $url = url('/invoice/' . $this->invoice->id);

        return TelegramMessage::create()
            // Optional recipient user id.
            ->to($notifiable->telegram_user_id)
            // Markdown supported.
            ->content("Hello there!\nYour invoice has been *PAID*")
            
            // (Optional) Blade template for the content.
            // ->view('notification', ['url' => $url])
            
            // (Optional) Inline Buttons
            ->button('View Invoice', $url)
            ->button('Download Invoice', $url);
    }
}

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

Laravel Telegram Notification Example

Attach a Photo

public function toTelegram($notifiable)
{
    return TelegramFile::create()
        ->to($notifiable->telegram_user_id) // Optional
        ->content('Awesome *bold* text and [inline URL](http://www.example.com/)')
        ->file('/storage/archive/6029014.jpg', 'photo'); // local photo

        // OR using a helper method with or without a remote file.
        // ->photo('https://file-examples-com.github.io/uploads/2017/10/file_example_JPG_1MB.jpg');
}

Preview:

Laravel Telegram Photo Notification Example

Attach a Document

public function toTelegram($notifiable)
{
    return TelegramFile::create()
        ->to($notifiable->telegram_user_id) // Optional
        ->content('Did you know we can set a custom filename too?')
        ->document('https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf', 'sample.pdf');
}

Preview:

Laravel Telegram Document Notification Example

Attach a Location

public function toTelegram($notifiable)
{
    return TelegramLocation::create()
        ->latitude('40.6892494')
        ->longitude('-74.0466891');
}

Preview:

Laravel Telegram Location Notification Example

Attach a Video

public function toTelegram($notifiable)
{
    return TelegramFile::create()
        ->content('Sample *video* notification!')
        ->video('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4');
}

Preview:

Laravel Telegram Video Notification Example

Attach a GIF File

public function toTelegram($notifiable)
{
    return TelegramFile::create()
        ->content('Woot! We can send animated gif notifications too!')
        ->animation('https://sample-videos.com/gif/2.gif');

        // Or local file
        // ->animation('/path/to/some/animated.gif');
}

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:

/**
 * Route notifications for the Telegram channel.
 *
 * @return int
 */
public function routeNotificationForTelegram()
{
    return $this->telegram_user_id;
}

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.

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.

use NotificationChannels\Telegram\TelegramChannel;

Notification::route('telegram', 'TELEGRAM_CHAT_ID')
            ->notify(new InvoicePaid($invoice));

Available Message methods

  • to($chatId): (integer) Recipient's chat id.
  • token($token): (string) Bot token if you wish to override the default token for a specific notification (optional).
  • content(''): (string) Notification message, supports markdown. For more information on supported markdown styles, check out these docs.
  • view($view, $data = [], $mergeData = []): (string) Blade template name with Telegram supported HTML or Markdown syntax content if you wish to use a view file instead of the content() method.
  • button($text, $url): (string) Adds an inline "Call to Action" button. You can add as many as you want, and they'll be placed 2 in a row.
  • disableNotification($disableNotification = true): (bool) Send the message silently. Users will receive a notification with no sound.
  • options([]): (array) Allows you to add additional or override sendMessage payload (A Telegram Bot API method used to send message internally). For more information on supported parameters, check out these docs.

Available Location methods

  • to($chatId): (integer) Recipient's chat id.
  • token($token): (string) Bot token if you wish to override the default token for a specific notification (optional).
  • latitude($latitude): (float|string) Latitude of the location.
  • longitude($longitude): (float|string) Longitude of the location.
  • button($text, $url): (string) Adds an inline "Call to Action" button. You can add as many as you want, and they'll be placed 2 in a row.
  • disableNotification($disableNotification = true): (bool) Send the message silently. Users will receive a notification with no sound.
  • options([]): (array) Allows you to add additional or override the payload.

Available File methods

  • to($chatId): (integer) Recipient's chat id.
  • token($token): (string) Bot token if you wish to override the default token for a specific notification (optional).
  • content(''): (string) File caption, supports markdown. For more information on supported markdown styles, check out these docs.
  • view($view, $data = [], $mergeData = []): (string) Blade template name with Telegram supported HTML or Markdown syntax content if you wish to use a view file instead of the content() method.
  • file($file, $type, $filename = null): Local file path or remote URL, $type of the file (Ex:photo, audio, document, video, animation, voice, video_note_) and optionally filename with extension. Ex: sample.pdf. You can use helper methods instead of using this to make it easier to work with file attachment.
  • photo($file): Helper method to attach a photo.
  • audio($file): Helper method to attach an audio file (MP3 file).
  • document($file, $filename = null): Helper method to attach a document or any file as document.
  • video($file): Helper method to attach a video file.
  • animation($file): Helper method to attach an animated gif file.
  • voice($file): Helper method to attach a voice note (.ogg file with OPUS encoded).
  • videoNote($file): Helper method to attach a video note file (Upto 1 min long, rounded square video).
  • button($text, $url): (string) Adds an inline "Call to Action" button. You can add as many as you want, and they'll be placed 2 in a row.
  • disableNotification($disableNotification = true): (bool) Send the message silently. Users will receive a notification with no sound.
  • options([]): (array) Allows you to add additional or override the payload.

Alternatives

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

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].