PhpBotFramework  1.0.0
A framework for Telegram Bots' APIs.
Functions | Variables
Bot

Properties and methods to handle the TelegramBot. More...

Functions

 DanySpin97\PhpBotFramework\Bot::__construct (string $token)
 Construct an empy bot. More...
 
 DanySpin97\PhpBotFramework\Bot::__destruct ()
 Descruct the class.
 
 DanySpin97\PhpBotFramework\Bot::getQuery ()
 Get the query received from the inline query (for updates of type "inline_query"). More...
 
 DanySpin97\PhpBotFramework\Bot::processWebhookUpdate ()
 Get update and process it. More...
 
 DanySpin97\PhpBotFramework\Bot::processMessage ($message)
 Called every message received by the bot. More...
 
 DanySpin97\PhpBotFramework\Bot::processCallbackQuery ($callback_query)
 Called every callback query received by the bot. More...
 
 DanySpin97\PhpBotFramework\Bot::processInlineQuery ($inline_query)
 Called every inline query received by the bot. More...
 
 DanySpin97\PhpBotFramework\Bot::processChosenInlineResult ($chosen_inline_result)
 Called every chosen inline result received by the bot. More...
 
 DanySpin97\PhpBotFramework\Bot::processEditedMessage ($edited_message)
 Called every chosen edited message received by the bot. More...
 
 DanySpin97\PhpBotFramework\Bot::processChannelPost ($post)
 Called every new post in the channel where the bot is in. More...
 
 DanySpin97\PhpBotFramework\Bot::processEditedChannelPost ($edited_post)
 Called every time a post get edited in the channel where the bot is in. More...
 
 DanySpin97\PhpBotFramework\Bot::getUpdatesRedis (int $limit=100, int $timeout=60, string $offset_key='offset')
 Get updates received by the bot, using redis to save and get the last offset. More...
 
 DanySpin97\PhpBotFramework\Bot::getUpdatesLocal (int $limit=100, int $timeout=60)
 Get updates received by the bot, and hold the offset in $offset. More...
 
 DanySpin97\PhpBotFramework\Bot::getUpdatesDatabase (int $limit=100, int $timeout=0, string $table_name='telegram', string $column_name='bot_offset')
 Get updates received by the bot, using the sql database to store and get the last offset. More...
 
 DanySpin97\PhpBotFramework\Bot::addMessageCommand (string $command, callable $script)
 Add a function that will be executed everytime a message contain the selected command. More...
 
 DanySpin97\PhpBotFramework\Bot::addMessageCommandRegex (string $regex_rule, callable $script)
 Add a function that will be executed everytime a message contain a command that match the regex. More...
 
 DanySpin97\PhpBotFramework\Bot::addCallbackCommand (string $data, callable $script)
 Add a function that will be executed everytime a callback query contains a string as data. More...
 
 DanySpin97\PhpBotFramework\CoreBot::getChatID ()
 Get chat id of the current user. More...
 
 DanySpin97\PhpBotFramework\CoreBot::setChatID ($chat_id)
 Set current chat id. More...
 

Variables

 DanySpin97\PhpBotFramework\Bot::$inline_keyboard
 Store the inline keyboard.
 
 DanySpin97\PhpBotFramework\Bot::$pdo
 Pdo reference.
 
 DanySpin97\PhpBotFramework\Bot::$redis
 Redis connection.
 
 DanySpin97\PhpBotFramework\CoreBot::$chat_id
 Chat_id of the user that interacted with the bot.
 

Detailed Description

Properties and methods to handle the TelegramBot.

Here are listed all the properties and methods that will help the developer create the basic bot functions.

Function Documentation

§ __construct()

DanySpin97\PhpBotFramework\Bot::__construct ( string  $token)

Construct an empy bot.

Construct a bot with commands, multilanguage and status.

§ addCallbackCommand()

DanySpin97\PhpBotFramework\Bot::addCallbackCommand ( string  $data,
callable  $script 
)

Add a function that will be executed everytime a callback query contains a string as data.

Use this syntax:

addMessageCommand("menu", function($bot, $callback_query) {
    $bot->editMessageText($callback_query['message']['message_id'], "This is the menu"); });
Parameters
$dataThe string that will trigger this function.
$scriptThe function that will be triggered by the callback query if it contains the $data string. Must take an object(the bot) and an array(the callback query received).

§ addMessageCommand()

DanySpin97\PhpBotFramework\Bot::addMessageCommand ( string  $command,
callable  $script 
)

Add a function that will be executed everytime a message contain the selected command.

Use this syntax:

addMessageCommand("start", function($bot, $message) {
    $bot->sendMessage("Hi"); });
Parameters
$commandThe command that will trigger this function (without slash). Eg: "start", "help", "about"
$scriptThe function that will be triggered by a command. Must take an object(the bot) and an array(the message received).

§ addMessageCommandRegex()

DanySpin97\PhpBotFramework\Bot::addMessageCommandRegex ( string  $regex_rule,
callable  $script 
)

Add a function that will be executed everytime a message contain a command that match the regex.

Use this syntax:

addMessageCommandRegex("number\d", function($bot, $message, $result) {
    $bot->sendMessage("You sent me a number"); });
