2017 © Pedro Peláez
 

library telegram

image

tje3d/telegram

  • Sunday, January 7, 2018
  • by tje3d
  • Repository
  • 1 Watchers
  • 4 Stars
  • 91 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Telegram Bot API

PHP Telegram Bot API, Supports Laravel., (*1)

Installation

composer require tje3d/telegram, (*2)

Laravel Only

Service Provider

Tje3d\Telegram\Laravel\TelegramServiceProvider::class, (*3)

Facade

'Bot' => Tje3d\Telegram\Laravel\Facades\Bot::class, (*4)

Publish Assets

artisan vendor:publish --tag=telegram, (*5)

Will make a config file named telegram (config/telegram.php), (*6)

Examples

✔️ Initialize a Bot

$bot = new \Tje3d\Telegram\Bot($token);
$info = $bot->getMe();
print_r($info);

✔️ Set Web Hook

$bot->setWebhook('https://sld.tld');

✔️ Get Updates

$response = $bot->getUpdates();
...
$response = $bot->getUpdates($offset=0, $limit=100, $timeout=10); // Long pull

✔️ Send text message (known as sendMessage)

$bot->sendMethod(
    (new \Tje3d\Telegram\Methods\Text())
        ->text('test')
        ->chat_id($chatId)
);

⭐️ Or pass configuration as array

$bot->sendMethod(
    (new Tje3d\Telegram\Methods\Text(['text' => 'hi', 'chat_id' => $chatId]))
);

✔️ Keyboard

⭐️ Reply Keyboard

$bot->sendMethod(
    (new Tje3d\Telegram\Methods\Text)
        ->text('My Sample Text')
        ->chat_id($chatId)
        ->reply_markup(
            (new Tje3d\Telegram\Markups\ReplayKeyboardMarkup)
                ->row(function($handler){
                    $handler->addButton(['text' => 'btn1']);
                    $handler->addButton(['text' => 'my special button ⭐️']);
                })
                ->row(function($handler){
                    $handler->addButton(['text' => 'WOW']);
                })
                ->row(function($handler){
                    $handler->addButton(['text' => 'Hey this is third line!']);
                })
                ->row(function($handler){
                    $handler->addButton(['text' => '1']);
                    $handler->addButton(['text' => '2']);
                    $handler->addButton(['text' => '3']);
                    $handler->addButton(['text' => '4']);
                })
        )
);

image, (*7)

⭐️ Inline Keyboard

$bot->sendMethod(
    (new Tje3d\Telegram\Methods\Text)
        ->text('My Sample Text')
        ->chat_id($testChatId)
        ->reply_markup(
            (new Tje3d\Telegram\Markups\InlineKeyboardMarkup)
                ->row(function($handler){
                    $handler->addButton(['text' => 'btn1', 'url' => 'http://sld.tld']);
                    $handler->addButton(['text' => 'my special button ⭐️', 'url' => 'http://sld.tld']);
                })
                ->row(function($handler){
                    $handler->addButton(['text' => 'WOW', 'callback_data' => 'doSomethingSpecial']);
                })
        )
);

image, (*8)

✔️ Photo, Audio, Video, Document ...

$bot->sendMethod(
    (new \Tje3d\Telegram\Methods\Photo)
        ->chat_id($chatId)
        ->photo(realpath('pic.png'))
);

...

$bot->sendMethod(
    (new \Tje3d\Telegram\Methods\Video)
        ->chat_id($chatId)
        ->video(realpath('video.mp4'))
        ->duration(10) // optional
        ->width(320) // optional
        ->height(320) // optional
);

...

$bot->sendMethod(
    (new \Tje3d\Telegram\Methods\Audio)
        ->chat_id($chatId)
        ->audio(realpath('video.mp3'))
        ->duration(30) // optional
        ->performer('tje3d') // optional
        ->title('Great music') // optional
);
...

✔️ ChatAction

$bot->sendMethod(
    (new \Tje3d\Telegram\Methods\ChatAction)
        ->chat_id($testChatId)
        ->typing() // Could be: upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location
);

Exceptions

Throw's Tje3d\Telegram\Exceptions\TelegramResponseException if sendMethod failed., (*9)

try {
    $bot = new \Tje3d\Telegram\Bot($token);
    $response = $bot->sendMethod(
        (new \Tje3d\Telegram\Methods\Text())
            ->text($text)
            ->chat_id($chatId)
    );
} catch (TelegramResponseException $e) {
    print_r($e->response());
}

Contact me

You can contact me via Telegram or Email., (*10)

The Versions

07/01 2018

dev-stable

dev-stable

  Sources   Download

MIT

The Requires

 

by Avatar moein

06/05 2017

1.3.1

1.3.1.0

  Sources   Download

MIT

The Requires

 

by Avatar moein

06/05 2017

1.3.0

1.3.0.0

  Sources   Download

MIT

The Requires

 

by Avatar moein

20/04 2017

1.2.0

1.2.0.0

  Sources   Download

MIT

The Requires

 

by Avatar moein

14/04 2017

1.1.2

1.1.2.0

  Sources   Download

MIT

The Requires

 

by Avatar moein

10/03 2017

dev-master

9999999-dev

  Sources   Download

The Requires

 

by Avatar moein