PHPackages                             alexsisukin/php-telegram-bot-core - 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. alexsisukin/php-telegram-bot-core

ActiveLibrary[API Development](/categories/api)

alexsisukin/php-telegram-bot-core
=================================

PHP Telegram bot

0.53(8y ago)019MITPHPPHP ^5.5|^7.0

Since Jan 30Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Alexsisukin/php-telegram-bot-core)[ Packagist](https://packagist.org/packages/alexsisukin/php-telegram-bot-core)[ Docs](https://github.com/Alexsisukin/php-telegram-bot-core)[ RSS](/packages/alexsisukin-php-telegram-bot-core/feed)WikiDiscussions master Synced 1mo ago

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

PHP Telegram Bot
================

[](#php-telegram-bot)

[![Join the bot support group on Telegram](https://camo.githubusercontent.com/8849db21f207901c78c54221d53f877c3d7cbe3bff6cbf2e98a775bae7dadcfe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74656c656772616d2d405048505f5f54656c656772616d5f5f426f745f5f537570706f72742d3332613264612e737667)](https://telegram.me/PHP_Telegram_Bot_Support)[![Donate](https://camo.githubusercontent.com/d14d49accd95f2b5c4ef775100b7f9d45171a33f5f6d70175f13df8a85770536/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539322539392d446f6e6174652d626c75652e737667)](#donate)

[![Build Status](https://camo.githubusercontent.com/3e073012c5712d355139ddc4ea95f6560e0119623f6ce0f4e266f1340cc6e963/68747470733a2f2f7472617669732d63692e6f72672f7068702d74656c656772616d2d626f742f636f72652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-telegram-bot/core)[![Code Coverage](https://camo.githubusercontent.com/f34e5be97f3b7ef44faddc3f7398c638014a6c65fb98f32c2c5b13262c96e756/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7068702d74656c656772616d2d626f742f636f72652f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=develop)[![Code Quality](https://camo.githubusercontent.com/e88cb70cbf4f0730bb06ce656b07f722cd0eb1e9327dc2b5fae0f2cbcffd8643/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7068702d74656c656772616d2d626f742f636f72652f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=develop)[![Latest Stable Version](https://camo.githubusercontent.com/3a2e9084d9f62dd0bff4b67e27a11c3ddedba8b7b400ea2ae0b2945bea017d8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4c6f6e676d616e2f74656c656772616d2d626f742e737667)](https://packagist.org/packages/longman/telegram-bot)[![Total Downloads](https://camo.githubusercontent.com/2e76cf3d6a8d11e50fbcf01e0c07cdc3f7ad01101cae0831df17e9a970405374/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4c6f6e676d616e2f74656c656772616d2d626f742e737667)](https://packagist.org/packages/longman/telegram-bot)[![Downloads Month](https://camo.githubusercontent.com/04f4263968e03f6066f8b85b18b438e4c40e0a027cc42dd144937158d90ece2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f4c6f6e676d616e2f74656c656772616d2d626f742e737667)](https://packagist.org/packages/longman/telegram-bot)[![Minimum PHP Version](https://camo.githubusercontent.com/3c66b413733fe72f056485e12551cfa626a3acd96d9d7e441ca52dbc3a39646a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344352e362d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/855513c989ea504a9fe4e868e184f125bcd5535eee19a90e556ad0e53fb4e197/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f4c6f6e676d616e2f74656c656772616d2d626f742e737667)](https://github.com/php-telegram-bot/core/LICENSE.md)

A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.org/bots/api "Telegram Bot API")

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Instructions](#instructions)
    - [Create your first bot](#create-your-first-bot)
    - [Require this package with Composer](#require-this-package-with-composer)
    - [Choose how to retrieve Telegram updates](#choose-how-to-retrieve-telegram-updates)
    - [Webhook installation](#webhook-installation)
    - [Self Signed Certificate](#self-signed-certificate)
    - [Unset Webhook](#unset-webhook)
    - [getUpdates installation](#getupdates-installation)
- [Support](#support)
    - [Types](#types)
    - [Inline Query](#inline-query)
    - [Methods](#methods)
    - [Send Message](#send-message)
    - [Send Photo](#send-photo)
    - [Send Chat Action](#send-chat-action)
    - [getUserProfilePhoto](#getuserprofilephoto)
    - [getFile and dowloadFile](#getfile-and-dowloadfile)
    - [Send message to all active chats](#send-message-to-all-active-chats)
- [Utils](#utils)
    - [MySQL storage (Recommended)](#mysql-storage-recommended)
    - [Channels Support](#channels-support)
    - [Botan.io integration (Optional)](#botanio-integration-optional)
- [Commands](#commands)
    - [Predefined Commands](#predefined-commands)
    - [Custom Commands](#custom-commands)
    - [Commands Configuration](#commands-configuration)
- [Admin Commands](#admin-commands)
    - [Set Admins](#set-admins)
    - [Channel Administration](#channel-administration)
- [Upload and Download directory path](#upload-and-download-directory-path)
- [Logging](doc/01-utils.md)
- [Documentation](#documentation)
- [Example bot](#example-bot)
- [Projects with this library](#projects-with-this-library)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [Donate](#donate)
- [License](#license)
- [Credits](#credits)

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

[](#introduction)

This is a pure PHP Telegram Bot, fully extensible via plugins. Telegram recently announced official support for a [Bot API](https://telegram.org/blog/bot-revolution) allowing integrators of all sorts to bring automated interactions to the mobile platform. This Bot aims to provide a platform where one can simply write a plugin and have interactions in a matter of minutes.

The Bot can:

- retrieve updates with webhook and getUpdates methods.
- supports all types and methods according to Telegram API (25 May 2016).
- supports supergroups.
- handle commands in chat with other bots.
- manage Channel from the bot admin interface.
- full support for **inline bots**.
- inline keyboard.
- Messages, InlineQuery and ChosenInlineQuery are stored in the Database.
- *Botan.io* integration and database cache system. (**new!**)
- Conversation feature

---

This code is available on [Github](https://github.com/php-telegram-bot/core). Pull requests are welcome.

Instructions
------------

[](#instructions)

### Create your first bot

[](#create-your-first-bot)

1. Message @botfather  with the following text: `/newbot`If you don't know how to message by username, click the search field on your Telegram app and type `@botfather`, where you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users has similar usernames to `botfather`.

    [![botfather initial conversation](https://camo.githubusercontent.com/c41f7100347d9e629a4d3211d836fcd02d749ddd2cc329a8d83c088f517ceca2/687474703a2f2f692e696d6775722e636f6d2f614932366978522e706e67)](https://camo.githubusercontent.com/c41f7100347d9e629a4d3211d836fcd02d749ddd2cc329a8d83c088f517ceca2/687474703a2f2f692e696d6775722e636f6d2f614932366978522e706e67)
2. @botfather replies with `Alright, a new bot. How are we going to call it? Please choose a name for your bot.`
3. Type whatever name you want for your bot.
4. @botfather replies with `Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.`
5. Type whatever username you want for your bot, minimum 5 characters, and must end with `bot`. For example: `telesample_bot`
6. @botfather replies with:

    ```
    Done! Congratulations on your new bot. You will find it at
    telegram.me/telesample_bot. You can now add a description, about
    section and profile picture for your bot, see /help for a list of
    commands.

    Use this token to access the HTTP API:
    123456789:AAG90e14-0f8-40183D-18491dDE

    For a description of the Bot API, see this page:
    https://core.telegram.org/bots/api

    ```
7. Note down the 'token' mentioned above.
8. Type `/setprivacy` to @botfather.

    [![botfather later conversation](https://camo.githubusercontent.com/f5c5019b8512280ea872002f6b5a076207640b0568c40d8cafdf8de60a7658d2/687474703a2f2f692e696d6775722e636f6d2f745744567668342e706e67)](https://camo.githubusercontent.com/f5c5019b8512280ea872002f6b5a076207640b0568c40d8cafdf8de60a7658d2/687474703a2f2f692e696d6775722e636f6d2f745744567668342e706e67)
9. @botfather replies with `Choose a bot to change group messages settings.`
10. Type (or select) `@telesample_bot` (change to the username you set at step 5 above, but start it with `@`)
11. @botfather replies with

    ```
    'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.
    'Disable' - your bot will receive all messages that people send to groups.
    Current status is: ENABLED

    ```
12. Type (or select) `Disable` to let your bot receive all messages sent to a group. This step is up to you actually.
13. @botfather replies with `Success! The new status is: DISABLED. /help`

### Require this package with Composer

[](#require-this-package-with-composer)

Install this package through [Composer](https://getcomposer.org/ "Composer"). Edit your project's `composer.json` file to require `longman/telegram-bot`.

Create *composer.json* file

```
{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "php": ">=5.5",
        "longman/telegram-bot": "*"
    }
}
```

and run `composer update`

**or**

run this command in your command line:

```
composer require longman/telegram-bot
```

### Choose how to retrieve Telegram updates

[](#choose-how-to-retrieve-telegram-updates)

The bot can handle updates with **Webhook** or **getUpdates** method:

WebhookgetUpdatesDescriptionTelegram sends the updates directly to your hostYou have to fetch Telegram updates manuallyHost with httpsRequiredNot requiredMySQLNot requiredRequiredWebhook installation
--------------------

[](#webhook-installation)

Note: For a more detailed explanation, head over to the [example-bot repository](https://github.com/php-telegram-bot/example-bot "Example Bot repository") and follow the instructions there.

In order to set a [Webhook](https://core.telegram.org/bots/api#setwebhook "Webhook on Telegram Bot API") you need a server with HTTPS and composer support. (For a [self signed certificate](#self-signed-certificate) you need to add some extra code)

Create [*set.php*](https://github.com/php-telegram-bot/example-bot/blob/master/set.php "example set.php") with the following contents:

```
