2017 © Pedro Peláez
 

library telegram-api

A complete Telegram bot API implementation written in PHP, with support for inline bots!

image

unreal4u/telegram-api

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  • Thursday, July 26, 2018
  • by unreal4u
  • Repository
  • 42 Watchers
  • 346 Stars
  • 16,813 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 82 Forks
  • 2 Open issues
  • 60 Versions
  • 15 % Grown

The README.md

PHP 7 Telegram Bot API Library, (*1)

Telegram API Library

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage License, (*2)

This is a PHP7 bot API implementation for Telegram implementing the vast majority of Bot API up until v4.7. The only thing it does not implement is Telegram Passport which was introduced in Bot API v4.0. It is unlikely to be introduced as it may introduce security vulnerabilities. However, if you think you have a strong case for the need, feel free to let me know., (*3)

About this package

  • Enables you to anything supported by the Telegram Bot API: messages, stickers, location, inline bots and any other supported method via PHP to a Telegram user (either direct conversation, channel, group or supergroup).
  • Respects and implements the default types and methods made by Telegram itself. Have any doubts about any method? Just check the original documentation, this implementation will not differ too much.
  • Doesn't need any mandatory dependencies, except for ReactPHP, which you can inject if you already use it elsewhere.
  • Full inline bots support.
  • Full support for payment system.

Known bugs

Telegram, (*4)

The only thing that is not included in this library (yet) is the Passport support. This was an ongoing development, but it ended up being a lot more work than initially thought, so if someone wants to pick that up... be my guest!, (*5)

All other known bugs can be found in the form of issues or pull requests. Found a new bug? Feel free to submit a PR or create an issue! Not sure if you've found a new bug? You can always ask in the special group :), (*6)

Roadmap

  • v4 (no branch yet) will be the next major release. More information.
  • v3 (master branch) is the current active branch.
  • v2 (v2 branch) is deprecated and no new work will be done there.
  • v1 is deprecated and no new work will be done there.
  • v0 is deprecated and no new work will be done there.

Installation

Total Downloads, (*7)

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Read this for installation instructions.
The preferred (and only for now) installation method is Composer, so add the following to your composer.json:, (*8)

{
  "require": {
    "unreal4u/telegram-api": "~3.4"
  }
}

If you are not familiar with it, I suggest reading the basic usage manual located here., (*9)

Tip for Russian users

In order to use a proxy, you can use the https://github.com/clue/php-socks-react package and pass on the following options to the Client:, (*10)

<?php

use Clue\React\Socks\Client;

$loop = Factory::create();
// Replace PROXY_ADDRESS and PROXY_PORT with the correct configuration
$proxy = new Client('socks5://' . PROXY_ADDRESS . ':' . PROXY_PORT, new Connector($loop));
$handler = new HttpClientRequestHandler($loop, [
    'tcp' => $proxy,
    'timeout' => 3.0,
    'dns' => false
]);

$this->tgLog = new TgLog(BOT_TOKEN, $handler);
// The rest is exactly the same as it normally is, see the examples folder for more information

With these simple steps, a proxy is configured in no time!, (*11)

Upgrading v2.x to v3

