2017 © Pedro Peláez
 

library telegrambotclient

Powerful client for Telegram Bot API

image

alxmsl/telegrambotclient

Powerful client for Telegram Bot API

  • Thursday, November 19, 2015
  • by alxmsl
  • Repository
  • 4 Watchers
  • 5 Stars
  • 44 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

TelegramBotClient

License Latest Stable Version Total Downloads, (*1)

Build Status Scrutinizer Code Quality Code Coverage Dependency Status, (*2)

Powerful client for Telegram Bot API, (*3)

Advantages

  1. Lightweight. You could use only two classes for work: API client and response
  2. Powerful. Same time you could use all 16 Bot API types and all 13 Bot API methods
  3. composer support makes installation simplified
  4. Independent namespace helps to use Bot API client on different projects and frameworks
  5. CLI utility helps you to test Bot API interactions

Installation

For simplified usage all what you need is require packet via composer, (*4)

    $ composer require alxmsl/telegrambotclient

In third-party projects, require packet in your composer.json, (*5)

    "alxmsl/telegrambotclient": "*"

...and update composer: composer update, (*6)

Usages

First what you need is client instance. Just create it, (*7)

    use alxmsl\Telegram\Bot\Client;
    $Client = new Client('123456789:Y0uR5EcREtT0KEn');

....then you could call bot methods directly and got API response string, (*8)

    $result = $Client->call(<method name>, <call parameters>);
    printf("%s\n", $result);

...or use methods wrappers, (*9)

    $updates = $Client->getUpdates(0, 1);
    var_dump($updates);

Method wrappers helps you to return specific result types as described in API documentation. For example, using getUpdates you be returned array of Update instances, sendMessage wrapper returns you Message object etc., (*10)

    use alxmsl\Telegram\Bot\Client;
    use alxmsl\Telegram\Bot\Type\Message;

    $Client  = new Client('123456789:Y0uR5EcREtT0KEn');
    $Message = $Client->sendMessage(34567, 'hello');
    ($Message instanceof Message); // that's TRUE 

When something wrong, wrapper throws UnsuccessfulException. For example code, (*11)

    $Client = new Client('123456789:Br0KEnT0kEN');
    try {
        $Message = $Client->getMe();
    } catch (UnsuccessfulException $Ex) {
        printf("%s\n%s", $Ex->getCode(), $Ex->getMessage());
    }

is showed you, (*12)

401
Error: Unauthorized

Console usage

You could use script call.php to call Telegram Bot API directly, (*13)

    $ php bin/call.php -h
    Using: /usr/local/bin/php bin/call.php [-h|--help] -m|--method [-p|--parameters] -t|--token
    -h, --help  - show help
    -m, --method  - bot method name
    -p, --parameters  - method calls parameters
    -t, --token  - authentication token

Using utility you could test your bot's authentication token, (*14)

    $ php bin/call.php -t='123456789:Y0uR5EcREtT0KEn' -m='getMe' 
    {"ok":true,"result":{"id":123456789,"first_name":"alxmslClientBot","username":"alxmslClientBot"}}

When something wrong^ utility will show you error response from Bot API, (*15)

    $ php bin/call.php -t='123456789:Br0KEnT0kEN' -m='getMe' 
    {"ok":false,"error_code":401,"description":"Error: Unauthorized"}

... got updates etc., (*16)

    $ php bin/call.php -t='123456789:Y0uR5EcREtT0KEn' -m='getUpdates' -p='{"limit":1}' 
    {"ok":true,"result":[{"update_id":7654321,"message":{"message_id":2,"from":{"id":34567,"first_name":"Alexey","last_name":"Maslov"},"chat":{"id":34567,"first_name":"Alexey","last_name":"Maslov"},"date":1435870467,"text":"\/start"}}]}

Tests

For completely tests running just call phpunit command, (*17)

    $ phpunit
    PHPUnit 4.7.5 by Sebastian Bergmann and contributors.

    Runtime:    PHP 5.5.23

    ................

    Time: 190 ms, Memory: 9.00Mb

    OK (16 tests, 784 assertions)

License

Copyright 2015 Alexey Maslov alexey.y.maslov@gmail.com, (*18)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at, (*19)

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License., (*20)

The Versions

19/11 2015

dev-master

9999999-dev

Powerful client for Telegram Bot API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

api bot telegram bot api

19/11 2015

v1.0.4

1.0.4.0

Powerful client for Telegram Bot API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

api bot telegram bot api

12/07 2015

v1.0.3

1.0.3.0

Powerful client for Telegram Bot API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

api bot telegram bot api

09/07 2015

v1.0.2

1.0.2.0

Powerful client for Telegram Bot API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

api bot telegram bot api

07/07 2015

v1.0.1

1.0.1.0

Powerful client for Telegram Bot API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

api bot telegram bot api

07/07 2015

v1.0.0

1.0.0.0

Powerful client for Telegram Bot API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Avatar alxmsl

api bot telegram bot api