2017 © Pedro Peláez
 

library telegram-bot-api

Lightweight PHP7 client for a Telegram Bot API

image

tigris/telegram-bot-api

Lightweight PHP7 client for a Telegram Bot API

  • Thursday, July 27, 2017
  • by lagman
  • Repository
  • 1 Watchers
  • 1 Stars
  • 85 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

Tigris: Telegram Bot API Client

Build Status Join the chat at https://gitter.im/tigris-php/tigris GitHub license, (*1)

Lightweight PHP7 client for a Telegram Bot API, (*2)

Overview

Current API version: 3.2, (*3)

Requirements: * PHP 7 * Guzzle 6, (*4)

Installation

Composer

The preferred way to install this extension is through Composer., (*5)

Either run, (*6)

php composer.phar require tigris/telegram-bot-api

or add, (*7)

"tigris/telegram-bot-api": "*"

to the require section of your composer.json, (*8)

Usage

Getting started

First you need to create api client instance, (*9)

$httpClient = new \GuzzleHttp\Client();
$apiClient = new \Tigris\Telegram\ApiClient($httpClient);
$apiClient->setApiToken('CHANGEME');

Create api wrapper instance, (*10)

$apiWrapper = new \Tigris\Telegram\ApiWrapper($apiClient);

Use api wrapper methods mapped directly to the Telegram Bot API, (*11)

$apiWrapper->sendChatAction([
    'chat_id' => 123,
    'action' => \Tigris\Telegram\Helpers\ChatAction::TYPING,
]);
$apiWrapper->sendMessage([
    'chat_id' => 123
    'text' => 'Hello, World!',
    'parse_mode' => \Tigris\Telegram\Helpers\ParseMode::HTML,
]);                        

Type mapping

Please note that every method call response call is being parsed into the corresponding type. We offer PHP classes for all of the API objects. For example, sendMessage() call would return an instance of \Tigris\Telegram\Types\Message objects. Objects, arrays, nested arrays, scalar values are fully supported by the type parser., (*12)

Getting updates

// Get array of the \Tigris\Telegram\Types\Updates\Update
$updates = $apiWrapper->getUpdates([
    'offset' => $this->offset,
]);

// Process received updates
foreach ($updates as $update) {
    $this->offset = $update->update_id + 1;
    $this->setLastOffset($this->offset);
    $this->processUpdate($update);
}                     

Handling errors

By default every mapped method returns null value if an error occurs. You can change this behavior by adding callable error handler to your ApiWrapper instance., (*13)

$apiWrapper->setErrorHandler(function (\Exception $e) use ($logger) {
    $logger->log($e);         
});

Going further

Please feel free to investigate the source code. All the api methods and types are fully documented. Please contact us in the gitter chat channel: https://gitter.im/tigris-php/tigris, (*14)

License

MIT, (*15)

The Versions

27/07 2017

dev-master

9999999-dev

Lightweight PHP7 client for a Telegram Bot API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bot client telegram

27/07 2017

3.2.4

3.2.4.0

Lightweight PHP7 client for a Telegram Bot API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bot client telegram

26/07 2017

3.2.3

3.2.3.0

Lightweight PHP7 client for a Telegram Bot API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bot client telegram

26/07 2017

3.2.2

3.2.2.0

Lightweight PHP7 client for a Telegram Bot API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bot client telegram

26/07 2017

3.2.1

3.2.1.0

Lightweight PHP7 client for a Telegram Bot API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bot client telegram

25/07 2017

3.2

3.2.0.0

Lightweight PHP7 client for a Telegram Bot API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bot client telegram