You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Malio/app/Utils/Telegram/Commands/MenuCommand.php

89 lines
2.5 KiB
PHTML

<?php
namespace App\Utils\Telegram\Commands;
7 years ago
use App\Utils\Telegram\{TelegramTools};
use Telegram\Bot\Actions;
use Telegram\Bot\Commands\Command;
/**
* Class MenuCommand.
*/
class MenuCommand extends Command
{
/**
* @var string Command Name
*/
protected $name = 'menu';
/**
* @var string Command Description
*/
7 years ago
protected $description = '[私聊] 用户主菜单、个人中心.';
/**
* {@inheritdoc}
*/
public function handle($arguments)
{
$Update = $this->getUpdate();
$Message = $Update->getMessage();
// 消息 ID
$MessageID = $Message->getMessageId();
// 消息会话 ID
$ChatID = $Message->getChat()->getId();
if ($ChatID > 0) {
// 私人会话
// 发送 '输入中' 会话状态
$this->replyWithChatAction(['action' => Actions::TYPING]);
// 触发用户
$SendUser = [
'id' => $Message->getFrom()->getId(),
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
'username' => $Message->getFrom()->getUsername(),
];
$user = TelegramTools::getUser($SendUser['id']);
if ($user == null) {
// 回送信息
$this->replyWithMessage(
[
'text' => $_ENV['user_not_bind_reply'],
'parse_mode' => 'Markdown',
]
);
return;
}
7 years ago
$reply = \App\Utils\Telegram\Callbacks\UserCallback::getUserIndexKeyboard($user);
// 回送信息
return $this->replyWithMessage(
[
'text' => $reply['text'],
'parse_mode' => 'Markdown',
'disable_web_page_preview' => false,
'reply_to_message_id' => null,
'reply_markup' => json_encode(
[
'inline_keyboard' => $reply['keyboard']
]
),
]
);
} else {
if ($_ENV['enable_delete_user_cmd'] === true) {
TelegramTools::DeleteMessage([
'chatid' => $ChatID,
'messageid' => $MessageID,
]);
}
}
}
}