![]() |
PhpBotFramework
1.0.0
A framework for Telegram Bots' APIs.
|
Methods to create a localized bot. More...
Functions | |
| DanySpin97\PhpBotFramework\Bot::getLanguageDatabase ($default_language='en') | |
| Get current user language from the database, and set it in $language. More... | |
| DanySpin97\PhpBotFramework\Bot::getLanguageRedis ($default_language='en') | |
| Get current user language from redis, and set it in language. More... | |
| DanySpin97\PhpBotFramework\Bot::getLanguageRedisAsCache ($default_language='en', $expiring_time='86400') | |
| Get current user language from redis, as a cache, and set it in language. More... | |
| DanySpin97\PhpBotFramework\Bot::setLanguageRedisAsCache ($language, $expiring_time='86400') | |
| Set the current user language in both redis, sql database and $language. More... | |
| DanySpin97\PhpBotFramework\Bot::loadLocalization ($dir='./localization') | |
| Load localization files (JSON-serialized) from a folder and set them in $local variable. More... | |
Variables | |
| DanySpin97\PhpBotFramework\Bot::$language | |
| Store the language for a multi-language bot. | |
| DanySpin97\PhpBotFramework\Bot::$local | |
| Store localization data. | |
| DanySpin97\PhpBotFramework\Bot::$user_table = '"User"' | |
| Table contaning bot users data in the sql database. | |
| DanySpin97\PhpBotFramework\Bot::$id_column = 'chat_id' | |
| Name of the column that represents the user id in the sql database. | |
Methods to create a localized bot.
| DanySpin97\PhpBotFramework\Bot::getLanguageDatabase | ( | $default_language = 'en' | ) |
Get current user language from the database, and set it in $language.
| $default_language | Optional. Default language to return in case of errors. |
| DanySpin97\PhpBotFramework\Bot::getLanguageRedis | ( | $default_language = 'en' | ) |
Get current user language from redis, and set it in language.
Using redis database we get language stored and the value does not expires.
| $default_language | Optional. Default language to return in case of errors. |
| DanySpin97\PhpBotFramework\Bot::getLanguageRedisAsCache | ( | $default_language = 'en', |
|
$expiring_time = '86400' |
|||
| ) |
Get current user language from redis, as a cache, and set it in language.
Using redis database as cache, seeks the language in it, if there isn't then get the language from the sql database and store it (with default expiring of one day) in redis. It also change $language parameter of the bot to the language returned.
| $default_language | Optional. Default language to return in case of errors. |
| $expiring_time | Optional. Set the expiring time for the language on redis each time it is took from the sql database. |
| DanySpin97\PhpBotFramework\Bot::loadLocalization | ( | $dir = './localization' | ) |
Load localization files (JSON-serialized) from a folder and set them in $local variable.
Save all localization files, saved as json format, from a directory and put the contents in $local variable. Each file will be saved into $local with the first two letters of the filename as the index. Access the english data as $this->local["en"]["Your key"]. File ./localization/en.json:
{"Hello_Msg": "Hello"}
File ./localization/it.json:
{"Hello_Msg": "Ciao"}
Usage in processMessage():
$sendMessage($this->local[$this->language]["Hello_Msg"]);
| $dir | Directory where the localization files are saved. |
| DanySpin97\PhpBotFramework\Bot::setLanguageRedisAsCache | ( | $language, | |
$expiring_time = '86400' |
|||
| ) |
Set the current user language in both redis, sql database and $language.
Save it on database first, then create the expiring key on redis.
| $language | The new language to set. |
| $expiring_time | Optional. Time for the language key in redis to expire. |
1.8.12