mirror of
https://github.com/v2board/v2board.git
synced 2024-11-14 07:29:13 +08:00
update telegram
This commit is contained in:
parent
e3c5466c0a
commit
941289c641
@ -9,6 +9,8 @@ use App\Models\User;
|
|||||||
|
|
||||||
class TelegramController extends Controller
|
class TelegramController extends Controller
|
||||||
{
|
{
|
||||||
|
protected $msg;
|
||||||
|
|
||||||
public function __construct(Request $request)
|
public function __construct(Request $request)
|
||||||
{
|
{
|
||||||
if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) {
|
if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) {
|
||||||
@ -18,16 +20,17 @@ class TelegramController extends Controller
|
|||||||
|
|
||||||
public function webhook(Request $request)
|
public function webhook(Request $request)
|
||||||
{
|
{
|
||||||
$msg = $this->getMessage($request->input());
|
$this->msg = $this->getMessage($request->input());
|
||||||
if (!$msg) return;
|
if (!$this->msg) return;
|
||||||
try {
|
try {
|
||||||
switch($msg->command) {
|
switch($this->msg->command) {
|
||||||
case '/bind': $this->bind($msg);
|
case '/bind': $this->bind();
|
||||||
break;
|
break;
|
||||||
|
default: $this->help();
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$telegramService = new TelegramService();
|
$telegramService = new TelegramService();
|
||||||
$telegramService->sendMessage($msg->chat_id, $e->getMessage());
|
$telegramService->sendMessage($this->msg->chat_id, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +47,9 @@ class TelegramController extends Controller
|
|||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function bind(object $msg)
|
private function bind()
|
||||||
{
|
{
|
||||||
|
$msg = $this->msg;
|
||||||
if (!$msg->is_private) return;
|
if (!$msg->is_private) return;
|
||||||
$subscribeUrl = $msg->args[0];
|
$subscribeUrl = $msg->args[0];
|
||||||
$subscribeUrl = parse_url($subscribeUrl);
|
$subscribeUrl = parse_url($subscribeUrl);
|
||||||
@ -65,4 +69,16 @@ class TelegramController extends Controller
|
|||||||
$telegramService = new TelegramService();
|
$telegramService = new TelegramService();
|
||||||
$telegramService->sendMessage($msg->chat_id, '绑定成功');
|
$telegramService->sendMessage($msg->chat_id, '绑定成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function help()
|
||||||
|
{
|
||||||
|
$msg = $this->msg;
|
||||||
|
if (!$msg->is_private) return;
|
||||||
|
$telegramService = new TelegramService();
|
||||||
|
$telegramService->sendMessage($msg->chat_id, "
|
||||||
|
绑定账号\r\n
|
||||||
|
------------------------\r\n
|
||||||
|
发送:/bind 订阅地址
|
||||||
|
");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user