saelozahra / telegram-api

Complete Telegram bot API implementation for PHP7

Home Page:https://github.com/unreal4u/telegram-api/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

Telegram API

This is a complete PHP7 bot API implementation for Telegram implementing the totality of Bot API v2.3.1

Known bugs / Open issues

None at the moment. If you find any, feel free to submit a PR or create an issue!

About this class

  • 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 dependency, except for Guzzle, which you can inyect if you already use it elsewhere.
  • Full inline bots support!

Installation

The preferred method is composer, so add the following to your composer.json:

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

Upgrading v1.x to v2

Please check the following Wiki page if you have to upgrade from v1 to v2.

General usage

Basic usage example:

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

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

$tgLog = new TgLog(BOT_TOKEN);
$message = $tgLog->performApiRequest($sendMessage);

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() and you'll get the native Telegram response back as an object. Different methods return different object types.

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

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

Getting updates via Webhook

Please check the following wiki section for more information on this.

Inline bots

Please checkout the special wiki page about inline bots.

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.

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.

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.

Want to colaborate?

Colaborations are very welcome! Check this Wiki page out for more information that will make the development easier!

Contact the author

I actually don't use Telegram. Nah, kidding, you can contact me at t.me/unreal4u. Another great way to help is to simply create an issue or a pull request!

Bugs related with security

Please handle these responsibly! If you happen to find one, please contact the author privately.

Special thanks to

About

Complete Telegram bot API implementation for PHP7

https://github.com/unreal4u/telegram-api/wiki

License:MIT License


Languages

Language:PHP 99.3%Language:Shell 0.7%