mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Support Slack notifications
This commit is contained in:
parent
8845adaddc
commit
a78b6b1c51
@ -1067,6 +1067,7 @@ class AccountController extends BaseController
|
||||
$user->notify_viewed = Input::get('notify_viewed');
|
||||
$user->notify_paid = Input::get('notify_paid');
|
||||
$user->notify_approved = Input::get('notify_approved');
|
||||
$user->slack_webhook_url = Input::get('slack_webhook_url');
|
||||
$user->save();
|
||||
|
||||
$account = $user->account;
|
||||
|
@ -10,6 +10,7 @@ use App\Events\QuoteInvitationWasApproved;
|
||||
use App\Events\PaymentWasCreated;
|
||||
use App\Services\PushService;
|
||||
use App\Jobs\SendNotificationEmail;
|
||||
use App\Notifications\PaymentCreated;
|
||||
|
||||
/**
|
||||
* Class NotificationListener
|
||||
@ -47,14 +48,17 @@ class NotificationListener
|
||||
* @param $type
|
||||
* @param null $payment
|
||||
*/
|
||||
private function sendEmails($invoice, $type, $payment = null, $notes = false)
|
||||
private function sendNotifications($invoice, $type, $payment = null, $notes = false)
|
||||
{
|
||||
foreach ($invoice->account->users as $user)
|
||||
{
|
||||
if ($user->{"notify_{$type}"})
|
||||
{
|
||||
if ($user->{"notify_{$type}"}) {
|
||||
dispatch(new SendNotificationEmail($user, $invoice, $type, $payment, $notes));
|
||||
}
|
||||
|
||||
if ($payment && $user->slack_webhook_url) {
|
||||
$user->notify(new PaymentCreated($payment, $invoice));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +67,7 @@ class NotificationListener
|
||||
*/
|
||||
public function emailedInvoice(InvoiceWasEmailed $event)
|
||||
{
|
||||
$this->sendEmails($event->invoice, 'sent', null, $event->notes);
|
||||
$this->sendNotifications($event->invoice, 'sent', null, $event->notes);
|
||||
$this->pushService->sendNotification($event->invoice, 'sent');
|
||||
}
|
||||
|
||||
@ -72,7 +76,7 @@ class NotificationListener
|
||||
*/
|
||||
public function emailedQuote(QuoteWasEmailed $event)
|
||||
{
|
||||
$this->sendEmails($event->quote, 'sent', null, $event->notes);
|
||||
$this->sendNotifications($event->quote, 'sent', null, $event->notes);
|
||||
$this->pushService->sendNotification($event->quote, 'sent');
|
||||
}
|
||||
|
||||
@ -85,7 +89,7 @@ class NotificationListener
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendEmails($event->invoice, 'viewed');
|
||||
$this->sendNotifications($event->invoice, 'viewed');
|
||||
$this->pushService->sendNotification($event->invoice, 'viewed');
|
||||
}
|
||||
|
||||
@ -98,7 +102,7 @@ class NotificationListener
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendEmails($event->quote, 'viewed');
|
||||
$this->sendNotifications($event->quote, 'viewed');
|
||||
$this->pushService->sendNotification($event->quote, 'viewed');
|
||||
}
|
||||
|
||||
@ -107,7 +111,7 @@ class NotificationListener
|
||||
*/
|
||||
public function approvedQuote(QuoteInvitationWasApproved $event)
|
||||
{
|
||||
$this->sendEmails($event->quote, 'approved');
|
||||
$this->sendNotifications($event->quote, 'approved');
|
||||
$this->pushService->sendNotification($event->quote, 'approved');
|
||||
}
|
||||
|
||||
@ -122,7 +126,7 @@ class NotificationListener
|
||||
}
|
||||
|
||||
$this->contactMailer->sendPaymentConfirmation($event->payment);
|
||||
$this->sendEmails($event->payment->invoice, 'paid', $event->payment);
|
||||
$this->sendNotifications($event->payment->invoice, 'paid', $event->payment);
|
||||
|
||||
$this->pushService->sendNotification($event->payment->invoice, 'paid');
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ class User extends Authenticatable
|
||||
'google_2fa_secret',
|
||||
'google_2fa_phone',
|
||||
'remember_2fa_token',
|
||||
'slack_webhook_url',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -446,6 +447,11 @@ class User extends Authenticatable
|
||||
//$this->notify(new ResetPasswordNotification($token));
|
||||
app('App\Ninja\Mailers\UserMailer')->sendPasswordReset($this, $token);
|
||||
}
|
||||
|
||||
public function routeNotificationForSlack()
|
||||
{
|
||||
return $this->slack_webhook_url;
|
||||
}
|
||||
}
|
||||
|
||||
User::created(function ($user)
|
||||
|
@ -2767,6 +2767,9 @@ $LANG = array(
|
||||
'group' => 'Group',
|
||||
'subgroup' => 'Subgroup',
|
||||
'unset' => 'Unset',
|
||||
'received_new_payment' => 'You\'ve received a new payment!',
|
||||
'slack_webhook_help' => 'Receive payment notifications using Slack :link.',
|
||||
'incoming_webhooks' => 'incoming webhooks',
|
||||
|
||||
);
|
||||
|
||||
|
@ -5,11 +5,29 @@
|
||||
|
||||
@include('accounts.nav', ['selected' => ACCOUNT_NOTIFICATIONS])
|
||||
|
||||
{!! Former::open()->addClass('warn-on-exit') !!}
|
||||
{!! Former::open()
|
||||
->addClass('warn-on-exit')
|
||||
->rules([
|
||||
'slack_webhook_url' => 'url',
|
||||
]) !!}
|
||||
{{ Former::populate($account) }}
|
||||
{{ Former::populateField('slack_webhook_url', auth()->user()->slack_webhook_url) }}
|
||||
|
||||
@include('accounts.partials.notifications')
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Slack</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
{!! Former::text('slack_webhook_url')
|
||||
->label('webhook_url')
|
||||
->help(trans('texts.slack_webhook_help', ['link' => link_to('https://my.slack.com/services/new/incoming-webhook/', trans('texts.incoming_webhooks'), ['target' => '_blank'])])) !!}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{!! trans('texts.google_analytics') !!}</h3>
|
||||
@ -22,39 +40,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{!! trans('texts.facebook_and_twitter') !!}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="notify_sent" class="control-label col-lg-4 col-sm-4"> </label>
|
||||
<div class="col-lg-8 col-sm-8">
|
||||
|
||||
<div id="fb-root"></div>
|
||||
<script>(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=635126583203143";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));</script>
|
||||
|
||||
<div class="fb-follow" data-href="https://www.facebook.com/invoiceninja" data-colorscheme="light" data-layout="button" data-show-faces="false" data-size="large"></div>
|
||||
|
||||
<a href="https://twitter.com/invoiceninja" class="twitter-follow-button" data-show-count="false" data-related="hillelcoren" data-size="large">Follow @invoiceninja</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
|
||||
|
||||
<div class="help-block">{{ trans('texts.facebook_and_twitter_help') }}</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<center class="buttons">
|
||||
{!! Button::success(trans('texts.save'))
|
||||
->submit()->large()
|
||||
|
Loading…
Reference in New Issue
Block a user