update telegram

This commit is contained in:
Tokumeikoi 2020-05-17 16:00:28 +08:00
parent 422b18ca66
commit 29d7228861
2 changed files with 9 additions and 5 deletions

View File

@ -21,13 +21,17 @@ class ConfigController extends Controller
]);
}
public function setTelegramWebhook()
public function setTelegramWebhook(Request $request)
{
$telegramService = new TelegramService();
$telegramService = new TelegramService($request->input('telegram_bot_token'));
if (!$telegramService->getMe()) {
abort(500, '机器人Token有误');
}
if (!$telegramService->setWebhook(config('v2board.app_url') . '/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token')))) {
if (!$telegramService->setWebhook(
config('v2board.app_url')
. '/api/v1/guest/telegram/webhook?access_token='
. md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token')))
)) {
abort(500, 'Webhook设置失败');
}
return response([

View File

@ -6,9 +6,9 @@ use \Curl\Curl;
class TelegramService {
protected $api;
public function __construct()
public function __construct(string $token = '')
{
$this->api = 'https://api.telegram.org/bot' . config('v2board.telegram_bot_token') . '/';
$this->api = 'https://api.telegram.org/bot' . config('v2board.telegram_bot_token', $token) . '/';
}
public function sendMessage(int $chatId, string $text, string $parseMode = '')