2023-08-30 10:37:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Service\Forms\Webhooks;
|
|
|
|
|
|
|
|
use App\Models\Forms\Form;
|
|
|
|
|
|
|
|
class WebhookHandlerProvider
|
|
|
|
{
|
2024-02-23 10:54:12 +00:00
|
|
|
public const SLACK_PROVIDER = 'slack';
|
|
|
|
|
|
|
|
public const DISCORD_PROVIDER = 'discord';
|
|
|
|
|
|
|
|
public const SIMPLE_WEBHOOK_PROVIDER = 'webhook';
|
|
|
|
|
|
|
|
public const ZAPIER_PROVIDER = 'zapier';
|
2023-08-30 10:37:08 +00:00
|
|
|
|
|
|
|
public static function getProvider(Form $form, array $data, string $provider, ?string $webhookUrl = null)
|
|
|
|
{
|
|
|
|
switch ($provider) {
|
|
|
|
case self::SLACK_PROVIDER:
|
|
|
|
return new SlackHandler($form, $data);
|
|
|
|
case self::DISCORD_PROVIDER:
|
|
|
|
return new DiscordHandler($form, $data);
|
|
|
|
case self::SIMPLE_WEBHOOK_PROVIDER:
|
|
|
|
return new SimpleWebhookHandler($form, $data);
|
|
|
|
case self::ZAPIER_PROVIDER:
|
|
|
|
if (is_null($webhookUrl)) {
|
|
|
|
throw new \Exception('Zapier webhook url is required');
|
|
|
|
}
|
2024-02-23 10:54:12 +00:00
|
|
|
|
2023-08-30 10:37:08 +00:00
|
|
|
return new ZapierHandler($form, $data, $webhookUrl);
|
|
|
|
default:
|
|
|
|
throw new \Exception('Unknown webhook provider');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|