PHPackages                             uzdevid/yii2-telegram - 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. uzdevid/yii2-telegram

ActiveYii2-extension[API Development](/categories/api)

uzdevid/yii2-telegram
=====================

Integration with Telegram

1.3.0(3y ago)1101BSD-4-ClausePHP

Since Jul 18Pushed 3y agoCompare

[ Source](https://github.com/uzdevid/yii2-telegram)[ Packagist](https://packagist.org/packages/uzdevid/yii2-telegram)[ RSS](/packages/uzdevid-yii2-telegram/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Extension for develop telegram bot
==================================

[](#extension-for-develop-telegram-bot)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](https://getcomposer.org).

Either run

```
composer require uzdevid/yii2-telegram "1.2.0"

```

or add

```
"uzdevid/yii2-telegram": "1.2.0"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Create `telegram` extension with config params

```
$config = [
    '_bot_' => [
        'token' => '5390057974:AAFsR6ySk6CTPHs9neYkAXdKTO5cer1cdho'
    ]
];

$telegram = new Telegram($config);
```

---

### Set and delete webhook

[](#set-and-delete-webhook)

- `$url` - url to Your handler

```
$url = "https://example.com/telegrambot";
```

```
$telegram->bot->setWebHook($url);
```

```
$telegram->bot->deleteWebHook($url);
```

---

### Send

[](#send)

#### Send text \[[docs](https://core.telegram.org/bots/api#sendmessage)\]

[](#send-text-docs)

> - `$text` - \[`string` | `required`\] - message text.
> - `$params` - \[`array` | `optional`\] - additional params: parse\_mode, entities, disable\_web\_page\_preview and other. Read the telegram bot docs...
> - `$chat_id` - \[`integer` | `required`\] - telegram user chat id.

```
$text = "Hello world!!!";
$params = [
    'parse_mode'=> 'HTML'
];
$chat_id = 1234567;
```

```
$telegram->bot->sender->text($text, $params)->send($chat_id);
```

> **Note:** All send requests return a response from telegram

Example

```
$result = $telegram->bot->sender->text($text, $params)->send($chat_id);
file_put_contents('test.json', json_encode($result, JSON_UNESCAPED_UNICODE));
```

---

#### Send photo \[[docs](https://core.telegram.org/bots/api#sendphoto)\]

[](#send-photo-docs)

> - `$photo` - \[`string` | `required`\] - path to photo.
> - `$params` - \[`array` | `optional`\] - additional params: parse\_mode, caption\_entities, disable\_notification and other. Read the telegram bot docs...
> - `$text` - \[`string` | `optional`\] - caption for photo.
> - `$chat_id` - \[`integer` | `required`\] - telegram user chat id.

```
$photo = '/img/elephant.jpg'
$text = "This is elephant photo";
$params = [
    'parse_mode'=> 'HTML'
];
$chat_id = 1234567;
```

```
$telegram->bot->sender->photo($photo, $params)->text($text)->send($chat_id);
```

or you can send a photo without a caption

```
$telegram->bot->sender->photo($photo, $params)->send($chat_id);
```

---

#### Send video \[[docs](https://core.telegram.org/bots/api#sendvideo)\]

[](#send-video-docs)

> - `$video` - \[`string` | `required`\] - path to video.
> - `$params` - \[`array` | `optional`\] - additional params: duration, width, height and other. Read the telegram bot docs...
> - `$text` - \[`string` | `optional`\] - caption for video.
> - `$chat_id` - \[`integer` | `required`\] - telegram user chat id.

```
$video = '/img/avengers-final.mp4'
$text = "Avengers: Final";
$params = [
    'parse_mode'=> 'HTML'
];
$chat_id = 1234567;
```

```
$telegram->bot->sender->video($photo, $params)->text($text)->send($chat_id);
```

or you can send a video without a caption

```
$telegram->bot->sender->video($photo, $params)->send($chat_id);
```

---

#### Send sticker \[[docs](https://core.telegram.org/bots/api#sendsticker)\]

[](#send-sticker-docs)

> - `$sticker` \[`string` | `required`\] - sticker id.
> - `$params` - \[`array` | `optional`\] - additional params: disable\_notification, protect\_content, reply\_to\_message\_id and other. Read the telegram bot docs...
> - `$chat_id` - \[`integer` | `required`\] - telegram user chat id.

```
$sticker = "CAACAgIAAxkBAAEFRRhiz-WSsSh7GsHDlj8_csvlad9-2gACHQADO3EfIqmCmmAwV9EZKQQ";
$params = [
    'disable_notification'=> true
];
$chat_id = 1234567;
```

```
$telegram->bot->sender->sticker($sticker, $params)->send($chat_id);
```

---

#### Send contact \[[docs](https://core.telegram.org/bots/api#sendcontact)\]

[](#send-contact-docs)

> - `$phone` \[`string` | `required`\] - phone number.
> - `$first_name` \[`string` | `required`\] - first name.
> - `$last_name` \[`string` | `optional`\] - last name.
> - `$params` - \[`array` | `optional`\] - additional params: vcard, disable\_notification, protect\_content and other. Read the telegram bot docs...
> - `$chat_id` - \[`integer` | `required`\] - telegram user chat id.

```
$phone = '+998993261330';
$first_name = 'Diyorbek';
$last_name = 'Ibragimov';
$params = [
    'disable_notification'=> true
];
$chat_id = 1234567;
```

```
$telegram->bot->sender->contact($url, $first_name, $last_name)->send($chat_id);
```

---

#### Send poll \[[docs](https://core.telegram.org/bots/api#sendpoll)\]

[](#send-poll-docs)

> - `$question` - \[`string` | `required`\] - Question.
> - `$options` - \[`array` | `required`\] - Options.
> - `$correct_option_id` - \[`integer` | `optional`\] - Correct option id, Required for polls in quiz mode.
> - `$params` - \[`array` | `optional`\] - additional params: type, allows\_multiple\_answers, explanation and other. Read the telegram bot docs...

```
$question = "Question";
$options = ['variant id-0', 'variant id-1', 'variant id-2'];
$correct_option_id = 1;
$params = ['type' => 'quiz'];
$chat_id = 1234567;
```

```
$telegram->bot->sender->poll($question, $options, $correct_option_id, $params)->send($chat_id);
```

### Send message, photo, video, sticker and poll with inline keyboard and/or keyboard

[](#send-message-photo-video-sticker-and-poll-with-inline-keyboard-andor-keyboard)

Keyboard

```
$telegram->bot->sender
    ->text($text)
    ->createKeyboard([['text' => "Button"]])
    ->send($chat_id);
```

---

URL inline keyboard

```
$telegram->bot->sender
    ->photo($photo)
    ->text($text)
    ->createInlineKeyboard([['text' => "URL button", 'url' => "https://devid.uz"]])
    ->send($chat_id);
```

---

callback inline keyboard

```
$callback_data = json_encode(['command' => '/callback', 'id' => 12021]);
$telegram->bot->sender
    ->text($text)
    ->createInlineKeyboard([['text' => 'callback', 'callback_date' => $callback_data]])
    ->send($chat_id);
```

---

### Handlers

[](#handlers)

> **Note:** When processing requests, there is no need to specify a chat id when sending a response to a request.

Processing `/start` request

```
$telegram->bot->handler->onMessage('/start', function ($body) use ($telegram) {
    // Your code
    $telegram->bot->sender->text("Welcome")->send();
});
```

---

Processing callback query

```
$telegram->bot->handler->onCommand('/callback', function ($body, $callback_data) use ($telegram) {
    // Your code
    $telegram->bot->sender->photo('/img/elephant.jpg')->send();
});
```

---

Processing all (\*) inline query

```
$telegram->bot->handler->onQuery('*', function ($query, $body) use ($telegram) {
    // Your code
    $title = "Mode: InlineQuery";
    $description = "Query: {$query}";
    $content = "Answer content";

    $telegram->bot->sender->inline
        ->answer([$telegram->bot->sender->inline->article($title, $description, $content)])
        ->send();
});
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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

Every ~94 days

Total

4

Last Release

1116d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/104216283?v=4)[UzDevid](/maintainers/uzdevid)[@uzdevid](https://github.com/uzdevid)

---

Top Contributors

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

---

Tags

yii2yii2-extensionyii2extensionbottelegram

### Embed Badge

![Health badge](/badges/uzdevid-yii2-telegram/health.svg)

```
[![Health](https://phpackages.com/badges/uzdevid-yii2-telegram/health.svg)](https://phpackages.com/packages/uzdevid-yii2-telegram)
```

###  Alternatives

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

Telegram bot api component for Yii2

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

Support chat for site based on Telegram bot

526.3k](/packages/onmotion-yii2-telegram)[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.7k](/packages/dotzero-yii2-amocrm)[conquer/services

Yii2 soap wsdl web services

1632.5k](/packages/conquer-services)[apexwire/yii2-restclient

Tools to use API as ActiveRecord for Yii2

143.5k](/packages/apexwire-yii2-restclient)

PHPackages © 2026

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