- Saved searches
- Use saved searches to filter your results more quickly
- License
- kuvardin/TelegramBotsApi
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Overview
- Telegram Bot API — PHP SDK
- Requirements
- Installation
- Laravel Additional Steps
- Step 1: Add the Service Provider
- Step 2: Add Facade (Optional)
- Step 3: Publish Configuration File
- Additional information
- Contributing
- License
- Search
- Saved searches
- Use saved searches to filter your results more quickly
- License
- telegram-bot-sdk/telegram-bot-sdk
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
PHP SDK for Telegram bots API
License
kuvardin/TelegramBotsApi
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
SDK for latest version of Telegram bots API (from April 21, 2023)
composer require "kuvardin/telegram-bots-api: dev-master"
require 'vendor/autoload.php'; $client = new GuzzleHttp\Client(); $token = '123456:AAAAAAAAAAAAAAA'; $bot = new Kuvardin\TelegramBotsApi\Bot($client, $token);
require 'vendor/autoload.php'; $client = new GuzzleHttp\Client(); $token = '123456:AAAAAAAAAAAAAAA'; $bot = new Kuvardin\TelegramBotsApi\Bot($client, $token); $chat_id = 123456789; $message_text = 'Hi!'; $request = $bot->sendMessage($chat_id, $message_text); try < $message = $request->sendRequest(); echo 'Successful sent'; > catch (Kuvardin\TelegramBotsApi\Exceptions\TelegramBotsApiException $e) < echo "API error #$e->getCode()>: $e->getMessage()>"; > catch (GuzzleHttp\Exception\GuzzleException $e) < echo "cURL error #$e->getCode()>: $e->getMessage()>"; >
require 'vendor/autoload.php'; $client = new GuzzleHttp\Client(); $token = '123456:AAAAAAAAAAAAAAA'; $bot = new Kuvardin\TelegramBotsApi\Bot($client, $token); $webhooks_handler_url = 'https://example.com/script.php'; $request = $bot->setWebhook($webhooks_handler_url); try < $request->sendRequest(); echo 'Success'; > catch (Kuvardin\TelegramBotsApi\Exceptions\TelegramBotsApiException $e) < echo "API error #$e->getCode()>: $e->getMessage()>"; > catch (GuzzleHttp\Exception\GuzzleException $e) < echo "cURL error #$e->getCode()>: $e->getMessage()>"; >
Receive incoming updates via an outgoing webhook
require 'vendor/autoload.php'; $client = new GuzzleHttp\Client(); $token = '123456:AAAAAAAAAAAAAAA'; $bot = new Kuvardin\TelegramBotsApi\Bot($client, $token); $input = file_get_contents('php://input'); if ($input === false || $input === '') < throw new Error('Input is empty'); > $input_decoded = json_decode($input, true, 512, JSON_THROW_ON_ERROR); if (!is_array($input_decoded)) < throw new Error("Input are not JSON array: $input"); > $request = null; $update = new Kuvardin\TelegramBotsApi\Types\Update($input_decoded); switch ($update->getType()) < case Kuvardin\TelegramBotsApi\Enums\UpdateType::Message: $request = $bot->sendMessage( chat_id: $update->message->chat->id, text: 'Hello World', parse_mode: Kuvardin\TelegramBotsApi\Enums\ParseMode::HTML, reply_markup: new Kuvardin\TelegramBotsApi\Types\InlineKeyboardMarkup([ [ // Buttons row 1 new Kuvardin\TelegramBotsApi\Types\InlineKeyboardButton( text: 'Open URL', url: 'https://github.com/kuvardin', ), new Kuvardin\TelegramBotsApi\Types\InlineKeyboardButton( text: 'Send callback command', callback_data: 'like_it', ), ], [ // Buttons row 2 // . ], [ // Buttons row 3 // . ], // . ]), ); break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::EditedMessage: // . break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::ChannelPost: // . break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::EditedChannelPost: // . break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::InlineQuery: // . break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::ChosenInlineResult: // . break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::CallbackQuery: // . break; case Kuvardin\TelegramBotsApi\Enums\UpdateType::ShippingQuery: // . break; // . > if ($request !== null) < header('Content-Type: application/json'); echo json_encode($request->getRequestData(), JSON_THROW_ON_ERROR); >
About
PHP SDK for Telegram bots API
Overview
Telegram Bot 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 the Introduction to Bots and Bot FAQ on official Telegram site.
Telegram Bot API — PHP SDK
This is an Unofficial Telegram Bot API SDK for PHP language. Lets you develop Telegram Bots easily! Supports Laravel out of the box.
Please review the official documentation of Telegram Bot API to understand the usage better.
Requirements
- PHP 5.5+
- Composer
- Telegram Bot API Access Token — Talk to @BotFather and generate one.
- Laravel 5 or Lumen Installation (Optional only if you want to use with either of these frameworks).
Installation
The recommended way to install the SDK is with Composer. Composer is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project.
# Install Composer curl -sS https://getcomposer.org/installer | php
You can add the SDK as a dependency using the composer.phar CLI:
php composer.phar require irazasyed/telegram-bot-sdk ^2.0
Or if you already have composer installed globally, then simply execute:
composer require irazasyed/telegram-bot-sdk ^2.0
Alternatively, you can specify the SDK as a dependency in your project’s existing composer.json file:
After installing, you need to require Composer’s autoloader if you want to use the library standalone:
require 'vendor/autoload.php';
You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org.
Laravel Additional Steps
If you’re using Laravel and would like to use the SDK with it, then follow the below instructions. Otherwise, you can skip this part.
Step 1: Add the Service Provider
Open config/app.php and, to your providers array at the bottom, add:
Telegram\Bot\Laravel\TelegramServiceProvider::class
Step 2: Add Facade (Optional)
Optionally add an alias to make it easier to use the library. Open config/app.php and, to your «aliases» array at the bottom, add:
'Telegram' => Telegram\Bot\Laravel\Facades\Telegram::class
Step 3: Publish Configuration File
Open your terminal window and fire the following command to publish config file to your config directory:
php artisan vendor:publish --provider="Telegram\Bot\Laravel\TelegramServiceProvider"
php artisan vendor:publish
The former command publishes config file for just this package and the latter publishes vendor config files for other packages too. Depending on what you want to do, you can use any (Doesn’t really matter).
Additional information
The library takes advantage of the amazing Laravel Collection API to automatically map the data. So it’s a lot easier to work with the array of data. Supports all the methods listed on the official docs.
Any issues, feedback, suggestions or questions please use issue tracker here.
Contributing
Thank you for considering contributing to the project. Please review the CONTRIBUTING guidelines before submitting any pull requests.
License
This project is released under the BSD 3-Clause License.
Search
From here you can search these documents. Enter your search terms below.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
🤖 Telegram Bot API PHP SDK 4.x. Create Telegram Bots with PHP Easily! [WIP]
License
telegram-bot-sdk/telegram-bot-sdk
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Telegram Bot API — PHP SDK
Telegram Bot SDK lets you develop Telegram Bots in PHP easily! Supports Laravel framework and comes with addons to enhance your bot development experience.
Telegram Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.
To learn more about the Telegram Bot API, please consult the Introduction to Bots and Bot FAQ on Telegram’s official site.
To get started writing your bots using Telegram Bot SDK, please refer the SDK Documentation.
NOTE: SDK has been migrated from the original repo irazasyed/telegram-bot-sdk since 4.x.
Documentation for the SDK can be found on the website.
Starting from version 4.x, the project has been renamed from irazasyed/telegram-bot-sdk to telegram-bot-sdk/telegram-bot-sdk .
In order to receive the new version and future updates, you need to rename it in your composer.json:
"require": < - "irazasyed/telegram-bot-sdk": "(version you use)", + "telegram-bot-sdk/telegram-bot-sdk": "(version you use)", >
Laravel service provider in addition to various other Laravel specific features have been moved to its own package.
"require": < - "irazasyed/telegram-bot-sdk": "(version you use)", + "telegram-bot-sdk/laravel": "^4.0", >
Are You Using Telegram Bot SDK?
If you’re using this SDK to build your Telegram Bots or have a project that’s relevant to this SDK, We’d love to know and share it with the world.
Head over to Awesome Telegram Bots to share, discover, and learn more.
Thank you for considering contributing to the project. Please read the contributing guide before creating an issue or sending in a pull request.
Please read our Code of Conduct before contributing or engaging in discussions.
If you discover a security vulnerability within this project, please email Syed at security at telegram-bot-sdk.com . All security vulnerabilities will be promptly addressed. You may view our full security policy here.
The Telegram Bot SDK is a third-party library and is not associated with, endorsed by, or affiliated with Telegram or its products. For more details, please read the Disclaimer
This project is open-sourced software licensed under the BSD 3-Clause license.
About
🤖 Telegram Bot API PHP SDK 4.x. Create Telegram Bots with PHP Easily! [WIP]