mirror of
https://github.com/v2board/v2board.git
synced 2025-06-13 13:17:52 +08:00
update: telegram bot modularization
This commit is contained in:
38
app/Plugins/Telegram/Commands/ReplyTicket.php
Normal file
38
app/Plugins/Telegram/Commands/ReplyTicket.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
use App\Services\TicketService;
|
||||
|
||||
class ReplyTicket extends Telegram {
|
||||
public $regex = '/[#](.*)/';
|
||||
public $description = '获取帮助';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
if (!$message->is_private) return;
|
||||
$this->replayTicket($message, $match[1]);
|
||||
}
|
||||
|
||||
|
||||
private function replayTicket($msg, $ticketId)
|
||||
{
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
if (!$msg->text) return;
|
||||
if ($user->is_admin || $user->is_staff) {
|
||||
$ticketService->replyByAdmin(
|
||||
$ticketId,
|
||||
$msg->text,
|
||||
$user->id
|
||||
);
|
||||
}
|
||||
$telegramService = $this->telegramService;
|
||||
$telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown');
|
||||
$telegramService->sendMessageWithAdmin("#`{$ticketId}` 的工单已由 {$user->email} 进行回复", true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user