Telegram Bot

dev
GeekQu 7 years ago
parent 086f4c5b58
commit 6ab5fcd17e
No known key found for this signature in database
GPG Key ID: F0EEABFCD04A5891

@ -0,0 +1,96 @@
<?php
namespace App\Utils\Telegram\Commands;
use App\Models\User;
use App\Services\Config;
use Telegram\Bot\Actions;
use Telegram\Bot\Commands\Command;
/**
* Class UnbindCommand.
*/
class UnbindCommand extends Command
{
/**
* @var string Command Name
*/
protected $name = 'unbind';
/**
* @var string Command Description
*/
protected $description = '';
/**
* {@inheritdoc}
*/
public function handle($arguments)
{
$Update = $this->getUpdate();
$Message = $Update->getMessage();
// 消息 ID
$MessageID = $Message->getMessageId();
// 消息会话 ID
$ChatID = $Message->getChat()->getId();
// 触发用户
$SendUser = [
'id' => $Message->getFrom()->getId(),
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
'username' => $Message->getFrom()->getUsername(),
];
$User = User::where('telegram_id', $SendUser['id'])->first();
if ($ChatID > 0) {
// 私人
// 发送 '输入中' 会话状态
$this->replyWithChatAction(['action' => Actions::TYPING]);
if ($User == null) {
// 回送信息
$this->replyWithMessage(
[
'text' => '您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号.',
'parse_mode' => 'Markdown',
]
);
return;
}
// 消息内容
$MessageText = trim($arguments);
if ($MessageText == $User->email) {
$User->telegram_id == '';
if ($User->save()) {
$text = '解绑成功.';
} else {
$text = '解绑失败.';
}
// 回送信息
$this->replyWithMessage(
[
'text' => $text,
'parse_mode' => 'Markdown',
]
);
return;
}
$text = '发送 **/unbind 账户邮箱** 进行解绑.';
// 回送信息
$this->replyWithMessage(
[
'text' => $text,
'parse_mode' => 'Markdown',
]
);
}
}
}

@ -20,6 +20,7 @@ class Process
Commands\PingCommand::class,
Commands\CheckinCommand::class,
Commands\MyCommand::class,
Commands\UnbindCommand::class,
]
);
$update = $bot->commandsHandler(true);

Loading…
Cancel
Save