Git Product home page Git Product logo

telegram-api's Introduction

PHP 7 Telegram Bot API

Telegram API

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage License

This is a PHP7 bot API implementation for Telegram implementing the totality of Bot API up until v3.5

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 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

All 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 :)

Roadmap

  • v3 (master branch) is the current active branch.
  • v2 (v2 branch) will be updated with the latest Bot API updates until at least April 2018. Depending on usage and some other factors, this can be extended.
  • 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

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:

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

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

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 !)

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

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();

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.

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?

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

Contact the author

Telegram

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 help is to simply create an issue or a pull request!

Bugs related with security

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.

Special thanks to

telegram-api's People

Contributors

azacchino avatar megazoll avatar nanosector avatar unreal4u avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.