return parent::beforeAction($action);
}
+
public function actionSetWebhook($on = '1')
+ {
+ $client = new Client();
+ $url = 'https://api.telegram.org/bot' . Yii::$app->params['TELEGRAM_BOT_TOKEN'] . '/setWebhook';
+ $webhookUrl = $on == '1' ? Yii::$app->params['TELEGRAM_WEBHOOK_URL'] : '';
+
+ try {
+ $response = $client->post($url, [
+ 'json' => [
+ 'url' => $webhookUrl
+ ]
+ ]);
+
+ // Проверяем, успешен ли ответ
+ $responseBody = json_decode($response->getBody()->getContents(), true);
+ if ($responseBody && isset($responseBody['ok']) && $responseBody['ok']) {
+ Yii::info("Webhook успешно установлен: {$webhookUrl}", 'telegram');
+ return "OK";
+ } else {
+ Yii::error("Ошибка установки вебхука: " . json_encode($responseBody), 'telegram');
+ return "NOT OK";
+ }
+ } catch (\Exception $e) {
+ Yii::error("Ошибка установки вебхука: " . $e->getMessage(), 'telegram');
+ return "NOT OK";
+ }
+ }
+ /*public function actionSetWebhook($on = '1')
{
return self::apiRequest('setWebhook', [
'url' => (
$on == '1' ? Yii::$app->params['TELEGRAM_WEBHOOK_URL'] : ''
)
]) ? "OK" : "NOT OK";
- }
+ }*/
// public function actionInfo() {
// self::apiRequestJson("sendMessage", ['chat_id' => "5489795686", "parse_mode" => "html", "text" => '<a href="http://www.google.ru/"><b>Hello</b></a>',