PHP code example of alexvkokin / telegram-bot-app
1. Go to this page and download the library: Download alexvkokin/telegram-bot-app library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alexvkokin / telegram-bot-app example snippets
protected static $keyboardMap =
[
'Tbot/TestApp/StartController' => [
'actionStart' => [
"setButton" =>[
["icon" => 'F09F91A4', "text" => 'Профайл', "controller" => "Tbot/TestApp/ProfileController", "action" => "actionIndex"],
],
"inline" => [
["command" => '/start']
]
],
'actionGoodluck' => [
"inline" => [
["command" => '/goodluck']
]
]
],
'Tbot/TestApp/ProfileController' => [
'actionIndex' => [
"setButton" =>[
["icon" => 'E284B9', "text" => 'Информация о профайле', "controller" => "Tbot/TestApp/ProfileController", "action" => "actionData"],
["icon" => 'E2988E', "text" => 'Мой контакт', "controller" => "Tbot/TestApp/ProfileController", "action" => "actionContact", 'params' => ["request_contact" => true]],
["icon" => 'E29780', "text" => 'Назад', "controller" => "Tbot/TestApp/StartController", "action" => "actionStart"],
],
"inline" => [
["command" => '/profile'],
["callback" => 'profileGet']
]
],
'actionMessage' => [
'message' => 'Tbot/Message/Text',
],
],
];
$keyboard = [
"inline_keyboard" => [
[
[
"text" => "Вывести мои данные",
"callback_data" => "profileGet|id=5|parent_id=1",
],
]
]
];
'Tbot/TestApp/ProfileController' => [
'actionIndex' => [
"inline" => [
["callback" => 'profileGet']
]
]
]
[
'id' => 5,
'parent_id' => 1,
]
public function actionStart()
{
$keyboard = [
"keyboard" => [
Helper::keyboard(static::$keyboardMap, get_class($this), 'actionStart'),
],
"one_time_keyboard" => false,
"resize_keyboard" => true
];
$api = new ApiRequest($this->token);
$api->sendButtons($this->message->getChatId(), $keyboard, 'Добро пожаловать в наш бот');
}
Helper::keyboard(static::$keyboardMap, get_class($this), 'actionStart'),
$message_data = file_get_contents('php://input'); // получаем сообщение от телеграм бота
$tbot_key = 'API Ключ от вашего бота';
$keyboardMap = \Tbot\TestApp\AppKeyboardMap::getKeyboardMap(); // Получаем вашу карту кнопок
if ($app = new \Tbot\TestApp\StartController($message_data, $tbot_key, $keyboardMap))
{
$app->run();
}