PHPackages                             jaykee1/api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. jaykee1/api

ActiveLibrary[API Development](/categories/api)

jaykee1/api
===========

Use telegram bot api easily.

v1.0.0(7y ago)272MITPHP

Since Nov 27Pushed 5y agoCompare

[ Source](https://github.com/jaykee1/API)[ Packagist](https://packagist.org/packages/jaykee1/api)[ RSS](/packages/jaykee1-api/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Introduction
------------

[](#introduction)

[![Download](https://camo.githubusercontent.com/764c404a69e39396665ae2deb240074e90bb16f3ab0ee95a81aea73873e3d9d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a61796b6565312f4150492e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jaykee1/API) [![Version](https://camo.githubusercontent.com/38bdbf606ef698737560c179229b669a855253d13069facfb76eaf3512cfc82f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d56312e312e302d79656c6c6f677265656e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jaykee1/API) [![API Version](https://camo.githubusercontent.com/bdc03e32dd6461b856eb9c7c58a2b7bf63c2bd1bf7182e10361f55ff1cab575a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f61706925323076657273696f6e2d56332e362d6f72616e67652e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jaykee1/API) [![Stars](https://camo.githubusercontent.com/f893789acc7197c4410ca1b98eec106a369012d58d7b69e3fd234e01c1d6f07a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a61796b6565312f4150492e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d4c696b65)](https://github.com/jaykee1/API)

The API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult [Telegram Introduction to Bots](https://core.telegram.org/bots) and [Bot FAQ](https://core.telegram.org/bots/faq).

### Requirements

[](#requirements)

1. PHP 5.5+
2. [Composer](https://getcomposer.org/) - Dependency Manager for PHP
3. [yiisoft/yii2](https://packagist.org/packages/yiisoft/yii2) - Yii PHP Framework Version 2
4. [Bot Token](https://core.telegram.org/bots#3-how-do-i-create-a-bot) - Telegram Bot API Access Token

### Installation

[](#installation)

Install this package through [Composer](https://getcomposer.org/). Edit your project's `composer.json` file to require `"jaykee1/api": "*"` Or run this command in your command line:

```
composer require jaykee1/api
```

Usage
-----

[](#usage)

The most common way of using this library is to create a new object from the API class, which allows you to access all of the authorized Telegram methods. By using the API class, events can also be used for you, which in the end of this article has been taught how to use it.

```
$token = '';
$api = new \api\base\API($token);
```

### Request

[](#request)

As we said, this library is an HTTP-based interface, and all requests are sent using the **POST** method. To create a simple request, you must create a new object from the Request class and send the input parameters such as the method name.

```
$request = new \api\base\Request($token, [
    'method' => 'sendMessage',
    'chat_id' => '',
    'text' => 'Hello !!'
]);
```

You do not need to create your own requests in this way, you can use the same object you used to create the API class before. We've prepared for you all the methods in the documentation of the Telegram.

```
$request = $api->sendMessage();
$request->chat_id = '';
$request->text = 'Hello !!';
```

At the end and after sending your desired parameters, your request object is ready to be sent to the Telegram.

### Response

[](#response)

After sending any request, you will receive a response, that is a Response object type. To send the request you created in the previous step, you must use the `send()` method and save the response in a variable.

```
$response = $request->send();
```

According to the Telegram documentation about [sending the message](https://core.telegram.org/bots/api#sendmessage), after sending a message, you will receive a response like the Message object. In the response object you can use the `has()` method to verify a field and use `get()` to get the value of a field.

```
if ($response instanceof \api\response\Message) {
    // request succeed
    if ($response->hasText())
        $text = $response->getText();

    // OR
    // if (isset($response->text))
    //     $text = $response->text;
}
```

> **NOTE**
>
> Making any request that directly uses the Request object will send us an array response, not an object.

### Methods

[](#methods)

We will support all the methods already in the [Telegram documentation](https://core.telegram.org/bots/api#available-methods). You can access all of them through `src\methods` and edit them if you wish. All methods in the API are case-insensitive. We only support **POST** HTTP method and we will use **`multipart/form-data`** for passing files to Telegram server.

### Sending files

[](#sending-files)

#### By file\_id

[](#by-file_id)

If the file is already stored somewhere on the Telegram servers, you don't need to reupload it: each file object has a **file\_id** field, simply pass this **file\_id** as a parameter instead of uploading. There are **no limits** for files sent this way.

```
$request = $api->sendPhoto();
$request->chat_id = '';
$request->caption = 'sent by file_id.';
$request->photo = 'AgADBAADXME4GxQXZAc6zkxv265UJKGYEAAEC';
$request->send();
```

> **NOTE**
>
> file\_id is unique for each individual bot and can't be transferred from one bot to another.

#### By URL

[](#by-url)

Provide Telegram with an HTTP URL for the file to be sent. Telegram will download and send the file. 5 MB max size for photos and 20 MB max for other types of content.

- When sending by URL the target file must have the correct MIME type (e.g., `audio/mpeg` for [sendAudio](https://core.telegram.org/bots/api#sendaudio), etc.).
- In [sendDocument](https://core.telegram.org/bots/api#senddocument), sending by URL will currently only work for **gif**, **pdf** and **zip** files.
- To use [sendVoice](https://core.telegram.org/bots/api#sendvoice), the file must have the type `audio/ogg` and be no more than 1MB in size. 1–20MB voice notes will be sent as files.
- Other configurations may work but we can't guarantee that they will.

```
$request = $api->sendPhoto();
$request->chat_id = '';
$request->caption = 'sent by url.';
$request->photo = 'http://example.com/photos/dogs.jpg';
$request->send();
```

#### By InputFile

[](#by-inputfile)

This object represents the contents of a file to be uploaded. Must be posted using `multipart/form-data` in the usual way that files are uploaded via the browser.

```
$request = $api->sendPhoto();
$request->chat_id = '';
$request->caption = 'sent by InputFile.';
$request->photo = new \api\InputFile('@photos/cats.jpg');
$request->send();
```

### Keyboards

[](#keyboards)

Traditional chat bots can of course be taught to understand human language. But sometimes you want some more formal input from the user — and this is where **custom keyboards** can become extremely useful.

```
$request->reply_markup = $markup;
```

#### Reply Keyboards

[](#reply-keyboards)

Whenever your bot sends a message, it can pass along a special keyboard with predefined reply options (see [ReplyKeyboardMarkup](https://core.telegram.org/bots/api/#replykeyboardmarkup)). Telegram apps that receive the message will display your keyboard to the user. Tapping any of the buttons will immediately send the respective command. This way you can drastically simplify user interaction with your bot. Telegram currently support text and emoji for your buttons.

Here are some custom keyboard examples:

 [![](https://camo.githubusercontent.com/668cce86950dd9dd07cd6456e0f2375aee39c723e73ebb661bda8e408e68afda/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303138342f312f35594a78782d726f7374412f616433663734303934343835666239376264 "Keyboard for a poll bot")](https://camo.githubusercontent.com/668cce86950dd9dd07cd6456e0f2375aee39c723e73ebb661bda8e408e68afda/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303138342f312f35594a78782d726f7374412f616433663734303934343835666239376264) [![](https://camo.githubusercontent.com/a520c4af5f2963319dfaf50390a14f69bae9b5873c9ba0d97bb9b8c138537b95/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303838302f312f6a532d5953566b44434e512f623339376466636566633664613064633730 "Keyboard for a calculator bot. Because you can.")](https://camo.githubusercontent.com/a520c4af5f2963319dfaf50390a14f69bae9b5873c9ba0d97bb9b8c138537b95/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303838302f312f6a532d5953566b44434e512f623339376466636566633664613064633730) [![](https://camo.githubusercontent.com/5960e1b785a2cd37bd5d9eb76d535d1c258453dffe8a71447ba8e4c68733732e/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303733332f322f4b6f7973714a4b515f6b492f613165653436613337373739366333393631 "Keyboard for a trivia bot")](https://camo.githubusercontent.com/5960e1b785a2cd37bd5d9eb76d535d1c258453dffe8a71447ba8e4c68733732e/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303733332f322f4b6f7973714a4b515f6b492f613165653436613337373739366333393631)

```
use api\keyboard\ReplyKeyboardMarkup;
use api\keyboard\button\KeyboardButton;

// Keyboard plan
$markup = new ReplyKeyboardMarkup();
$markup->resize_keyboard = true;

// button for request user location
$locationBtn = new KeyboardButton();
$locationBtn->text = 'Send your location';
$locationBtn->request_location = true;
$markup->addButton($locationBtn, 1);

// button for request user phone number
$NumberBtn = new KeyboardButton();
$NumberBtn->text = 'Send your phone number';
$NumberBtn->request_contact = true;
$markup->addButton($NumberBtn, 2);
```

#### Inline Keyboards

[](#inline-keyboards)

There are times when you'd prefer to do things without sending any messages to the chat. For example, when your user is changing settings or flipping through search results. In such cases you can use Inline Keyboards that are integrated directly into the messages they belong to.

Unlike with custom reply keyboards, pressing buttons on inline keyboards doesn't result in messages sent to the chat. Instead, inline keyboards support buttons that work behind the scenes: [callback buttons](https://core.telegram.org/bots/2-0-intro#callback-buttons), [URL buttons](https://core.telegram.org/bots/2-0-intro#url-buttons) and [switch to inline buttons](https://core.telegram.org/bots/2-0-intro#switch-to-inline-buttons).

 [![](https://camo.githubusercontent.com/911b755a7a571a3ef7c6acc030654b5541198bd4783de7fbadb3b81c9182c90c/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303231372f312f4e6b5243434c65515a56632f313761383034383337383032373030656134 "Callback buttons in @music")](https://camo.githubusercontent.com/911b755a7a571a3ef7c6acc030654b5541198bd4783de7fbadb3b81c9182c90c/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303231372f312f4e6b5243434c65515a56632f313761383034383337383032373030656134) [![](https://camo.githubusercontent.com/611e10c7565860786401bb7f12d92f299fbd28fcf93a3f6baa2f9d49be224e2d/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303635392f312f52524a79756c62744c42592f656136313633343131633765623466346463 "More callback buttons in @music")](https://camo.githubusercontent.com/611e10c7565860786401bb7f12d92f299fbd28fcf93a3f6baa2f9d49be224e2d/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303635392f312f52524a79756c62744c42592f656136313633343131633765623466346463) [![](https://camo.githubusercontent.com/47736dd84175ad87b922e3feb99b564e3ba03910109d896ded4639b90577e5b3/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303939392f312f324a536f55566c574b61302f346661643265323734336463386564613034 "A URL button")](https://camo.githubusercontent.com/47736dd84175ad87b922e3feb99b564e3ba03910109d896ded4639b90577e5b3/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303939392f312f324a536f55566c574b61302f346661643265323734336463386564613034)

> When callback buttons are used, your bot can update its existing messages (or just their keyboards) so that the chat remains tidy.

```
use api\keyboard\InlineKeyboardMarkup;
use api\keyboard\button\InlineKeyboardButton;

// Keyboard plan
$markup = new InlineKeyboardMarkup();

// url button
$urlBtn = new InlineKeyboardButton();
$urlBtn->text = 'Go to Google';
$urlBtn->url = 'https://google.com';
$markup->addButton($urlBtn, 1, 1);

// callback button
$callbackBtn = new InlineKeyboardButton();
$callbackBtn->text = 'Callback Btn';
$callbackBtn->callback_data = 'onclickCallbackBtn';
$markup->addButton($callbackBtn, 1, 2);

// switch button
$switchBtn = new InlineKeyboardButton();
$switchBtn->text = 'Switch to ...';
$switchBtn->switch_inline_query = 'my query';
$markup->addButton($switchBtn, 2);
```

### Inline Mode

[](#inline-mode)

The following methods and objects allow your bot to work in [inline mode](https://core.telegram.org/bots/inline). Please see Telegram [Introduction to Inline bots](https://core.telegram.org/bots/inline) for more details. To enable this option, send the `/setinline` command to [@BotFather](https://t.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bot’s name.

 [![](https://camo.githubusercontent.com/3e79a69ae8ad2832cbfd909972988b844c3ec3b0757d2c906bb8b171ef2eba4f/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303939352f312f492d7775627558416e7a6b2f326533393733396430616336626435343538 "Users can type the bot’s username in any chat, then type a query without sending any messages")](https://camo.githubusercontent.com/3e79a69ae8ad2832cbfd909972988b844c3ec3b0757d2c906bb8b171ef2eba4f/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303939352f312f492d7775627558416e7a6b2f326533393733396430616336626435343538)

#### Results

[](#results)

`InlineQueryResult` object represents one result of an inline query. Telegram clients currently support results of the following 20 types and you can find them through `src\inline` and edit it.

```
$article = new \api\inline\InlineQueryResultArticle();
$article->id = 'result_1';
$article->title = 'Article';
$article->description = 'This is a article result.';

$input = new \api\input\InputTextMessageContent();
$input->message_text = '*Hello* my friend.';
$input->parse_mode = \api\ParseMode::MARKDOWN;
$article->input_message_content = $input;

$results[] = $article;
```

#### Answer to Query

[](#answer-to-query)

Use `answerInlineQuery` method to send answers to an inline query. On success, *True* is returned.

 [![](https://camo.githubusercontent.com/d1e1119d011a080fea59b3d9adbd62b199973517bf7b870b5b1faca853a749c2/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303034392f322f4d326d7a716a5a6f6955772f326438373266306466326165643138326436 "Vertical scrolling")](https://camo.githubusercontent.com/d1e1119d011a080fea59b3d9adbd62b199973517bf7b870b5b1faca853a749c2/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303034392f322f4d326d7a716a5a6f6955772f326438373266306466326165643138326436) [![](https://camo.githubusercontent.com/cb1f45fc965e54233926da5315efa678e5e2924203542d90bf9c62dcc58200c3/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303539322f322f50342d7446686d427343672f353734313861663038663161323532643435 "Horizontal scrolling")](https://camo.githubusercontent.com/cb1f45fc965e54233926da5315efa678e5e2924203542d90bf9c62dcc58200c3/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303539322f322f50342d7446686d427343672f353734313861663038663161323532643435)

> No more than **50** results per query are allowed.

```
$getUpdates = $api->getUpdates();
$getUpdates->limit = 1;
$getUpdates->allowed_updates = ['inline_query'];
$updates = $getUpdates->send();

if (sizeof($updates) == 1) {
    $inlineQuery = $updates[0];

    $request = $api->answerInlineQuery();
    $request->results = $results;
    $request->inline_query_id = $inlineQuery->id;
    $response = $request->send();
}
```

### Helpers

[](#helpers)

#### Actions

[](#actions)

Chat Actions let you broadcast a type of action depending on what the user is about to receive. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).

```
$request = $api->sendChatAction();
$request->chat_id = '';
$request->action = \api\Actions::TYPING;
$request->send();
```

#### Formatting

[](#formatting)

The Bot API supports basic formatting for messages. You can use bold and italic text, as well as inline links and pre-formatted code in your bots' messages. Telegram clients will render them accordingly. You can use either markdown-style or HTML-style formatting.

> **NOTE**
>
> Telegram clients will display an alert to the user before opening an inline link (‘Open this link?’ together with the full URL).

```
$request = $api->sendMessage();
$request->text = '*bold text*';
$request->chat_id = '';
$request->parse_mode = \api\ParseMode::MARKDOWN;

$response = $request->send();
if ($response instanceof \api\response\Error) {
    // request failed
}
```

#### Events

[](#events)

For developers who want to make better and more effective, we also include events in this library so that we can have full access to all requests and responses received and errors.

API object has four Events:

- AfterSend - `API::EVENT_AFTER_SEND`
- BeforeSend - `API::EVENT_BEFORE_SEND`
- RequestFailed - `API::EVENT_REQUEST_FAILED`
- RequestSucceed - `API::EVENT_REQUEST_SUCCEED`

```
use api\method\sendMessage;
use api\event\RequestFailed;

API::on(API::EVENT_REQUEST_FAILED, function (RequestFailed $event) {
    $error = $event->error;
    $method = $event->method;
    $code = $error->error_code;
    $description = $error->description;
    $message = '[' . $code . '] ' . $description;

    if ($method->has('chat_id')) {
        $token = $event->token;
        $chat_id = $method->get('chat_id');
        (new sendMessage($token))
            ->setChatId($chat_id)
            ->setText($message)
            ->send();
    }
});
```

Disclaimer
----------

[](#disclaimer)

This project and its author is neither associated or affiliated with Telegram in any way.

License
-------

[](#license)

This project is released under the [MIT License](https://github.com/botstan/API/blob/master/LICENSE).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2725d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/186497b7f649e7c8960c83d12af53a43b9bcd6f3fa7efe020a0bfedfef3d34c7?d=identicon)[jaykee1](/maintainers/jaykee1)

---

Top Contributors

[![jaykee1](https://avatars.githubusercontent.com/u/17101031?v=4)](https://github.com/jaykee1 "jaykee1 (3 commits)")

---

Tags

apiyii2bottelegram

### Embed Badge

![Health badge](/badges/jaykee1-api/health.svg)

```
[![Health](https://phpackages.com/badges/jaykee1-api/health.svg)](https://phpackages.com/packages/jaykee1-api)
```

###  Alternatives

[sonko-dmitry/yii2-telegram-bot-api

Telegram bot api component for Yii2

2132.2k](/packages/sonko-dmitry-yii2-telegram-bot-api)[borsaco/telegram-bot-api-bundle

A simple wrapper for telegram-bot-api.

5633.0k](/packages/borsaco-telegram-bot-api-bundle)[klev-o/telegram-bot-api

Simple and convenient object-oriented implementation Telegram bot API with php version ^7.4 support. You'll like it)

457.8k1](/packages/klev-o-telegram-bot-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
