dev-master
9999999-dev https://github.com/BlazeMV/BlazingPHP Telegram Bot SDK
MIT
The Requires
- php >=5.5.0
- composer/composer 1.5
by Adam Dawood
telegram telegram bot telegram php telegram bot sdk
Wallogit.com
2017 © Pedro PelĂĄez
PHP Telegram Bot SDK
Installing, (*1)
Create a new project, (*2)
composer create-project blaze/blazingsdk <project-name>
Create a new Bot, (*3)
cd <project-name> )composer new bot <bot-name> <bot-api-token>(optional) using laravelâs database module (eloquent) with bots, (*4)
At this point bot will be already configured to respond to /start and /help commands with some default response. You can edit these response from commands.php file inside your bot's directory, (*5)
To add support for more commands add a new method to Commands class (commands.php file). The method should be static (will be changed later) and method name should be the first word of the command. The method should also accept 2 arguments a bot object and a message object., (*6)
Eg: if you are adding support for /hello command your method should look like, (*7)
public static function hello(Bot $bot, Message $msg) { }Note a command doesn't necessarily have to be in the beginning of a msg to be sent to commands.php. you can change this from updates.php, (*8)
If you want bot to respond to CallBackQueries you have add a method to CallBackQueries class (CallBackQueries.php file). The method should be static and its name should be the first word of callback queryâs data. The method should also accept 2 arguments, a bot object and a CallBackQuery object., (*9)
Eg: if you are adding support for a call back query with first word of data as 'hello' your method should look like, (*10)
public static function hello(Bot $bot, CallBackQuery $cbq) { }You can also edit updates.php file to customize the way you want to handle commands, CallBackQueries and other types of bot update objects., (*11)
For the telegram api objects (Message, chat user etcâŠ) use get before api method as getters., (*12)
$msg->getMessageId()
To send requests to telegram api use sendRequest() method in bot class. This method accepts an array. The array must contain a method key and other parameters for the specified method., (*13)
$bot->sendRequest (array(
âmethodâ => âsendMessageâ,
âchat_idâ => $msg->getChat()->getId(),
âtextâ => âsome textâ
));
PHP Telegram Bot SDK
MIT
telegram telegram bot telegram php telegram bot sdk