mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Support: Send new ticket notifications to Telegram
This commit is contained in:
parent
cdc130ecc2
commit
d7e3d2d77d
3 changed files with 50 additions and 0 deletions
|
@ -7,6 +7,7 @@ use openvk\Web\Models\Entities\TicketComment;
|
|||
use openvk\Web\Models\Repositories\TicketComments;
|
||||
// use openvk\Web\Models\Repositories\Users;
|
||||
use openvk\Web\Models\RowModel;
|
||||
use openvk\Web\Util\Telegram;
|
||||
use Nette\Database\Table\ActiveRow;
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
use Chandler\Session\Session;
|
||||
|
@ -52,6 +53,17 @@ final class SupportPresenter extends OpenVKPresenter
|
|||
$ticket->setText($this->postParam("text"));
|
||||
$ticket->setcreated(time());
|
||||
$ticket->save();
|
||||
|
||||
$helpdeskChat = OPENVK_ROOT_CONF["openvk"]["credentials"]["telegram"]["helpdeskChat"];
|
||||
if($helpdeskChat) {
|
||||
$ticketText = ovk_proc_strtr($this->postParam("text"), 1500);
|
||||
$telegramText = "<b>📬 Новый тикет!</b>\n\n";
|
||||
$telegramText .= "<a href='$serverUrl/support/reply/{$ticket->getId()}'>{$ticket->getName()}</a>\n";
|
||||
$telegramText .= "$ticketText\n\n";
|
||||
$telegramText .= "Автор: <a href='$serverUrl{$ticket->getUser()->getURL()}'>{$ticket->getUser()->getCanonicalName()}</a> ({$ticket->getUser()->getRegistrationIP()})\n";
|
||||
Telegram::send($helpdeskChat, $telegramText);
|
||||
}
|
||||
|
||||
header("HTTP/1.1 302 Found");
|
||||
header("Location: /support/view/" . $ticket->getId());
|
||||
} else {
|
||||
|
|
34
Web/Util/Telegram.php
Normal file
34
Web/Util/Telegram.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Util;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\Exception\ClientException as GuzzleClientException;
|
||||
|
||||
class Telegram
|
||||
{
|
||||
static function send(string $to, string $text, bool $webPagePreview = false): bool
|
||||
{
|
||||
$conf = (object) OPENVK_ROOT_CONF["openvk"]["credentials"]["telegram"];
|
||||
if(!$conf->enable)
|
||||
return false;
|
||||
|
||||
try {
|
||||
(new GuzzleClient)->request(
|
||||
"POST",
|
||||
"https://api.telegram.org/bot{$conf->token}/sendMessage",
|
||||
[
|
||||
"form_params" => [
|
||||
"chat_id" => $to,
|
||||
"text" => $text,
|
||||
"disable_web_page_preview" => $webPagePreview ? "true" : "false",
|
||||
"parse_mode" => "HTML",
|
||||
]
|
||||
]
|
||||
);
|
||||
} catch (GuzzleClientException $ex) {
|
||||
trigger_error("Could not send Telegram message to $to: {$ex->getMessage()}", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -65,6 +65,10 @@ openvk:
|
|||
enable: false
|
||||
client: ""
|
||||
secret: "SECRET_KEY_HERE"
|
||||
telegram:
|
||||
enable: false
|
||||
token: "TOKEN_HERE"
|
||||
helpdeskChat: ""
|
||||
eventDB:
|
||||
enable: false # Better enable this
|
||||
database:
|
||||
|
|
Loading…
Reference in a new issue