Parameters
$regex_ruleRegex rule that will called for evalueting the command received.
$scriptThe function that will be triggered by a command. Must take an object(the bot) and an array(the message received).

§ getChatID()

DanySpin97\PhpBotFramework\CoreBot::getChatID ( )

Get chat id of the current user.

Returns
Chat id of the user.

§ getQuery()

DanySpin97\PhpBotFramework\Bot::getQuery ( )

Get the query received from the inline query (for updates of type "inline_query").

Returns
The query sent by the user, throw exception if the current update is not an inline query.

§ getUpdatesDatabase()

DanySpin97\PhpBotFramework\Bot::getUpdatesDatabase ( int  $limit = 100,
int  $timeout = 0,
string  $table_name = 'telegram',
string  $column_name = 'bot_offset' 
)

Get updates received by the bot, using the sql database to store and get the last offset.

It check if an offset exists on redis, then get it, or call getUpdates to set it. Then it start an infinite loop where it process updates and update the offset on redis. Each update is surrounded by a try/catch.

See also
getUpdates
Parameters
$limitOptional. Limits the number of updates to be retrieved. Values between 1—100 are accepted.
$timeoutOptional. Timeout in seconds for long polling.
$table_nameOptional. Name of the table where offset is saved in the database
$column_nameOptional. Name of the column where the offset is saved in the database

§ getUpdatesLocal()

DanySpin97\PhpBotFramework\Bot::getUpdatesLocal ( int  $limit = 100,
int  $timeout = 60 
)

Get updates received by the bot, and hold the offset in $offset.

Get the update_id of the first update to parse, set it in $offset and then it start an infinite loop where it processes updates and keep $offset on the update_id of the last update received. Each processUpdate() method call is surrounded by a try/catch.

See also
getUpdates
Parameters
$limitOptional. Limits the number of updates to be retrieved. Values between 1—100 are accepted.
$timeoutOptional. Timeout in seconds for long polling.

§ getUpdatesRedis()

DanySpin97\PhpBotFramework\Bot::getUpdatesRedis ( int  $limit = 100,
int  $timeout = 60,
string  $offset_key = 'offset' 
)

Get updates received by the bot, using redis to save and get the last offset.

It check if an offset exists on redis, then get it, or call getUpdates to set it. Then it start an infinite loop where it process updates and update the offset on redis. Each update is surrounded by a try/catch.

See also
getUpdates
Parameters
$limitOptional. Limits the number of updates to be retrieved. Values between 1—100 are accepted.
$timeoutOptional. Timeout in seconds for long polling.
$offset_keyOptional. Name of the variable where the offset is saved on Redis

§ processCallbackQuery()

DanySpin97\PhpBotFramework\Bot::processCallbackQuery (   $callback_query)
protected

Called every callback query received by the bot.

Override it to script the bot answer for each callback. $chat_id set inside of this function.

Parameters
$callback_queryReference to the callback query received.

§ processChannelPost()

DanySpin97\PhpBotFramework\Bot::processChannelPost (   $post)
protected

Called every new post in the channel where the bot is in.

Override it to script the bot answer for each post sent in a channel. $chat_id set inside of this function.

Parameters
$postThe message sent in the channel.

§ processChosenInlineResult()

DanySpin97\PhpBotFramework\Bot::processChosenInlineResult (   $chosen_inline_result)
protected

Called every chosen inline result received by the bot.

Override it to script the bot answer for each chosen inline result. $chat_id set inside of this function.

Parameters
$chosen_inline_resultReference to the chosen inline result received.

§ processEditedChannelPost()

DanySpin97\PhpBotFramework\Bot::processEditedChannelPost (   $edited_post)
protected

Called every time a post get edited in the channel where the bot is in.

Override it to script the bot answer for each post edited in a channel. $chat_id set inside of this function.

Parameters
$postThe message edited in the channel.

§ processEditedMessage()

DanySpin97\PhpBotFramework\Bot::processEditedMessage (   $edited_message)
protected

Called every chosen edited message received by the bot.

Override it to script the bot answer for each edited message. $chat_id set inside of this function.

Parameters
$edited_messageThe message edited by the user.

§ processInlineQuery()

DanySpin97\PhpBotFramework\Bot::processInlineQuery (   $inline_query)
protected

Called every inline query received by the bot.

Override it to script the bot answer for each inline query. $chat_id and $query(use getQuery() to access it) set inside of this function.

Parameters
$inline_queryReference to the inline query received.

§ processMessage()

DanySpin97\PhpBotFramework\Bot::processMessage (   $message)
protected

Called every message received by the bot.

Override it to script the bot answer for each message. $chat_id set inside of this function.

Parameters
$messageReference to the message received.

§ processWebhookUpdate()

DanySpin97\PhpBotFramework\Bot::processWebhookUpdate ( )

Get update and process it.

Call this method if you are using webhook. It will get update from php::, check it and then process it using processUpdate.

§ setChatID()

DanySpin97\PhpBotFramework\CoreBot::setChatID (   $chat_id)

Set current chat id.

Change the chat id which the bot execute api methods.

Parameters
$chat_idThe new chat id to set.