localmed / outbox-rails

Rails Engine for sending email, SMS, and push notifications.
MIT License
5 stars 1 forks source link

Disable sending types of messages from within notifier. #3

Open favour121 opened 8 years ago

favour121 commented 8 years ago

How can I disable sending specific messages from within a notifier action or in a before_action filter?

I want the notifiers themselves to handle the logic of deciding what type of messages to send depending on user preferences. I know I can disable sending notifications in a before_filter, but I dnt want to disable all message types, just specific ones.

petebrowne commented 8 years ago

You can use the skip_[type]! method in the notifier body. Here's an example

Alternatively: messages are only delivered to the addresses/phone numbers you give them in the audience hash. So leave out message types you don't wish to send:

UserNotifier.welcome.deliver(email: 'me@example.com', sms: '+15551234567')
# this will only send the email:
UserNotifier.welcome.deliver(email: 'me@example.com')
favour121 commented 8 years ago

@petebrowne I know about sending the types to the deliver function. What I was looking for was the skip_[type]! function.

Thanks a lot, buddy!

If you have the time there is something else. Does Outbox support the deliver_later function? How can I achieve that if it doesn't?

I wrote an Outbox client for an SMS api which I plan to make open source soon. Great work buddy!

petebrowne commented 8 years ago

Awesome, I look forward to seeing the SMS api!

I honestly haven't tested the deliver_later method. We use it in conjunction with Sidekiq and have explicit jobs for setting up and sending our notifications.

A PR to add/test that functionality would be greatly appreciated!