![]() |
PhpBotFramework
1.0.0
A framework for Telegram Bots' APIs.
|
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. | |
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.
| DanySpin97\PhpBotFramework\Bot::__construct | ( | string | $token | ) |
Construct an empy bot.
Construct a bot with commands, multilanguage and status.
| 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"); });
| $data | The string that will trigger this function. |
| $script | The 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). |
| 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"); });
| $command | The command that will trigger this function (without slash). Eg: "start", "help", "about" |
| $script | The function that will be triggered by a command. Must take an object(the bot) and an array(the message received). |
| 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"); });
| $regex_rule | Regex rule that will called for evalueting the command received. |
| $script | The function that will be triggered by a command. Must take an object(the bot) and an array(the message received). |
| DanySpin97\PhpBotFramework\CoreBot::getChatID | ( | ) |
Get chat id of the current user.
| DanySpin97\PhpBotFramework\Bot::getQuery | ( | ) |
Get the query received from the inline query (for updates of type "inline_query").
| 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.
| $limit | Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. |
| $timeout | Optional. Timeout in seconds for long polling. |
| $table_name | Optional. Name of the table where offset is saved in the database |
| $column_name | Optional. Name of the column where the offset is saved in the database |
| 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.
| $limit | Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. |
| $timeout | Optional. Timeout in seconds for long polling. |
| 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.
| $limit | Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. |
| $timeout | Optional. Timeout in seconds for long polling. |
| $offset_key | Optional. Name of the variable where the offset is saved on Redis |
|
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.
| $callback_query | Reference to the callback query received. |
|
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.
| $post | The message sent in the channel. |
|
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.
| $chosen_inline_result | Reference to the chosen inline result received. |
|
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.
| $post | The message edited in the channel. |
|
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.
| $edited_message | The message edited by the user. |
|
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.
| $inline_query | Reference to the inline query received. |
|
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.
| $message | Reference to the message received. |
| 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.
| DanySpin97\PhpBotFramework\CoreBot::setChatID | ( | $chat_id | ) |
Set current chat id.
Change the chat id which the bot execute api methods.
| $chat_id | The new chat id to set. |
1.8.12