mirror of https://github.com/MISP/MISP
Merge pull request #9021 from vincenzocaputo/add-telegram-alert-module
new: [misp-workflow-modules] Telegram alert modulebad_encoding_pymisp
commit
e0bc2d57e5
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
include_once APP . 'Model/WorkflowModules/action/Module_webhook.php';
|
||||
|
||||
class Module_telegram_send_alert extends Module_webhook
|
||||
{
|
||||
public $id = 'telegram-send-alert';
|
||||
public $name = 'Telegram Send Alert';
|
||||
public $version = '0.1';
|
||||
public $description = 'Send a message alert to a Telegram channel';
|
||||
public $icon_path = 'Telegram.png';
|
||||
|
||||
private $telegram_url = "https://api.telegram.org/";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->params = [
|
||||
[
|
||||
'id' => 'bot_token',
|
||||
'label' => 'Telegram Bot Token',
|
||||
'type' => 'input',
|
||||
'placeholder' => 'bot123:ABC',
|
||||
],
|
||||
[
|
||||
'id' => 'chat_id',
|
||||
'label' => 'Telegram Chat id',
|
||||
'type' => 'input',
|
||||
'placeholder' => '123',
|
||||
],
|
||||
[
|
||||
'id' => 'message_body_template',
|
||||
'label' => 'Message Body Template',
|
||||
'type' => 'textarea',
|
||||
'placeholder' => __('Template redendered using Jinja2'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function exec(array $node, WorkflowRoamingData $roamingData, array &$errors = []): bool
|
||||
{
|
||||
$params = $this->getParamsWithValues($node);
|
||||
$rData = $roamingData->getData();
|
||||
|
||||
$bot_token = $params['bot_token']['value'];
|
||||
$chat_id = $params['chat_id']['value'];
|
||||
$message_body = $this->render_jinja_template($params['message_body_template']['value'], $rData);
|
||||
|
||||
$data = [
|
||||
'chat_id' => $chat_id,
|
||||
'text' => $message_body,
|
||||
'parse_mode' => "HTML",
|
||||
];
|
||||
|
||||
$url = $this->telegram_url . $bot_token . "/sendMessage";
|
||||
|
||||
$response = $this->doRequest(
|
||||
$url,
|
||||
'json',
|
||||
$data
|
||||
);
|
||||
|
||||
if (!$response->isOk()) {
|
||||
if ($response->code === 401) {
|
||||
$errors[] = __('Authentication failed');
|
||||
return false;
|
||||
}
|
||||
$errors[] = __('Something went wrong with the request: %s', $response->body);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue