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

Functions

 DanySpin97\PhpBotFramework\Bot::__construct (string $token)
 Construct an empy bot. More...
 
 DanySpin97\PhpBotFramework\Bot::__destruct ()
 Descruct the class.
 
DanySpin97\PhpBotFramework\Bot::getText ()
 Get the text of the message (for updates of type "message"). More...
 
DanySpin97\PhpBotFramework\Bot::getData ()
 Get the data received from the callback query (for updates of type "callback_query"). More...
 
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::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, $script)
 Add a function that will be executed everytime a message contain the selected command. 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\CoreBot::$chat_id
 Chat_id of the user that interacted with the bot.
 

Detailed Description

Function Documentation

§ __construct()

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

Construct an empy bot.

Construct a bot with commands, multilanguage and status.

§ addMessageCommand()

DanySpin97\PhpBotFramework\Bot::addMessageCommand ( string  $command,
  $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).

§ getChatID()

& DanySpin97\PhpBotFramework\CoreBot::getChatID ( )

Get chat id of the current user.

Returns
Chat id of the user.

§ getData()

& DanySpin97\PhpBotFramework\Bot::getData ( )

Get the data received from the callback query (for updates of type "callback_query").

Returns
The data of the current callback, throw exception if the current update is not a callback query.

§ 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.

§ getText()

& DanySpin97\PhpBotFramework\Bot::getText ( )

Get the text of the message (for updates of type "message").

Returns
The text of the current message, throw exception if the current update is not a message.

§ 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 and $data(use getData() to access it) set inside of this function.

Parameters
$callback_queryReference to the callback query received.

§ 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.

§ 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_messageReference to the edited message received.

§ 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 and $text(use getText to access it) 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.