Download the PHP package bahramali/telegram-bot-php without Composer
On this page you can find all versions of the php package bahramali/telegram-bot-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bahramali/telegram-bot-php
More information about bahramali/telegram-bot-php
Files in bahramali/telegram-bot-php
Package telegram-bot-php
Short Description Telegram-Bot-PHP is a PHP library for interacting with the official Telegram Bot API
License MIT
Homepage https://github.com/ErfanBahramali/Telegram-Bot-PHP
Informations about the package telegram-bot-php
Telegram Bot PHP
Telegram Bot PHP is a PHP Library for interaction with Telegram Bot API 5.4 (November 5, 2021).
Table
- Requirements
- Installation
- Usage
- Security
- Config
- Configs
- Logging
- onLog
- onLogUpdate
- onLogRequestAndResponse
- onLogError
- Main Config
- Use Config
- Set Config
- Update
- Webhook
- Get Updates
- Methods
- Keyboards
- Response
- Get Response
- Result
- Example
- Error
- Request
- Download File
- Helper
- Format
- Exceptions
- Update Type
- Chat Action
- Examples
- Troubleshooting
- About Us
- License
Requirements
Please read the Telegram API document at least once
- Read Telegram API document
- php >=7.4
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
Installation
Use composer to require it,
or
or
Create composer.json
file and add
and run
Note: If you don't have Composer you can download it HERE.
Usage
To use this library, you need to require the Composer Autoloader And create a new object from the bot class
Please read the Telegram API document at least once
Security
You can add a specific parameter to your webhook url so that only you know about that link.
Example:
Then check in your code the parameter that must be present
Be sure to check that the IP is the sender of the Telegram IP.
You can use the 'isTelegramIp' function of 'bot' class to check Telegram IP
Example:
Config
Configs
You can adjust the configuration and change it in each section
if you are using a local bot api server, Set up your server url
if you are using a local bot api server, Set up your server file url, for download file
Convert updates and response to objects for easier access
Also you can set the variable to false and receive updates and response as an array
If you don't want to use Webhook automatically, set this variable to false
If you don't want some methods to have some of their parameters automatically, set this variable to false
Its accuracy is not always guaranteed
If you want the program to continue after the error, set this variable to false
This is only for when the response code of the submitted request is not equal to 200
Logging
This library can log all their update , requests , responses and errors
Just set the function for the desired log
You can change any of the functions anywhere in the app
Get the information and you can use any method you want to record it
onLog
For updates , requests , responses and errors
At the end, the program is called and sends update and a list of all requests and responses and errors as input
Example
onLogUpdate
For update only
When the update is received, the function is called
Example
onLogRequestAndResponse
For requests and responses only
When a request is sent and the response code is 200
Example
onLogError
For errors only
When a request is sent and the response code is not 200
Example
Main Config
The main configuration is constant everywhere in the program And when a new configuration is created, the default value is the value set for the main configuration.
You can adjust the main configuration and change it in each section
Note: You can see the default values above
Use
It should only be used statically
Use Config
Just create an object of config class and change the values
Note: The default configuration values are the Main configuration values
Set
To use the created configuration, it can be set to the second parameter of the bot class
It can also be changed later if needed
Update
There are two ways to receive the update
There is no difference between camelCase and under_score to get the parameters
Webhook
If you are using a webhook you can get updates using the 'getUpdate' and 'getInput' functions
https://core.telegram.org/bots/api#setwebhook
Example
Get Updates
Returns an array of update object
https://core.telegram.org/bots/api#getupdates
Example:
Methods
To use the methods, all you have to do is type in the name of the method and pass an array of parameters listed in the Telegram api document.
Example:
You can also use static
Example:
Also to use different BOT_API_TOKEN
You can in the second parameter of each method, Enter a new BOT_API_TOKEN
Example:
Keyboards
InlineKeyboardMarkup
ReplyKeyboardMarkup
ReplyKeyboardRemove
ForceReply
Response
There is no difference between camelCase and under_score to get the parameters
Get Response
Result
Example:
Error:
Request:
Download File
download file by file_id
Helper
Helpers are auxiliary functions for receiving certain values or checking some items or doing certain tasks
Note: You can see the full list of functions in the Helpers Folder
There is no difference between camelCase and under_score to get the parameters
Example:
You can also create a new helper with the input update array
Of course, the bot builds the helper itself and there is no need to build a helper with its value, You can get the bot helper with 'getHelper'
Example:
Format
The Format class is a class to help create different text formats
https://core.telegram.org/bots/api#formatting-options
Mention
You can easily mention users
Styles
Example:
Example:
Exceptions
You can manage errors with try catch
BotException: Main exception class used for exception handling
BotLogException: exception class used for log
BotNotSupportException: exception class Thrown when Feature not support
Update Type
If you want to check the type of updates
You can use helpers
You can see the full list of 'updateTypeIs...' functions in the helper type class
Example:
Or
You can use the 'getUpdateType' helper to get the type of update and then check it using different types of updates
You can see the full list of update types in the update type class
Example:
Chat Action
You can use existing chat actions to send chat action
You can see the full list of chat actions in the chat action class
Example:
Examples
Troubleshooting
please report any bugs you find on the issues page.
About Us
This library can be used for easy interaction with Telegram Bot API
License
Telegram-Bot-PHP is licensed under the MIT License - see the LICENSE file for details
All versions of telegram-bot-php with dependencies
ext-curl Version *
ext-json Version *
ext-mbstring Version *
ext-openssl Version *