Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement Request] Multiple webhook urls per 'webhook' #9

Open
cjthomp opened this issue Mar 28, 2017 · 4 comments
Open

[Enhancement Request] Multiple webhook urls per 'webhook' #9

cjthomp opened this issue Mar 28, 2017 · 4 comments

Comments

@cjthomp
Copy link

cjthomp commented Mar 28, 2017

What we need is the ability for a single notification-notifiable combo to have multiple destination webhooks.

Maybe check if routeNotificationForWebhook() returns an array and iterate through them?

@frkami123
Copy link

frkami123 commented Mar 29, 2017

something like this?
notifiable trait on Webhook model.

<?php
class Webhook extends Model
{
    use Notifiable;

    public function routeNotificationForWebhook()
    {
        return $this->url;
    }
}

then

$webhooks = Webhook::all();
foreach($webhooks as $wh) {
    $wh->notify(new InvoicePaid($invoice));
}

@cjthomp
Copy link
Author

cjthomp commented Mar 29, 2017

More that, say, $user->routeNotificationForWebhook() should be able to return an array (say the user has a slack webhook, zapier update, external server update, etc) of destinations instead of a single url.

So, say on WebhookChannel:33 you might do something like

if (! $urls = $notifiable->routeNotificationFor('Webhook')) {
    return;
}
$urls = !is_array($urls) ? [$urls] : $urls;

foreach ($urls as $url) {
    $webhookData = $notification->toWebhook($notifiable)->toArray();
    $response = $this->client->post($url, [
        'body' => json_encode(Arr::get($webhookData, 'data')),
        'verify' => false,
        'headers' => Arr::get($webhookData, 'headers'),
    ]);
    if ($response->getStatusCode() >= 300 || $response->getStatusCode() < 200) {
        throw CouldNotSendNotification::serviceRespondedWithAnError($response);
    }
}

It's still not perfect, optimally you'd also be able to customize the payload and/or set custom options per endpoint, but it'd be a good step (and make it usable for us)

@atymic
Copy link
Member

atymic commented Sep 16, 2019

Hi!

Sorry for the long delay.

I like the idea of this feature. Feel free to PR :)

@HDVinnie
Copy link

Would love to see this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants