Discord Notifications
Send to Channel
You can send notifications to tools like Slack or Discord and even trigger workflows. To get started with receiving messages on Discord, use the following code.
You can get a custom webhook right within your Discord server settings.
site/plugins/discord/index.php
<?php
Kirby::plugin('kart/discord', [
'options' => [
'webhook' => ''; // TODO: set you webhook URL here
],
'hooks' => [
'user.create:after' => function (User $user) {
if ($user->isCustomer()) {
site()->discord([
'content' => 'NEW Customer: '.$user->nameOrEmail(),
]);
}
},
],
'siteMethods' => [
'discord' => function (array $data): bool {
$webhook = option('kart.discord.webhook');
if ($webhook) {
$response = Remote::post($webhook, [
'headers' => [
'Accept' => 'application/json',
'Accept-Charset: utf8',
],
'data' => $data,
]);
return $response->code() === 204;
}
return false;
},
],
// other options
]);