mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add Webhook content message
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {Button, Form, FormInstance, Input, Select, SelectProps, Space, Tag} from "antd";
|
import {Button, Form, FormInstance, Input, Select, SelectProps, Space, Tag, Typography} from "antd";
|
||||||
import {t} from "ttag";
|
import {t} from "ttag";
|
||||||
import {ApiOutlined, MinusCircleOutlined, PlusOutlined} from "@ant-design/icons";
|
import {ApiOutlined, MinusCircleOutlined, PlusOutlined} from "@ant-design/icons";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@@ -209,7 +209,7 @@ export function WatchlistForm({form, connectors, onFinish, isCreation}: {
|
|||||||
}]}
|
}]}
|
||||||
noStyle
|
noStyle
|
||||||
>
|
>
|
||||||
<Input placeholder={t`Data Source Name`} style={{width: '60%'}} autoComplete='off'/>
|
<Input placeholder={t`slack://TOKEN@default?channel=CHANNEL`} style={{width: '60%'}} autoComplete='off'/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{fields.length > 1 ? (
|
{fields.length > 1 ? (
|
||||||
<MinusCircleOutlined
|
<MinusCircleOutlined
|
||||||
@@ -219,7 +219,11 @@ export function WatchlistForm({form, connectors, onFinish, isCreation}: {
|
|||||||
) : null}
|
) : null}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
))}
|
))}
|
||||||
<Form.Item>
|
<Form.Item help={
|
||||||
|
<Typography.Link href='https://symfony.com/doc/current/notifier.html#chat-channel'>
|
||||||
|
{t`Check out this link to the Symfony documentation to help you build the DSN`}
|
||||||
|
</Typography.Link>}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
type="dashed"
|
type="dashed"
|
||||||
onClick={() => add()}
|
onClick={() => add()}
|
||||||
@@ -233,7 +237,7 @@ export function WatchlistForm({form, connectors, onFinish, isCreation}: {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Form.List>
|
</Form.List>
|
||||||
<Form.Item>
|
<Form.Item style={{marginTop: '10px'}}>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
{isCreation ? t`Create` : t`Update`}
|
{isCreation ? t`Create` : t`Update`}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
|
use Symfony\Component\Notifier\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
|
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
use Symfony\Component\Notifier\Transport\Dsn;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
@@ -50,6 +51,29 @@ class WatchListController extends AbstractController
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
private function verifyWebhookDSN(WatchList $watchList): void
|
||||||
|
{
|
||||||
|
if (null !== $watchList->getWebhookDsn()) {
|
||||||
|
foreach ($watchList->getWebhookDsn() as $dsnString) {
|
||||||
|
$dsn = new Dsn($dsnString);
|
||||||
|
|
||||||
|
$scheme = $dsn->getScheme();
|
||||||
|
$webhookScheme = WebhookScheme::tryFrom($scheme);
|
||||||
|
|
||||||
|
if (null === $webhookScheme) {
|
||||||
|
throw new BadRequestHttpException("The DSN scheme ($scheme) is not supported");
|
||||||
|
}
|
||||||
|
$transportFactoryClass = $webhookScheme->getChatTransportFactory();
|
||||||
|
/** @var AbstractTransportFactory $transportFactory */
|
||||||
|
$transportFactory = new $transportFactoryClass();
|
||||||
|
$transportFactory->create($dsn)->send((new TestChatNotification())->asChatMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
@@ -70,22 +94,7 @@ class WatchListController extends AbstractController
|
|||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$watchList->setUser($user);
|
$watchList->setUser($user);
|
||||||
|
|
||||||
if (null !== $watchList->getWebhookDsn()) {
|
$this->verifyWebhookDSN($watchList);
|
||||||
foreach ($watchList->getWebhookDsn() as $dsnString) {
|
|
||||||
$dsn = new Dsn($dsnString);
|
|
||||||
|
|
||||||
$scheme = $dsn->getScheme();
|
|
||||||
$webhookScheme = WebhookScheme::tryFrom($scheme);
|
|
||||||
|
|
||||||
if (null === $webhookScheme) {
|
|
||||||
throw new BadRequestHttpException("The DSN scheme ($scheme) is not supported");
|
|
||||||
}
|
|
||||||
$transportFactoryClass = $webhookScheme->getChatTransportFactory();
|
|
||||||
/** @var AbstractTransportFactory $transportFactory */
|
|
||||||
$transportFactory = new $transportFactoryClass();
|
|
||||||
$transportFactory->create($dsn)->send((new TestChatNotification())->asChatMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In the limited version, we do not want a user to be able to register the same domain more than once in their watchlists.
|
* In the limited version, we do not want a user to be able to register the same domain more than once in their watchlists.
|
||||||
@@ -173,15 +182,7 @@ class WatchListController extends AbstractController
|
|||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$watchList->setUser($user);
|
$watchList->setUser($user);
|
||||||
|
|
||||||
if (null !== $watchList->getWebhookDsn()) {
|
$this->verifyWebhookDSN($watchList);
|
||||||
foreach ($watchList->getWebhookDsn() as $dsnString) {
|
|
||||||
$scheme = (new Dsn($dsnString))->getScheme();
|
|
||||||
|
|
||||||
if (null === WebhookScheme::tryFrom($scheme)) {
|
|
||||||
throw new BadRequestHttpException("The DSN scheme ($scheme) is not supported");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->getParameter('limited_features')) {
|
if ($this->getParameter('limited_features')) {
|
||||||
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
|
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ class DomainOrderErrorNotification extends Notification implements ChatNotificat
|
|||||||
|
|
||||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||||
{
|
{
|
||||||
$this->subject('Error: Domain Order');
|
$ldhName = $this->domain->getLdhName();
|
||||||
|
$this->subject("Error: Domain Order $ldhName")
|
||||||
|
->content("Domain name $ldhName tried to be purchased. The attempt failed.")
|
||||||
|
->importance(Notification::IMPORTANCE_HIGH);
|
||||||
|
|
||||||
return ChatMessage::fromNotification($this);
|
return ChatMessage::fromNotification($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ class DomainOrderNotification extends Notification implements ChatNotificationIn
|
|||||||
|
|
||||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||||
{
|
{
|
||||||
$this->subject('Domain Ordered');
|
$ldhName = $this->domain->getLdhName();
|
||||||
|
$this
|
||||||
|
->subject("Success: Domain Ordered $ldhName!")
|
||||||
|
->content("Domain name $ldhName has just been purchased. The API provider did not return an error.")
|
||||||
|
->importance(Notification::IMPORTANCE_HIGH);
|
||||||
|
|
||||||
return ChatMessage::fromNotification($this);
|
return ChatMessage::fromNotification($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ class DomainUpdateErrorNotification extends Notification implements ChatNotifica
|
|||||||
|
|
||||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||||
{
|
{
|
||||||
$this->subject('Error: Domain Update');
|
$ldhName = $this->domain->getLdhName();
|
||||||
|
$this->subject("Error: Domain Update $ldhName")
|
||||||
|
->content("Domain name $ldhName tried to be updated. The attempt failed.")
|
||||||
|
->importance(Notification::IMPORTANCE_MEDIUM);
|
||||||
|
|
||||||
return ChatMessage::fromNotification($this);
|
return ChatMessage::fromNotification($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ class DomainUpdateNotification extends Notification implements ChatNotificationI
|
|||||||
|
|
||||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||||
{
|
{
|
||||||
$this->subject('Domain Updated');
|
$ldhName = $this->domainEvent->getDomain()->getLdhName();
|
||||||
|
$action = $this->domainEvent->getAction();
|
||||||
|
$this->subject("Success: Domain Updated $ldhName")
|
||||||
|
->content("Domain name $ldhName information has been updated ($action).")
|
||||||
|
->importance(Notification::IMPORTANCE_HIGH);
|
||||||
|
|
||||||
return ChatMessage::fromNotification($this);
|
return ChatMessage::fromNotification($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ class TestChatNotification extends Notification implements ChatNotificationInter
|
|||||||
{
|
{
|
||||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||||
{
|
{
|
||||||
$this->subject('Test notification');
|
$this
|
||||||
$this->content('This is a test message. If you can read me, this Webhook is configured correctly');
|
->subject('Test notification')
|
||||||
|
->content('This is a test message. If you can read me, this Webhook is configured correctly')
|
||||||
|
->importance(Notification::IMPORTANCE_LOW);
|
||||||
|
|
||||||
return ChatMessage::fromNotification($this);
|
return ChatMessage::fromNotification($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ msgstr ""
|
|||||||
#: assets/components/tracking/connector/ConnectorForm.tsx:156
|
#: assets/components/tracking/connector/ConnectorForm.tsx:156
|
||||||
#: assets/components/tracking/connector/ConnectorForm.tsx:165
|
#: assets/components/tracking/connector/ConnectorForm.tsx:165
|
||||||
#: assets/components/tracking/watchlist/WatchlistForm.tsx:109
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:109
|
||||||
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:205
|
||||||
msgid "Required"
|
msgid "Required"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -203,12 +204,12 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/components/tracking/connector/ConnectorForm.tsx:176
|
#: assets/components/tracking/connector/ConnectorForm.tsx:176
|
||||||
#: assets/components/tracking/watchlist/WatchlistForm.tsx:192
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:243
|
||||||
msgid "Create"
|
msgid "Create"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/components/tracking/connector/ConnectorForm.tsx:179
|
#: assets/components/tracking/connector/ConnectorForm.tsx:179
|
||||||
#: assets/components/tracking/watchlist/WatchlistForm.tsx:195
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:246
|
||||||
msgid "Reset"
|
msgid "Reset"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -292,7 +293,27 @@ msgid ""
|
|||||||
"that may be available soon."
|
"that may be available soon."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/components/tracking/watchlist/WatchlistForm.tsx:192
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:196
|
||||||
|
msgid "DSN"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:208
|
||||||
|
msgid "This DSN does not appear to be valid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:212
|
||||||
|
msgid "slack://TOKEN@default?channel=CHANNEL"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:224
|
||||||
|
msgid "Check out this link to the Symfony documentation to help you build the DSN"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:233
|
||||||
|
msgid "Add a Webhook"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: assets/components/tracking/watchlist/WatchlistForm.tsx:243
|
||||||
msgid "Update"
|
msgid "Update"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -300,11 +321,11 @@ msgstr ""
|
|||||||
msgid "Edit the Watchlist"
|
msgid "Edit the Watchlist"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/components/tracking/watchlist/UpdateWatchlistButton.tsx:43
|
#: assets/components/tracking/watchlist/UpdateWatchlistButton.tsx:44
|
||||||
msgid "Update a Watchlist"
|
msgid "Update a Watchlist"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/components/tracking/watchlist/UpdateWatchlistButton.tsx:53
|
#: assets/components/tracking/watchlist/UpdateWatchlistButton.tsx:54
|
||||||
msgid "Cancel"
|
msgid "Cancel"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -517,15 +538,15 @@ msgstr ""
|
|||||||
msgid "Create a Connector"
|
msgid "Create a Connector"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/pages/tracking/WatchlistPage.tsx:47
|
#: assets/pages/tracking/WatchlistPage.tsx:53
|
||||||
msgid "Watchlist created !"
|
msgid "Watchlist created !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/pages/tracking/WatchlistPage.tsx:70
|
#: assets/pages/tracking/WatchlistPage.tsx:78
|
||||||
msgid "Watchlist updated !"
|
msgid "Watchlist updated !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: assets/pages/tracking/WatchlistPage.tsx:96
|
#: assets/pages/tracking/WatchlistPage.tsx:104
|
||||||
msgid "Create a Watchlist"
|
msgid "Create a Watchlist"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user