A lot of backwards incompatibility changes, but in a nutshell: * ReactPHP is the new Guzzle (Async requests!) * Changed parameter order when invoking the constructor of TgLog * Custom -Array types now implement IteratorAggregate (Solves #21 !), (*12)

Please check the following Wiki page if you have to upgrade from v2 to v3., (*13)

General usage

Basic usage example:

<?php

use \unreal4u\TelegramAPI\HttpClientRequestHandler;
use \unreal4u\TelegramAPI\TgLog;
use \unreal4u\TelegramAPI\Telegram\Methods\SendMessage;

$loop = \React\EventLoop\Factory::create();
$handler = new HttpClientRequestHandler($loop);
$tgLog = new TgLog(BOT_TOKEN, $handler);

$sendMessage = new SendMessage();
$sendMessage->chat_id = A_USER_CHAT_ID;
$sendMessage->text = 'Hello world!';

$tgLog->performApiRequest($sendMessage);
$loop->run();

(Side note: In case React\EventLoop\Factory cannot be resolved in the above code, add include('vendor/autoload.php') to your PHP file)., (*14)

With the SendMessage() object, you can create a message to be sent through the TgLog object.
All other functionality is based upon this behaviour, so every other method is very similar: you instantiate an object, pass that object to TelegramLog->performApiRequest(), which will return a Promise. If the method returns a reply, pass a callback to its onFulfilled parameter and you'll get the native Telegram response back as an object. Different methods return different object types., (*15)

Please refer to the examples directory to view examples of some of the implemented methods, including inline bots., (*16)

For examples of actual code that works in a production environment, please refer to my other repo: https://github.com/unreal4u/telegram-bots, (*17)

Getting updates via Webhook

Please check the following wiki section for more information on this., (*18)

Inline bots

Please checkout the special wiki page about inline bots., (*19)

Extra requirements

If you want to use this package, you'll need a bot API key. Check the following documentation for more instructions on that., (*20)

Getting everything started up

The most difficult thing to do when performing an action with the Telegram API is to get the chat_id, which is the actual conversation window the bot talks to. You can execute the GetUpdates() method in order to get this chatId. Note that there are some caveats on this, so you may be better out with the SetWebhook() method instead., (*21)

Development

Semver

I will try my best to respect Semantic Versioning.
That being said, the first stable release is v1.0.0, from there on no mayor BC changes will occur unless we update the major., (*22)

Want to colaborate?

Collaborations are very welcome! Check this Wiki page out for more information that will make the development easier!, (*23)

Contact the author

Telegram, (*24)

I actually don't use Telegram. Nah, kidding, I created a group where you can contact me at https://t.me/PHPBotAPI. Another great way to get in touch is to simply create an issue or a pull request!, (*25)

I would appreciate it if you could handle these responsibly. If you happen to find a security issue relating to this Telegram Bot API client, please ask me to contact you privately over here., (*26)

Special thanks to

The Versions

26/07 2018

v2.x-dev

2.9999999.9999999.9999999-dev

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

05/03 2018

v2.9.6

2.9.6.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

15/02 2018

v2.9.5

2.9.5.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

09/01 2018

v2.9.4

2.9.4.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

27/12 2017

v2.9.2

2.9.2.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

27/12 2017

v3.3.3

3.3.3.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

26/12 2017

v3.3.2

3.3.2.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

26/12 2017

v2.9.1

2.9.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

28/11 2017

v3.3.1

3.3.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

20/11 2017

v3.3.0

3.3.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

20/11 2017

v2.9.0

2.9.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

11/10 2017

v3.2.0

3.2.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

11/10 2017

v2.8.0

2.8.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

09/09 2017

v3.1.1

3.1.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

09/09 2017

v3.1.0

3.1.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

05/09 2017

v3.0.0

3.0.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

24/08 2017

v2.7.0

2.7.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

03/08 2017

v3.0.0-alpha

3.0.0.0-alpha

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

21/07 2017

v2.6.0

2.6.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

30/06 2017

v2.5.0

2.5.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

25/06 2017

v2.4.4

2.4.4.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

22/06 2017

v2.4.3

2.4.3.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

19/06 2017

v2.4.2

2.4.2.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

06/06 2017

v2.4.1

2.4.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

19/05 2017

dev-paymentsImplementation

dev-paymentsImplementation

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

19/05 2017

v2.4.0

2.4.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

23/02 2017

v2.3.1

2.3.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

08/01 2017

v2.3.0

2.3.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

08/01 2017

dev-gamingPlatform

dev-gamingPlatform

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

08/01 2017

v2.3.0-alpha

2.3.0.0-alpha

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

05/01 2017

v2.2.1

2.2.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

01/01 2017

v3.x-dev

3.9999999.9999999.9999999-dev

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

04/12 2016

v2.2.0

2.2.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

30/11 2016

dev-errorHandler

dev-errorHandler

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

29/11 2016

v2.1.1

2.1.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

21/11 2016

dev-BotAPI-v2.3

dev-BotAPI-v2.3

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

21/11 2016

v2.1.0

2.1.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

03/11 2016

v2.0.0

2.0.0.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

03/11 2016

v2.0.0-rc.1

2.0.0.0-RC1

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

21/07 2016

v2.0.0-alpha

2.0.0.0-alpha

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

20/07 2016

dev-api-bots-v2

dev-api-bots-v2

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

25/04 2016

v1.2.3

1.2.3.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

06/03 2016

v1.2.2

1.2.2.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

31/01 2016

v1.2.1

1.2.1.0

A complete Telegram bot API implementation written in PHP, with support for inline bots!

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

31/01 2016

dev-loggerIntegration

dev-loggerIntegration

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

31/01 2016

v1.2.0

1.2.0.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

26/01 2016

v1.1.1

1.1.1.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

24/01 2016

dev-inlineBots

dev-inlineBots

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

24/01 2016

v1.1.0

1.1.0.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

20/01 2016

v1.0.3

1.0.3.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

20/01 2016

v1.0.2

1.0.2.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

18/01 2016

v1.0.1

1.0.1.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

13/01 2016

v1.0.0

1.0.0.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

11/01 2016

v1.0.0-alpha

1.0.0.0-alpha

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

06/01 2016

v0.1.0

0.1.0.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot

06/01 2016

v0.0.6

0.0.6.0

Complete implementation used to communicate with the open-source Telegram API

  Sources   Download

MIT

The Requires

 

The Development Requires

api telegram telegram bot