Closed (fixed)
Project:
Push Notifications
Version:
7.x-1.2-beta1
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
24 Jun 2012 at 20:41 UTC
Updated:
17 May 2016 at 13:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
haagendazs commentedHi there. Integrating this module with Rules should be relatively simple, but I'm somewhat unsure of what the desired behavior is. Do you want to send a mass-push notification when a certain action happens, or are you planning to send individual push notifications?
Comment #2
mem-tn commentedHi,
I also think that this is an important feature, it is important to be able to send a message when something happend on the server.
can you please implement it.
+1
Comment #3
facine commented+1 to send individual push notifications.
Thanks!!
Comment #4
serkanb commentedI just needed the 'send a notification to this users on this event'-Action.
Takes a list of integers/uids and a message,
calls push_notifications_send_message with the parameters.
In case you only want to notify one user, you can give one uid as parameter and it should be fine.
Comment #5
kenwen commentedAgree that this would be a really useful feature
As a use case I would want users to be notified when a certain node type has been published and to open an app
Comment #6
jca commentedImplements integration between rules and push_notifications. The following events are given with this patch:
Comment #7
penyaskitoTagging with the sprint tags.
Comment #8
jlbellidoChanged tags
Comment #9
scotthooker commentedGood patch.
Comment #10
scotthooker commentedComment #11
haagendazs commentedLooks great, guys! Please give me a few more days to merge this and create a new release.
Excited that this feature will be available thanks to your patch!
Comment #12
scotthooker commentedI haven't tested on all platforms only ios.
Comment #13
Bevan commentedHere is another rules integration.
Comment #14
haagendazs commentedReviewed the different patches. It looks like people have different objectives for an integration with Rules: creating actions (SerkanB, Bevan) vs. creating events (jca).
@SerkanB @Bevan: For creating a simple action, SerkanB's patch looks pretty good and accomplishes the action of sending out a push notification to specific users. @Bevan: the push_notifications_send_message function expects user ids as opposed to user objects. I'm attaching a valid git patch that's almost identical to SerkanB's patch.
@jca: Do you have an actual use case for the number of rules events you created in your patch? I'm asking because it looks like you're trying to access very specific events (e.g. before token gets inserted, after token gets inserted) that seem to be targeted towards developers rather than site builders. Do you think exposing a custom hook for these actions might be more appropriate? Let me know either way and I'll wrap your changes into a single patch, including the rules action.
Comment #15
scotthooker commentedEven if they are targeted towards site builders having lots of events in rules generally is a good thing. We rely on the a lot in Commerce.
Comment #16
haagendazs commentedHere's a new patch that combines #4 and #6. This one should be patched against the latest 7.x-1.x-dev version as there were a bunch of modifications since #6 was created. I modified the wording for the rules events slighty to get them in line with the standard rules wording, the functionality from #6 should be untouched.
This patch should includes the following:
Comment #18
haagendazs commentedCommitted changes to 7.x-1.x-dev
Comment #19
dromansab commentedHi,
I'm registering token with anonymous user. How can I send a mass message to al registered tokens?
Thanks!
Comment #20
redorbit commentedMaybe a little bit late, but that`s how we send PN`s to all (anonymous) registered users based on rules events.
We are just reusing the function of the module, when a message is sent through the admin interface at "admin/config/services/push_notifications/message"
Example for IOS recipients:
1. Setup a rules event, e.g. content update
2. As action use "Custom PHP Code" and paste in the following code (payload is the notification text):
Example for Android recipients:
1. Setup the same event, e.g. content update
2. As action use "Custom PHP Code" and paste the following code:
A little bit annoying to setup the same rule two times and it`s also kind of a dirty hack, but it works.
Comment #21
ryandekker commentedSince this is already committed, I added a patch with a bit more flexibility in this issue. Would love some feedback over there. #2410077-1: PN Rules - sending to users of a role and dynamic selection of recipient
Comment #22
RyJ commentedHi,
Thanks for the patch!
Once applied, I used the code for android of comment #20 on notification payload, and 1 in array of uids.
Everything works fine, but in the notification received in the status bar of the device only the first letter of $payload is shown.
Why?
Again, thanks.
Comment #23
RyJ commentedFixed issue reported in the previous comment.
Make the following change:
$payload = "News Available";to$payload = array( 'alert' => $node->title);.Comment #24
ptmkenny commentedComment #25
anujdeo commented@redorbit:
First of all, Thanks a lot for your custom PHP code. It works and helped me:)
Just a little query.. Should $payload be an array?
Because when I tried your code- It was sending out pushes to registered devices but it was sending only first character of whatever in $payload variable.
It was also throwing waring at line 749 of push_notifications.module : "Invalid Arguments passed to foreach()"
So, I changed this line:
$payload = "News Available";To
And it works perfectly fine :)
Thanks again...
Please Note : I am very new to Drupal & PHP. So correct me iif I am wrong in above solution.
Comment #27
haagendazs commentedComment #28
Derimagia commentedThe actions here are pretty wacky. The action for sending push notification requires an array of user ids. Why can't you send it to an individual user? Why isn't it just an account or list of accounts? Right now you can't even do something like "On user login send push notification" since you need an array of ids
Comment #29
serkanb commentedIt's an array of integers because that's what push_notifications_send_message expects it to be.
As for the "I just want to notify a single use", see #4:
The event for a user login isn't really an issue of this module.
I think (without testing or looking which events exist) it should be pretty easy to create a rule which notifies an user if a user just logged in.
Where exactly did your attempt fail?
Comment #30
Derimagia commentedSorry, let me rephrase - it didn't fail it just doesn't use it's functionality currently.
The point of rules it so pass data types back and forth and to act on them not to have to make separate variables in rules for every uid you want to set a uid too.
"push_notifications_send_message" expecting uids is not a reason to not implement a function to map them like a user would expect. If this isn't for a reason I'll make a function to enhance this, but the fact that it wasn't done in the first place makes this very weird especially since it only takes a few minutes to do.
Comment #31
Derimagia commentedThe fact that push_notifications_send_message accepts a user id list is also very strange but that's obviously not related to this issue unless we were to just make that function be better at what it accepts
Comment #32
haagendazs commented@Derimagia, @SerkanB: Thanks for the comments about the Rules integration. TBH: I'm not an avid Rules user, so any feedback is welcome. And very helpful.
Derimagia, you were right. The previous action was working, but very limited to specifying an array of individual user ids. Originally, I wanted to use the push_notifications_send_message function in order to prevent creating another function, but that wasn't a good call.
I followed your suggestion and changed the action to send a message to only a single user identified by the account. Could you please review the change in the dev branch and see if this works better (see http://cgit.drupalcode.org/push_notifications/commit/?id=58a5001)? Using this change, I was able to create your example rule.
Thanks for testing.
Comment #33
Derimagia commentedI'm not a massive rules user as well but I was interested in making this work since I sometimes use rules for emails / notifications and things like that.
I ended up doing some more work on this - specific related to payloads. This may belong in it's own thread but I'll share what I did so far. It's half related to rules and half not.
Let me know your thoughts - payloads are probably something most people won't need though. So far it's worked well for me and my mobile team
Comment #34
haagendazs commented@Derimagia This looks awesome at first glance. The custom payload thing is an issue that quite a few people asked for. Could I ask you for a huge favor though: Would you mind creating a new issue for your patch? This thread has been going through so many revisions and different purposes, it's getting really unwieldy. I was hoping to get 7.x-1.2 released with just the current Rules implementation (including the fix from this afternoon).
Comment #35
Derimagia commentedUnderstood and I agree - Moved to Issue https://www.drupal.org/node/2716957
Comment #36
Derimagia commentedComment #37
haagendazs commentedThanks a lot. If you still have a minute, would you mind giving just this change a quick try and change the status if it works? I'd really appreciate it.
Comment #38
Derimagia commentedLGTM for this thread. Only small things are that it would be nice to not have a lot of functions that do the same thing with slightly different parameters (My point is petty here) and right now it doesn't allow for sending to multiple people in bulk (Push Notifications can bulk send and if you are sending to a lot of people you don't want to do it to 1 account at a time), but if the payload stuff is to be merged in it'll need to be altered anyway. You may also want to leave in the integer sending that was here before (See my patch) depending on how many people you think are using it.
Marking as Reviewed.
Comment #39
haagendazs commentedThanks for reviewing and the status change. With this latest change, you can still send push notifications to a single account identified by an integer if you switch to "Direct Input Mode" for that specific field in the action. I thought this would be useful if an admin user wants to be notified via push notification when certain actions happen.
I'll mark this issue as closed and will look at your separate issue shortly.