How do notifications work with Mailboxer gem? - ruby-on-rails

I'm trying to figure out how to setup a notifications system using Mailboxer.
I've already used it to setup an in-site messaging system so that users can message each other. Now I'd like to use it to send notifications from the site, to notify users of changes in their reputation points or remind them of actions they must complete. Something like Facebook or Stackoverflow's dropdown notification menus.
As an example, it might contain these types of notices:
User gets some points for performing an action:
"You received 50 points for helping #{user.name} with #{request.title}.
A reminder that the user must perform an action:
"You must review #{user.name}'s help with #{request.title}!
Will link to a page to complete that action.
User receives a reply to a message they sent:
"You've received a message from #{sender.name}"
Will link to the message.
Here are some details:
I don't want all notifications to send an email. Most will only need to be seen in the notifications menu. Is there an option in Mailboxer to control what is emailed, or would I have to bypass Mailboxer's mailers?
I'll want to format each type of notification differently in the dropdown. Add a specific glyphicon to each for example. Could I use the notification type field for this (using it to set a conditional)? How does type work? Can I just set it to a string, such as "reputation", depending on the notification?
Objects can be passed to the notify method. I'm confused about the purpose of this. How can that object be used? What objects would I want to send?
Feel free to leave some general info on Mailboxer notifications rather than specifically answering everything.
I've had pretty bad luck finding documentation for the notifications features, so would appreciate it if someone with some Mailboxer knowledge could chime in on this. Thanks in advance.

This is an late answer but just in case someone came upon this question like me, this is what I ended up doing.
There is an user identities method defined as https://github.com/mailboxer/mailboxer#user-identities
If it returns an email, an email will be sent. If it returns nil, no email will be sent.
There is a notify method in mailboxer, and you can use it to send notifications as,
alice.notify("Hi","Bob has just viewed your profile!")
And in mailboxer_email, check if the object is a notification or not.If it is, do not send an email.
def mailboxer_email(object)
if object.class==Mailboxer::Notification
return nil
else
email
end
end
You can defined more complex logic here such as disable email for certain type of users, etc.

Related

Send email notifications when a doc has been edited

I need a script that does the following: If any cell in a doc has been changed, then send email notification to custom address. I want the notifications sent every hour, not immediately (so if I'm editing the document- I don't want to get email every second...).
the current script I'm using is sending email notification for EVERY little change I'm doing...
Is that possible to send the notifications as a summary every hour or so?
I don't know if this is an acceptable solution for you. I did a work around for this. First I created a separate gmail account just to own docs. (This is because google does not notify when the owner makes changes.) I then forwarded the docs owner account to my outlook. In outlook I set up automatic forwarding rules to the address I wanted. I still have the problem of sending an email with every change but at least the people are informed.

How to aggregate iOS push notifications using Parse

so I'm developing an application where a user might get a notification based on some action but I only want the user to receive one notification of a specific type. An example might illustrate this better:
Say a user on facebook makes a facebook post. If someone likes the post they'll get a notification. However, if 20 different people like that post I don't want 20 separate notifications when they finally check their phone. I want one notification that says '20 people have liked your post.' I also only want to track the new notifications. Say 20 people have liked your post. I don't want the notification for the next 5 who've liked your post to be '25 people have liked your post.' I want it to be '5 new people have liked your post.'
What I don't know how to do is delete a notification that got sent using Parse. An idea I thought of off the top of my head for recording new posts was to keep track of what the user has seen for that post but that seems silly. It's a large amount of data to keep track of, compared to querying for a previous notification to that user for that channel (is that possible?).
Anyways, I was hoping other users of Parse using push notifications might've faced this problem and how you all might've gotten around it. I would like to implement my own backend but I don't have the expertise and I'm currently focused on the client side. Any help or suggestion would be greatly appreciated. Thanks!
The thing is, you have don't have the control to cancel a Push Notification. However, you do have a control when to send even how to send it. If you want to implement something like you say, you have to do custom works on that. You might observe a period of time like 2-3 minutes whether there are more than for example 10 notifications you want to send. If so, send one instead.
Before iOS 8, Push Notification did have so many limitations like we can not have our own custom action. But now, I think Apple will let us do more as time goes by.
This might not be the best way but here's how I plan on implementing the feature. I'm going to add a notifications array to the user ([Notification objects]), this will also allow me to query for notifications for a possible notifications page. Say this were facebook and the user gets a new like notification on a post (1 like total).
I will create a new notification object and add it to the User object's notifications array with properties 'seen' set to false, 'prevNotificationLikes' set to 1, and then send out a notification. The message will be generic for singular/plural #'s of likes.
If someone else likes the post before the user responded to the push notification, I will see that the user hasn't 'seen' (false) the first notification and I will not send out a new notification.
Say 19 people like the post and then the user checks the initial notification and sets the 'seen' property to true. The next notification check on the cloud code for the 21st like will query to see if there are any previous notifications for that post/user. Parse cloud will then find a corresponding notification for that post/like where prevNotificationLikes is equal to 1 and update that number to 21. If the 'seen' property is set to true, then it'll send out a notification '20 new people have liked your post.' I know that the notifications are sent 1 step late with the fact that the user probably already knows that 19 people have liked the post but it'll be a compromise to get the job done.
Any critique is welcome. Sorry for wall of text instead of code. I'm just writing out my idea before writing the code so that I have something to follow along.

