Code Monkey home page Code Monkey logo

laravel-telegram's Introduction

install:

composer require icekristal/laravel-telegram

migration:

php artisan vendor:publish --provider="Icekristal\LaravelTelegram\TelegramServiceProvider" --tag="migrations"

config:

php artisan vendor:publish --provider="Icekristal\LaravelTelegram\TelegramServiceProvider" --tag="config"

default handle:

php artisan vendor:publish --provider="Icekristal\LaravelTelegram\TelegramServiceProvider" --tag="translations"

lang:

php artisan vendor:publish --provider="Icekristal\LaravelTelegram\TelegramServiceProvider" --tag="ice_telegram_default_handlers"

use:

use Icekristal\LaravelTelegram\InteractsTelegramService;

class User extends Model
{
    use InteractsTelegramService;
}

$modelUser->telegram->chat_id;

send message, if chat telegram have owner

$modelUser->sendTelegramMessage('text message');

in config:

'method_messages' => [
    'text' => App\Services\DefaultBotTelegramHandle\TextTelegramHandle::class,
],

example handle text:

class TextTelegramHandle extends MainTelegramHandle
{
    public function __construct($data, $botInfo)
    {
        parent::__construct($data, $botInfo);
        $text = $data['text'] ?? '';
        if (Str::startsWith($text, '/start')) {
            $this->returnTextStart();
        } elseif (Str::startsWith($text, '/menu')) {
            $this->returnMenu();
        }  else {
            $this->parseOtherText();
        }
        
        $this->onlyMessage = "send only message";
        $this->message = "send message";
        $this->keyboard = [
            "inline_keyboard" => [
                [
                    ["text" => __('text_line_1') . " ✌️", "callback_data" => "callback_line_1"],
                ],
                [
                    ["text" => __('text_line_2') . " ✌️", "callback_data" => "callback_line_2"],
                ]
            ]
        ];
        $this->image = "URL image";
        $this->file = "URL file";
    }
}

class MainTelegramHandle
{

    public $onlyMessage = null;
    public $message = null;
    public $keyboard = null;
    public $image = null;
    public $file = null;

    public function __construct($data, $botInfo)
    {

    }

    public function getResult(): array
    {
        return [
            'only_message' => $this->onlyMessage,
            'callback_message' => $this->messageCallback,
            'message' => $this->message,
            'keyboard' => $this->keyboard,
            'image' => $this->image,
            'file' => $this->file,
            'show_alert' => $this->showAlert,
            'cache_time' => $this->cacheTime,
            'url' => $this->url,
        ];
    }
}

v3 >
Notification

    public function via($notifiable): array
    {
        return [\Icekristal\LaravelTelegram\Channels\TelegramChannel::class];
    }

    public function toTelegram($notifiable): TelegramMessage
    {
        return (new \Icekristal\LaravelTelegram\Channels\Messages\TelegramMessage())->content("Text");
    }

Facade Telegram:

IceTelegram::setInfoBot(array $infoBot);
IceTelegram::setChatId(mixed $chatId);
IceTelegram::setParams(array $params);
IceTelegram::setOwner(array $owner);
IceTelegram::sendMessage();
IceTelegram::deleteMessage();
IceTelegram::sendCallback();
IceTelegram::sendPhoto();
IceTelegram::sendDocument();
IceTelegram::sendLocation();
IceTelegram::sendQR();

v5.1 >

set config param:
 'main_telegram_server_url' => env('TELEGRAM_SERVER_URL', 'https://api.telegram.org'),

laravel-telegram's People

Contributors

icekristal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.