mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
feature: add telegram reply ticket
This commit is contained in:
parent
4a9367158b
commit
6a79ba5744
@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use App\Services\TicketService;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
@ -24,14 +25,13 @@ class TelegramController extends Controller
|
||||
$this->msg = $this->getMessage($request->input());
|
||||
if (!$this->msg) return;
|
||||
try {
|
||||
switch($this->msg->command) {
|
||||
case '/bind': $this->bind();
|
||||
switch($this->msg->message_type) {
|
||||
case 'send':
|
||||
$this->fromSend();
|
||||
break;
|
||||
case '/traffic': $this->traffic();
|
||||
case 'reply':
|
||||
$this->fromReply();
|
||||
break;
|
||||
case '/getlatesturl': $this->getLatestUrl();
|
||||
break;
|
||||
default: $this->help();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$telegramService = new TelegramService();
|
||||
@ -39,6 +39,27 @@ class TelegramController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function fromSend()
|
||||
{
|
||||
switch($this->msg->command) {
|
||||
case '/bind': $this->bind();
|
||||
break;
|
||||
case '/traffic': $this->traffic();
|
||||
break;
|
||||
case '/getlatesturl': $this->getLatestUrl();
|
||||
break;
|
||||
default: $this->help();
|
||||
}
|
||||
}
|
||||
|
||||
private function fromReply()
|
||||
{
|
||||
// ticket
|
||||
if (preg_match("/[#](.*)/", $this->msg->reply_text, $match)) {
|
||||
$this->replayTicket($match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getMessage(array $data)
|
||||
{
|
||||
if (!isset($data['message'])) return false;
|
||||
@ -50,6 +71,11 @@ class TelegramController extends Controller
|
||||
$obj->args = array_slice($text, 1);
|
||||
$obj->chat_id = $data['message']['chat']['id'];
|
||||
$obj->message_id = $data['message']['message_id'];
|
||||
$obj->message_type = !isset($data['message']['reply_to_message']) ? 'send' : 'reply';
|
||||
$obj->text = $data['message']['text'];
|
||||
if ($obj->message_type === 'reply') {
|
||||
$obj->reply_text = $data['message']['reply_to_message']['text'];
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
@ -124,4 +150,23 @@ class TelegramController extends Controller
|
||||
);
|
||||
$telegramService->sendMessage($msg->chat_id, $text, 'markdown');
|
||||
}
|
||||
|
||||
private function replayTicket($ticketId)
|
||||
{
|
||||
$msg = $this->msg;
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
if ($user->is_admin) {
|
||||
$ticketService->replyByAdmin(
|
||||
$ticketId,
|
||||
$msg->text,
|
||||
$user->id
|
||||
);
|
||||
}
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user