Rails, check if email was sent or not

I have an app that sends email to registred users. This app sends an automatic email to the user while he is using some functions. Plus, on the admin screen, the admin can send emails to all persons that didn't get the email sent automatically for any reason. I store in database a value showing if the email was delivered or not, so the admin won't send emails to someone that already got one.
The problem is: how can I check if the email was delivered correctly in order to update this value? I am not talking about tests, I need to check right after the method deliver is called if the email was sent, or if any problem happened, like connection loss or email is invalid. Is there any method or way to do this?
Thanks.
When you send a message and no error is raised, you can assume that the mail was delivered (at least you can assume that some system accepted the responsibility to deliver your message).
Nevertheless, there are many reasons for delivery failure; sometimes you may get an error hours or even days later. You will need to have a bouncing mail address and inspect returned messages. If you want to process bouncing, inspect an open source software with bouncing treatment such as phplist. This is no so trivial as you might think.
Another alternative is send e-mails through a dedicated service such us SendGrid. This services provide APIs that will allow you to retrieve information about your messages.
You can also use the mailman gem to parse reply email messages for bad email.

Can I place an email in iOS's outbox (preferably with MonoTouch)?

I would like to place an email in the iPhones email outbox, without showing the compose window to the user, so that he can not mess with the data that I want to send. Is this possible?
Thanks,
Timo
No - if you want to send an email using the user's email account you must allow them to modify the message contents: that's part of Apple's message framework. To be honest, it's a fairly sensible feature...I don't think many people would want an app that could just send things out without alerting the user or allowing them to modify it.
If you want to send a message and stop the user from messing with your data, just add an attachment and check for the attachment on the backend (assuming that because you want to send specific data)

How to test whether a mail was sent successfully using ActionMailer?

I'm using ActionMailer in Rails 3 to send periodic emails. I need to know whether an email was sent correctly (as far as it is possible to do so).
#lists.each do |list|
email = Reminder.deadline_reminder(list)
email.deliver
end
Is there a property of the email object (class Mail::message from the Mail library) that will tell me whether the send went correctly (no connection issues, authentication problems, etc)? I've looked through the classes on Github but haven't been able to figure anything out.
It all depends on what you consider successful.
You can test to see whether your code sent the message. You can often check the log to see if the mail-forwarding host received it and moved it on toward its destination.
But, only proprietary mail systems support delivery-receipts. SMTP doesn't and probably never will because of privacy issues and the inability of the mail-client vendors to agree on how to do it. So, even if it is delivered all the way to the intended destination there's no way to know if the person read it.
Your best bet is to put a link in the message that the user clicks which will tickle an app on the server with a token that was unique for that message. When the app sees the token it sets a flag letting you know they got the message AND at least read the part about clicking the link. Then, if there has to be a response within a given time you also track when the message was sent and escalate if the token wasn't received back within the time-limit.

Resources