All Projects → westacks → telebot

westacks / telebot

Licence: MIT license
Easy way to create Telegram bots in PHP. Rich Laravel support out of the box.

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects

Projects that are alternatives of or similar to telebot

Telegram-Support-Bot
📬 Manage and organize all your support inquiries on Telegram.
Stars: ✭ 63 (-70.97%)
Mutual labels:  telebot
laravel-firebase
Laravel FCM (Firebase Cloud Messaging) Notification Channel
Stars: ✭ 25 (-88.48%)
Mutual labels:  notification-channel

Project Logo

Latest Stable Version Bot API Version Total Downloads License

TeleBot is a PHP library for telegram bots development. Rich Laravel support out of the box. Has an easy, clean, and extendable way to handle telegram Updates.

Documentation

Documentation for the library can be found on the website.

Features

Bot Manager

Work easily with multiple bots using BotManager:

$manager->getMe(); // Fired by default bot specified in BotManager
$manager->bot('bot2')->getMe(); // Fired by `bot2` specified in BotManager

Object oriented and functional handlers

// Functional handler
$handler = function(TeleBot $bot, Update $update, $next) {
    if ($update->message->text === '/start') {
        return $bot->sendMessage([
            'chat_id' => $update->chat()->id,
            'text' => 'Hello, World!'
        ]);
    }

    return $next();
};


// Object oriented handler
class YourUpdateHandler extends CommandHandler
{
    protected static $aliases = ['/start'];
    protected static $description = 'Your description';

    public function handle()
    {
        return $this->sendMessage([
            'text' => 'Hello, World!'
        ]);
    }
}

Laravel Support

Library provides a Facade, artisan commands and notification channel to simplify the development process of your bot, if you are using Laravel:

Facade
TeleBot::getMe();
TeleBot::bot('bot2')->getMe();
Automatic webhook generation

After you insert your bot token, to create a webhook you need only to fire the following command:

$ php artisan telebot:webhook --setup

Route for handling updates is generated automatically for your APP_URL

Long polling

If you are not using webhook, or want to use bot in local or test environment, you may start long polling by only firyng this command:

$ php artisan telebot:polling
Setup commands autocompletion

The following command will automatically setup autocompletion for all registered bot commands on Telegram servers:

$ php artisan telebot:commands --setup
Notification channel
<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use WeStacks\TeleBot\Laravel\TelegramNotification;

class TelegramNotification extends Notification
{
    public function via($notifiable)
    {
        return ['telegram'];
    }

    public function toTelegram($notifiable)
    {
        return (new TelegramNotification)->bot('bot')
            ->sendMessage([
                'chat_id' => $notifiable->telegram_chat_id,
                'text'    => 'Hello, from Laravel\'s notifications!'
            ])
            ->sendMessage([
                'chat_id' => $notifiable->telegram_chat_id,
                'text'    => 'Second message'
            ]);
    }
}
Log driver

You may log your application errors by sending them to some Telegram chat. Simply add new log driver to a config/logging.php:

'telegram' => [
    'driver'    => 'custom',
    'via'       => \WeStacks\TeleBot\Laravel\Log\TelegramLogger::class,
    'level'     => 'debug',
    'bot'       => 'bot',
    'chat_id'   => env('TELEGRAM_LOG_CHAT_ID') // Any chat where bot can write messages.
]

Changelog

Please see CHANGELOG for more information what has changed recently.

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