Closed (fixed)
Project:
Privatemsg
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Oct 2008 at 03:23 UTC
Updated:
23 May 2012 at 21:04 UTC
Jump to comment: Most recent file
Comments
Comment #1
Flying Drupalist commentedComment #2
litwol commentednote to self: make active branch to be DRUPAL-6--1 as this seems that using HEAD is confusing to people
Comment #3
berdirAnother example of how great #288183: Provide api function for other modules to send messages. is :)
Here is a first version of a privatemsg_rules integration package, which depends on the api patch. It's only hacked together, but feel free to try it out. It's actually only a few lines, biggest part are the two default configuration..
Features:
- Action: Send new message
- Action: Reply to a message
- Event: New message sent
- Default Configuration: Send a welcome message from admin (uid 1) when a new user registers
- Default Configuration: Auto-Respond to a message sent to admin (uid 1) when it's an new thread
Limitations:
- Currently, Rules can't handle arrays/multiple values, so it's not possible to send a message to multiple users. However, answering a thread with multiple recipients is possible (because there is a separate reply function.. ) and the "new message sent"-event will be triggered once for each recipient
Please report if there are bugs, missing features or simply that it works ;)
Comment #4
Flying Drupalist commentedShould I be using this to handle email, or the code in the email thread?
Comment #5
berdirDepends :)
First, this is is just hacked together, and hasn't really been tested yet. Especially, I haven't tested to send e-mails but it should/might work. Also, this needs Rules as a dependency, and you have to know Rules quite a bit to make a useful notification email, especially with configuration in mind (Not every users wants email notification...).
On the other hand, the email notificiation module is a simple install & go module (Well, it will be when it will be using "my" api instead of defining its own hook). It just works, user-level configuration included.
Comment #6
bensemmel commentedHi,
I tried the API and the rules integration patch and everything works as expected. I implemented email notification using rules without any problems.
Thank you very much for all your work on this module
Regards,
Ben
Comment #7
liliplanet commentedThank you for the Rules integration ..
I cannot seem to make the php token's to work. The <? echo 1+1?> works great :)
Is this correct?
Just receive empty token values ..
Look forward to your reply and again, thank you.
Lilian
Comment #8
berdirYou need to output the variables and it has to be valid PHP code, for example
<?php print $recipient;?>(note the semicolon at the end). While it's a bit more to write, I really suggest to use "<?php print" instead of the shorthand "<?=", because the latter can be disabled in the php.ini configuration.Comment #9
aharown07 commentedMy issue #406088: Expose "send message to this user" to Actions (and Views) has been marked as a duplicate of this one.
Here's where I am though: can't really make sense of the Rules config. The "sending a message" action doesn't seem to allow for a "when a link is clicked to send one" condition. Rather, it seems more designed to make messages go out automatically when a variety of other things happen. I'm just looking for a "send a PM to to this user" link I can display in a View.
If there's a way to do this using Rules, I'm not seeing it.
(Edit: doesn't help that the Rules handbook appears to be broken... no tutorials at all, for example)
Comment #10
berdirAn action is something pre-configured. For example, you could create a ruleset with Rules which approves a node and sends a private message to the author to tell him that his node was approved. But it does not work with the current module, because a) there is no send message to author action available and b) integration of VBO with Rules seems to be a bit broken at the moment, I need to test that with the -dev version.
However, if you just want to display a link, you can do that inside a theme function. Add the user/author uid field to the view and create a theme function/template for that field. You can then load the user object for that uid and pass it to http://blog.worldempire.ch/api/function/privatemsg_get_link/1. This function will return the link to the new message form, which you can display with http://api.drupal.org/api/function/l/6.
Comment #11
aharown07 commentedThanks, Berdir. I understand the gist of what you're saying but I've never written a theme function (I have cut and pasted a few others wrote and posted). Is it in the roadmap anywhere to add send-message-to-author action to PrivateMsg?
Comment #12
berdirI am currently testing such an action, but I'm quite sure this is not what you want, because you can only send a previously defined, more or less static message.
We will maybe add such a views integration (what you want is views integration, not action/rules) later on, but if you want it now, you need to write a simple theme function.
Comment #13
aharown07 commentedYes, sounds like Views integration is what I'm after. Will have to see if I can figure out how to write the theme function.
Comment #14
atelier commentedThe rules integration seems to be working fine.
Is it possible to select a different user other than admin (uid 1) as the default sender?
Comment #15
berdir#14.
Sure, if the uid is either fixed or provided by the executed event. In my example, the uid 1 user is loaded as a hardcoded action, check out the provided example.
Comment #16
atelier commentedThanks for the quick reply, Berdir. I'm new to Rules so I didn't realize you could "Load a user account" as an action. After I added this action, it worked perfectly. Thanks again.
Comment #17
tsi commentedHello,
I have two problems :
1. I don't see your example rules anywhere.
2. The welcome message can only be sent by the user itself (acting or registered), which make no sense.
Thanks !
Comment #18
berdir1. Seems that the name of the hook is wrong, attached is a new version.
2. No, they can be sent by any userl, check out the comments above.
Comment #19
tsi commentedI still don't see the example rules, am I missing somthing ?
Comment #20
liliplanet commentedThank you Verdir for your last suggestion ..
I'm still struggling with the following:
1. The subject shows in the email, but not the recipient or the author.
2. Also after a ?> the email does not create a line break
Would most appreciate any further help, and thank you so much.
Lilian
Comment #21
atelier commentedCan this be rolled into the next release, as well?
Comment #22
manop commentedI might get something wrong. I got the message
Fatal error: Call to undefined function privatemsg_new_thread() in .../sites/all/modules/privatemsg_rules/privatemsg_rules.module on line 287
Comment #23
manop commentedThat's my mistake, I forgot the API. It works perfect now.
Comment #24
mr.andrey commentedI get the following errors after sending a message:
This is my subject:
And this is my message:
And this is what I actually get in the mail:
Any ideas?
Andrey.
Comment #25
berdir$recipient and $author is a user object, to display the name, you need to use $recipient->name.
Also, this needs to be rerolled because of changes in the latest -dev snapshot of privatemsg.
Comment #26
mr.andrey commentedGot it. It works well now, thanks.
Andrey.
Comment #27
tsi commentedtried it with the latest 1.x-dev dated 2009-Apr-28 and got the following error when creating a new user :
Fatal error: Unsupported operand types in ...\privatemsg\privatemsg.module on line 1164
should it work with the latest -dev ?
API is already included isn't it ?
Comment #28
berdirThere was a change in the API, I need to re-roll this module.
Comment #29
bensemmel commentedHi Berdir,
thank you again for taking care of this. Can you estimate when you will have the time to re-rol the module?
Regards,
ben
Comment #30
naheemsays commentedsee next post...
Comment #31
naheemsays commentedHere is an updated version of the module - Not tested as I had assumed it integrated with actions/trigger.
Just wondering what the benefit of rules integration over the action/trigger in core is?
(I have used neither... apart from setting a single action once via action/trigger and then removing it.)
Comment #32
berdirRules is *way* more flexible and can do more things. For example, trigger/actions doesn't have conditions.
I try to update the version soon, I have a version that should be working, but I need to test it a bit before I can upload it.
Comment #33
liliplanet commentedHi Berdir,
Thank you for this stunning enhancement to Private Message.
Is it perhaps possible to add the token realname (http://www.drupal.org/project/realname) instead of php echo $recipient->name where it would only be the username and not the full name. Or perhaps a cck token? (which would be for instance 'first name') using content_profile.
Would be much more personalized.
All the best,
Lilian
Comment #34
berdirPlease test the updated module.
Note that there is currently a bug with the reply functionalitity, that's not an issue of rules integration. (replies are sent as new threads)
Comment #35
berdirAnd now with attachment...
Comment #36
brad mering commentedI'm not sure if this is helpful to anyone else. I extended Berdir's code to allow you to trigger a PM to every member of a role. I used the structure of the system.roles.inc action that sends emails to everyone in the role. A very useful feature, at least to me.
Berdir, thanks for your work on this. Rules integration isn't the easiest.
Comment #37
brad mering commentedFound a bug. Here's a modified version.
Comment #38
zanhsieh commentedI tried privatemsg_rules_4.tar_.gz and privatemsg_rules2.tar_.gz. Both of them will cause my test site show following warning messages:
* warning: Illegal offset type in C:\xampp\htdocs\testsite\includes\form.inc on line 1363.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\includes\form.inc on line 1363.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 193.
* warning: Illegal offset type in isset or empty in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 77.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 194.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 197.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 193.
* warning: Illegal offset type in isset or empty in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 77.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 194.
* warning: Illegal offset type in C:\xampp\htdocs\testsite\sites\all\modules\rules\rules\rules.module on line 197.
Could anyone help me out? Thanks.
Comment #39
naheemsays commentedwhat version of privatemsg are you using? It would probably need to be the latest 1.x-dev nightly for the rules integration to work properly.
Or there might be a bug - not tested this module.
Comment #40
naheemsays commented[deleted]
Comment #41
brad mering commentedZanhsieh,
I've used both of those on drupal 6.12 running the latest dev build (June 23, 2009). I don't see any of the errors you report. Significant work has been done on the module since the last release (rc2). The current dev build seems very stable to me. I'm using it on a site in the last stages of beta testing, and I would have no problem using it in my production site, barring a last minute bug. You'll also get significant added functionality, including an email notify module that lets users control their own notification status.
Try out the dev build and let me know if you're still seeing those errors.
brad
Comment #42
jgarbe commentedBit of a nubbin here, but bear with me. I've installed the latest dev release and rolled with the extra module provided by brad of #37. Works good! No errors; good mojo. In terms of options for who the message goes to, though, here's my use-case scenario:
1. User creates node, content type Proposal Request. One of the CCK fields in the content type is a username user reference for the recipient (I'd love to have that be a real name, but baby steps, baby steps)
2. User saves.
3. A private message is sent to the recipient specified in that CCK field, saying "New Proposal Available" with a link to the node.
Can someone give me a general idea of where to bark to achieve this? I'm going to hack at it myself and see if I can figure it out, but as evidenced by this incredibly useful module and add-on, you guys are way better than me at this!
Thanks for all the great work!
Comment #43
zanhsieh commentednbz & brad,
I tried 6.x-1.0-rc2 & 6.x-1.x-dev and both got the same message as above. Drupal version is 6.10. Also, if I only enable Privatemsg Email Notification, the system will give me the same warning.
Thanks.
Comment #44
brad mering commentedZanhsieh,
Sorry still can't duplicate the problem. I'm running 6.12 and don't have time today to set up a 6.10 install to test. I might get a chance to try to duplicate over the weekend.
Jgarbe,
The user reference module comes with some rules stuff already built in. Add the action "Load a Referenced User" and weight it so it occurs before you send a message out. You can then reference that user either as the sender or recipient. You should be able to do this, I think, without writing a lick of code.
Brad
Comment #45
zanhsieh commentedBrad,
I figured out what the problem is. In order to use the patch and Private Msg Email Notification, the individual must use Rules module 6.x-1.x-dev. But I don't get any luck on Private Msg Rules integration so far (same warning message).
Comment #46
jgarbe commentedI'm now up to manop's stage in comment #22, #23. Would anyone mind shedding some light on the API patches, or should I ask in that thread? I'm seeing now that the latest patch (privatemsg.api_8.patch) has these lines in it:
--- privatemsg.author-pane.inc 6 Jan 2009 16:05:48 -0000 1.1.2.1
--- privatemsg-view.tpl.php 19 Dec 2008 06:09:50 -0000 1.1.2.2
and none of those files exist in privatemsg-6.x-1.0-rc2. They do exist in privatemsg-6.x-1.x-dev but the api is a .php file in the module root, not an .inc in its own folder.
Even with all these things aside, I'm still getting hash failures. Help?
Here's the link to the API thread: http://drupal.org/node/288183
Comment #47
berdirNot sure what you are talking about.
- My patches are *always* against the -dev version.
- There is no 6.x-1.0 release ;)
Just use the -dev release, there is no need to apply any other patches, just untar this into your privatemsg folder, enable it and it should work. I had never issues with differen rules version, but I don't use Rules regularly and that might be a possible reason for your problems.
Comment #48
jgarbe commentedWow thanks for the reality check, Berdir. I did just that...and everything's copacetic now. Thanks a million!
Everything with this is working just peachy for me. I've got private messages firing off to user-based CCK fields upon content type creation. Thanks everyone for your hard work!
Comment #49
drupup commentedI've installed the _4.tar.gz patch, and messages sent to "trigger" users are working great.
However, I'm getting errors when I try to use the "send to all user of role" action.
•warning: in_array() [function.in-array]: Wrong datatype for second argument in /home5/communs2/public_html/ecov/sites/all/modules/privatemsg/privatemsg_rules/privatemsg_rules.module on line 332.
•warning: implode() [function.implode]: Invalid arguments passed in /home5/communs2/public_html/ecov/sites/all/modules/privatemsg/privatemsg_rules/privatemsg_rules.module on line 336.
•user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT DISTINCT u.uid FROM ecov_users u INNER JOIN ecov_users_roles r ON u.uid = r.uid WHERE r.rid IN () in /home5/communs2/public_html/ecov/sites/all/modules/privatemsg/privatemsg_rules/privatemsg_rules.module on line 338.
This is a Drupal 6.13 installation and Privatemsg is using the 6.x-1.x-dev, though the same thing happens when I switch back to the rc3. This is the only problem I've noted with the 6.x-1.x-dev, and I've been testing it out quite a bit.
By the way....YES, brad mering, this is a very useful extension. It would be really cool if there could be an action to notify a specific user, since then I could specifically target the site admin, but role-based messaging essentially accomplishes the same thing, since the admin will be the only user in that role. Would be a nice UI feature if you removed the "arguments configuration" block from the form: I'm assuming that doesn't pass values to this function, but it's potentially confusing for the user....?
Berdir, thanks again for the work on this module. I may never use e-mail notification again.
Comment #50
berdirI will try to reproduce that bug.
Regarding single user, see comments #14-#16, there should be an action "Load a user account", which you can use to load uid 1 for example and use that in a later acton.
Comment #51
chaloalvarezj commentedI really like privatemsg and integrating with rules will make very powerful. So far only one event is available: New message sent.
I would like to see something like: New reply sent and/or provide a way to discern between sending a message or replying to a message.
If this functionality is already provided, please guide on how to implemented because so far cannot tell if a message is a new message or a reply.
Cheers
Comment #52
berdirYou can do that by checking thread_id and mid. If they are the same, it's a new thread. One of the examples is already doing that.
Comment #53
chaloalvarezj commentedThank you for your reply Berdir, I will check that up..
Comment #54
drupup commentedAh, you are absolutely right...load your user and everything works properly. Rules just keeps getting better and better as more modules integrate. As always, thanks for the quick response.
The role-based approach would still be a useful alternative. Man, I went a whole week without bringing up a warning screen!
Comment #55
R.Hendel commentedsubscribe
Comment #56
ycwjjjj commentedsubscribe
Comment #57
socialnicheguru commentedsubscribing
Comment #58
mgenovese commentedAny chance this can be a real module on Drupal.org versus living in a thread? IMHO it's a rather important piece of functionality and should be living in the modules area.
Also (for the developer, in particular), is there any reason this module wouldn't work with Drupal 5.x? It is stated to require 6.x.
Thanks.
(EDIT: OK, looks like the Rules module is only for 6.x. That answers that question. Looks like 5.x would be relegated to Workflow-ng.)
Comment #59
litwol commented#58 it will be included in privatemsg distribution once its been thoroughly tested. When after a few weeks it still works well on your site, please come back and mark this thread as 'Reviewed and tested by the community'.
Comment #60
mgenovese commentedThanks. If there was a 5.x version that used Workflow-NG instead, I'd be happy to test it. My production site is 6000+ users in Drupal 5.x.
Comment #61
litwol commentedWe offer a good upgrade path from d5 to d6. consider switching. once we open d7 development branch d5 will be completely removed from the project page. I recommend upgrading now while we somewhat support it before we stop.
Comment #62
mgenovese commentedMy site is big + complex enough that moving from 5.x to 6.x isn't possible right now since I'm a one-man show. Trust me, I've already considered it. Enough of the modules I use are stable in 5.x, but still in dev or n/a in 6.x, which has precluded me from moving....though other modules I use are being EOL'd for 5.x. So I'm screwed either way.
Eventually it will happen though. In the mean time, I'll look at doing the workflow_ng route. If it works, I'll post the code for other 5.x folks.
Comment #63
yajnin commentedsubscribe
Comment #64
liliplanet commentedThis works for me :)
Comment #65
mnlund commentedIs this planned to go in as a contrib module of privatemsg? If not maybe it would be a good idea to make it a standalone project here on drupal.org. The functionality privatemsg_rules provide is amazing. It's pretty funny to send messages on rules actions.
Comment #66
tobiberlinWhat is the level of this issue, any development?
Comment #67
berdirAs it is a separate sub-module and therefore easy to install, my focus lies currently (privatemsg 1.x) on issues that require patches.
My plan is to add this to privatemsg 2.x. This means once a stable 1.0 release has been published. I will write more about this soon in #372201: Roadmap for official 1.0 release.
AFAIK, this module does work as it is. If there are bugs or missing features, feel free to post them here and try to be as detailed as possible.
Comment #68
crea commentedGoing to try this. Btw, most Rules hooks should go in modulename.rules.inc file, so Rules dynamically includes it when necessary. This allows to save some memory.
Comment #69
berdirThanks, I've already changed that in an updated version of the module but haven't uploaded it yet.
Changes:
- Tagging support. That means you can add tags to a message with rules.
- Moved almost everything to privatemsg_rules.rules.inc
- Some bugs fixed.
Comment #70
infojunkieI wrote a modified version of
privatemsg_rules_newto specify the format of the message body in the action. It would be great to add this feature here.In my scenario, it was fine to hard-code the format in the action's code, but in general, I don't know how to add an input filter element form to a Rules action form.
Note that in this case, you will need to impersonate the author (http://drupal.org/node/218104) when calling
privatemsg_new_thread, in order for the pm_email_notify.module call todrupal_html_to_text(check_markup($message['body'], $message['format']))to work correctly given the specified author's filter permissions.Comment #71
berdirYou are more than welcome to extend my last version and upload it here. I'm not sure either how to implement the format either, you can just upload what you have for now and then we can improve it.
Edit: Thanks for the hint regarding check_markup() and global $user. I haven't understood those access checks before, but they aren't necessary, this is a bug. See http://drupal.org/node/634632. Once that other issue is commited (and it will be commited before 1.0), you will not have to impersonate the user anymore.
Comment #72
rburgundy commentedsubscribing - looking forward to testing any development in this area.
Comment #73
coloryan commentedWelcome Message Issue:
I'm having a hard time getting this to send a welcome message to new users. The rules is working in debug, and I've added a 'send to admin' along with the registered user. The admin gets the message, but the new user doesn't.
Here's a copy of the debug:
* Signing up for newsletter.
*
o 0 ms "User account has been created" has been invoked.
o 0.096 ms Executing the rule "Send welcome message with privatemsg when a new user is created" on rule set "User account has been created"
o 0.23 ms Action execution: "Load a user account"
o 1.614 ms Successfully added the new variable "Admin User (uid 1)"
o 2.304 ms Action execution: "Send a message" <--- new user, doesn't send.
o 2.511 ms Action execution: "Send a message" <--- same message to admin, sends.
o
+ 902.65 ms "A message is sent" has been invoked.
+ 902.799 ms Executing the rule "Auto-Respond a message to UID 1" on rule set "A message is sent"
+ 903.186 ms Condition "Recipient is uid 1" evaluated to TRUE.
+ 903.346 ms Condition "First message of thread" evaluated to TRUE.
+ 903.545 ms Action execution: "Reply a message"
+
# 1258.969 ms "A message is sent" has been invoked.
# 1259.171 ms Not executing the rule "Auto-Respond a message to UID 1" on rule set "A message is sent" to prevent recursion.
# 1259.239 ms Evaluation of "A message is sent" has been finished.
+ 1259.741 ms Evaluation of "A message is sent" has been finished.
o 1260.039 ms Evaluation of "User account has been created" has been finished.
* Created a new user account for test5. No e-mail has been sent.
Comment #74
berdirMaybe the new user does not have permission to read messages?
Comment #75
coloryan commentedNo, it's all there. They get the second rule that's an auto-reply from the admin.
Here's an exported version of the rule:
Comment #76
berdirHm..
your best bet is probably to var_dump() what's returned by the privatemg_new_thread() call inside the function privatemsg_rules_new() in privatemsg_rules.rules.inc. The function should look like this:
Of course, instead of var_dump (which is only really great if you have xdebug enabled), you can also use dpm() from devel.module or any other function to print an array.
That output should then either include the sent message or one more errors if sending failed for some reason.
I'll think about how I can integrate that into the rules debug output as that would be really helpful.
Comment #77
coloryan commentedGo figure... this one works. I added a new one, step by step. Maybe it didn't like the '?' in the message?
Comment #78
Bilmar commentedHello, thank you for the great work towards further integration of Privatemsg with Rules.
I tested the module at #69 and setup a rules as below.
I would like to essentially have a privatemsg message sent to the user upon an event.
Event: Flag - A node has been flagged under "watch list"
Action: Send a message
-Recipient: User who initiated the request
-Author: User who initiated the request
-Subject: Hello
-Body text: Test, node was flagged
After the event occurred, I checked Messages but do not see any message as the rule was setup to send.
Any ideas or can anyone replicate this issue with Send a message action?
*EDIT* I'm using Privatemsg 6.x-2.x-dev (2009-Dec-08). I see this thread says 6.x-1.x-dev. I will try to change my version to see if problem still occurs.
Comment #79
berdirThere aren't many differences between 2.x and 1.x yet. Also, this will be targeted against 2.x soon as that will be the release that will also include this.
Try to enable debug messages to see if your rule is actually called. I'll extend this soon to include more debug information about the sent message.
Comment #80
berdirAdded some logging calls, if your rules don't work, enable "Debug rule evaluation" at admin/rules/settings and it should show if the messages could be sent and if not, why.
Changing the version but it should still work with 1.0
Comment #81
Bilmar commentedThank you Berdir - I will be testing the new version of the module this week and will use "Debug rule evaluation" if I come across any issues.
Comment #82
BenK commentedSubscribing...
Comment #83
fizk commentedThis thread is over a year long....let's add this to privatemsg/privatemsg-dev asap!
Comment #84
BenK commentedHey everyone,
I just completed some extensive testing of Berdir's patch in #80 and it works very, very well. I was able to send a private message on a system event, tag that message with a keyword on a conditional basis (both for the sender and the recipient), and automatically reply to that message conditionally, too. All of this worked with a variety of conditions and on a variety of system events.
In my testing, I just noticed three minor issues:
1. What's the difference between the "send a message" action and the "send a message to author of a specific content" action? As far as I could tell, I could just use the generic "send a message" action and specify the content's author as the recipient, rather than use the more limited "send a message to author of a specific content" action. What is the difference in use case between the two?
2. When executing a rule involving a private message, I'm getting the following error message in my Drupal log (admin/reports/dblog):
"Object of class stdClass could not be converted to string in /xxx/xxx/xxx/public_html/includes/bootstrap.inc on line 774."
This error message doesn't affect any functionality and doesn't display to the user... it's only in the log. I've confirmed that it is only occurring when the rule fires.
3. When viewing debug information for Rules, the "Tag a privatemsg thread" action isn't displaying complete debug information. The debug info shows that a thread is being tagged, but it omits the name or id of the specific tag being applied. As a result, the debug info reads: "Tagging [threadid] with for [user]." It would be better if the actual tag displayed between the words "with" and "for."
Anyway, this is all pretty minor stuff... this Rules integration really is terrific and works beautifully.
Cheers,
Ben
Comment #85
berdirAwesome, thanks for testing.
I'm pretty sure that 3 is the reason for 2, I'm probably using trying to insert an object instead of a string when displaying the debug message.
And you are correct, send " a message to author of specific content" is useless, I'll remove that. Not sure why I've added that.
Comment #86
berdirOk, small update that resolves the reported issues.
- Removed the unecessary action
- Renamed the tag/load_tag actions so that they have a privatemsg_rules as function name, you need to update your rules if you are using those.
- Fixed the tag debug message, this should resolve 2 & 3 from above.
Please test and then we can finally add this to privatemsg!
Comment #87
BenK commentedThanks, Berdir, for making the changes/updates so quickly. I'll test again later today so that we can get this committed ASAP.
Just one quick question: When you say "you need to update your rules if you are using those," does that just mean re-saving the rule and clearing the site cache? Or do I actually need to delete the individual actions and then re-create them?
Best,
Ben
Comment #88
berdirI renamed the internal name of two of the actions (because they weren't prefixed with privatemsg_rules) so Rules will probably not find those that are defined in your configuration anymore. It should report those that are broken and you can then re-create them.
Comment #89
BenK commentedHi Berdir,
I've just tested the new version of the module that you posted in #86 and can confirm that all three issues I previously noted have now been fixed. Great work.
So I think this module is now ready to be officially committed to the 6.x-2.x-dev branch as soon as you have a chance.
Thanks again,
Ben
Comment #90
berdirCommited to 6.x-2.x-dev, needs to be ported to 7.x-1.x!
Comment #91
Flying Drupalist commentedYay, thank you all!
Comment #92
YK85 commentedI was not able to find !message (URL) and !settings (URL) variables to add in a message at "Send a message" Action in Rules. I have open the feature request at #704250: Rules Integration Email Notify Message Variables.
I am needing to replace Email Notify with Rules to utilize different Conditions for the notifications.
Please let me know if I am just not seeing this in the message Action page. Thanks!
Comment #93
hanamizuki commented+1
Comment #94
ethnovode commentedHello, I upgraded from 1.1 to 2.x-dev because of the rules support that seems pretty nice.
Like zanhsieh in #38, I just had these warnings and they were gone after I flushed the cache but they are back.
Sometimes, only the first warning shows.
I use Drupal 6.16 (php 5.2.3) and Rules 6.x-1.2.
Also, my /admin/rules/trigger now throws an error :
Fatal error: Unsupported operand types in /srv/d_lce/www***/htdocs/sites/all/modules/rules/rules/rules.module on line 348Thank you for this very nice module.
Comment #95
berdirOpen a new bug report, this issue is about D7 now.
Comment #96
BenK commentedHey Berdir,
I'm about to start testing the Private Message 7.x version... just wanted to check in first. Has any attempt been made yet to port rules integration to PM 7.x?
Thanks,
Ben
Comment #97
BenK commentedBerdir,
I've begun some pretty extensive testing of the Private Message 7.x-dev branch... recently posted various bugs in the issue queue.
Since the Rules 7.x-2.x-dev branch is quite solid now, I'd love to start testing Private Message's rules integration in 7.x as soon as we can get a 7.x port....
--Ben
Comment #98
berdirI've started a port and message action/event works, but I'm having some issues figuring out the more complicated tag stuff. If you have any links which document the api changes, please post them here, I haven't found anything.
Also, don't expect too much activity in the next days, my exams are starting in two days and I need to focus on them a bit more ;)
Comment #99
BenK commentedHere's a link to a recent thread where Rules API changes (from 6.x-1.x-dev to 7.x-2.x-dev) are discussed:
http://drupal.org/node/832046
As you'll see from fago's comments on the thread, he's recently marked it as critical to get more docs asap. But in the meantime, he jotted down some of the biggest changes in comment #2.
Also, the Rules 7.x-2.x-dev module itself appears to have some documentation in the rules.api.php file. I've attached the file to this comment (renamed it with a .txt extension) so that it's handy for reference.
--Ben
Comment #100
BenK commentedOops, I forgot to attach the rules.api.php file to my last comment. It's attached to this one...
Comment #101
berdirThanks, I will look into it. From what I see, I've addressed most of that already, mainly the custom data handling stuff is missing.
Comment #102
BenK commentedHey Berdir,
I was going to start testing D7 Rules integration, but when I went to look at the latest 7.x-dev version (which I have installed), I didn't see any "Privatemsg rules" sub-module. I know you said you've done some work on the port already... are you keeping the code somewhere else?
Thanks,
Ben
Comment #103
BenK commentedJust bumping this so I don't lose track of it...
Comment #104
BenK commentedJust a thought since I've been working on testing the new D7 token integration lately: We need to make sure that the Rules Integration for D7 works with our token integration. That includes having Token module's token browser show up on the Rules configuration page (for a Private Message action) and for the Private Message supplied tokens (for author and recipient) to be available.
Also, I'm not sure how Private Message's use of tokens will relate to Rules' own use of tokens. For instance, when creating a "Send a private message" Rules action as part of a Rules set, we may first want to make a "Load a Node ID" Rules action so that we can use tokens for that node in our message.
For instance, let's say the triggering event is someone creating a new node: We may want to be able to use a token for the node title in our Private Message subject and/or message body. So I'm assuming that we could make a Rules action to load the node ID and then use some type of Rules action to make the nid:title token available. Then, we could use that token in our message. I'm hoping that Rules would replace that token before it gets to Private Message and then Private Message would replace its own tokens. But I'm not totally sure about if this will work out of the box or if some coding for this will be necessary.
--Ben
Comment #105
berdirOk, attaching an initial version.
What works:
- Send/reply private message action
- private message sent event
Other stuff like everything that involves tagging does not yet work.
No diff since there is something strange, it tries to diff against the rules files of the 6.x-2.x release. Just extract the content of that archive into the privatemsg folder.
Comment #106
BenK commentedHey Berdir,
Thanks for the port! I started testing of this, but noticed the following error that prevented me from going deeper into the testing. To create this error, I used the "A message is sent" event and created a "Send a message" action on that event. Here's the error message I got:
Recoverable fatal error: Argument 2 passed to t() must be an array, boolean given, called in /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc on line 1822 and defined in t() (line 1414 of /Users/benkaplan/git/drupal/includes/bootstrap.inc).
Note that the original message I sent was sent successfully (although I didn't get sent to the redirection page because of the error). But that rules-generated message in response was not sent.
Also, I didn't get this error message initially (even though the rules-generated message was also not sent)... I only seemed to get it when I turned on Rules debug info in the Rules settings. So I'm not sure if turning on debug info is required to see the error.
--Ben
Comment #107
BenK commentedPer our discussion in IRC, I upgrade my Rules code to the latest version. I received the same fatal error except that the line number of the error changed in latest code. Here's the error I got most recently:
Recoverable fatal error: Argument 2 passed to t() must be an array, boolean given, called in /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc on line 1898 and defined in t() (line 1414 of /Users/benkaplan/git/drupal/includes/bootstrap.inc).
--Ben
Comment #108
BenK commentedPer Berdir's instructions in IRC, here is the more detailed debug info:
Debug: array ( 0 => 'Reacting on event %label.', 1 => array ( '%label' => 'A message is sent', ), 2 => 1, 3 => 1281384068.82, 4 => true, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
Debug: array ( 0 => 'Evaluating rule %label.', 1 => array ( '%label' => 'Privatemsg Rules Event', ), 2 => 1, 3 => 1281384068.83, 4 => NULL, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
Debug: array ( 0 => 'AND evaluated to TRUE.', 1 => array ( ), 2 => 1, 3 => 1281384068.83, 4 => NULL, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
Debug: array ( 0 => 'Evaluating the action %name.', 1 => array ( '%name' => 'privatemsg_rules_new', ), 2 => 1, 3 => 1281384068.84, 4 => NULL, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
Debug: array ( 0 => 'Writing new message with subject This is the subject of Rules message. The author is [user:name]. The recipient is [user:name]. to Ben Kaplan from person1', 1 => array ( ), 2 => 1, 3 => 1281384068.84, 4 => NULL, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
Debug: array ( 0 => 'Message not sent, reported error: Disallowed to send message because all recipients are blocked', 1 => array ( ), 2 => 1, 3 => 1281384068.84, 4 => NULL, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
Debug: array ( 0 => 'Warning message reported when trying to send message: Sorry, private messaging rules forbid sending messages to Ben Kaplan.', 1 => true, 2 => 1, 3 => 1281384068.84, 4 => NULL, ) in RulesLog->renderHelper() (line 1898 of /Users/benkaplan/git/drupal/sites/all/modules/rules/rules/includes/rules.core.inc).
--Ben
Comment #109
BenK commentedI think I know the cause of this error: It's kinda my fault, but it exposed a bug, too. I have a User Blocking Rule set up that prevents sending to administrator role. And because I'm sending on administrator account, it prevented the rule from sending a new message back to author of message from the recipient (authenticated role).
But I guess we need some kind of handling within Rules integration so that if user is blocked, it doesn't expose a fatal error to the sender. It should probably report the user blocked validation string.
--Ben
Comment #110
BenK commentedI've tested the "Send private message" event and the "Send private message action. In general, it seems to be working fine. However, I've noticed that "Author" and "Recipient" replacement patterns don't yet work (even though Site Information replacement patterns do work). This is true for both replacement patterns in the subject line and replacement patterns in the body.
Also, it seems that replacement patterns for both author and recipient are actually shown as the same patterns in the dropdown menu. For instance, [user:name] is shown as the replacement pattern for username for both the Author and the Recipient. So that may be related to the problem.
Now I need to test the "Reply to private message" action...
--Ben
Comment #111
berdirUff :)
That token stuff there is handled by rules.module. Meaning, it is replaced when sending the message, not when viewing... So it's not the same thing as tokens from our token integration issue. I need to figure out if I can somehow replace that with our own token handling. And the duplication issue is certainly a rules.module issue.
Have not yet looked into the fatal error issue but that is just a bug somewhere (either in rules.module or in privatemsg_rules.module) because it only happens when trying to debug the failure.
Comment #112
BenK commentedI tried the "Reply" action and it's working well! Nice that Rules prevents recursion since I tested with the "Send private message" event (and I would have had infinite replies). We still have the tokens problems, but otherwise, everything is working well.
One usability suggestion: The "Reply a message" action should probably be re-titled "Reply to a message".
Also, under data selectors, there is both mid and thread_id. I used thread_id. I'm not quite sure what the purpose/difference of mid would be...
--Ben
Comment #113
BenK commentedAs for token handling, yeah it would be nice if versions of the site tokens could also be supplied by Private Message. So maybe there is the Rules supplied ones, but also Private Message supplied ones that can be better controlled by us.
--Ben
Comment #114
BenK commentedOne additional question I have: Should there be any other Rules events besides "A message is sent"?
For instance, I could envision a "Reply is sent" event. Also, I could envision a "A message is read" event that would allow a form of "read receipts" (sender could be notified when there Private Message was read).
Anyway, just food for thought. Not sure of the feasibility of any of this...
--Ben
Comment #115
NathanM commentedAnother good one would be "User has unread messages". So you could display a message when a user had messages that hadn't been read, and perhaps make the message go away not necessarily if they had read the message, but rather just accessed their box.
Comment #116
berdir- Will rename the reply action
- thread_id is the id of the thread, mid is the message id. For the first message of a thread, mid == thread_id. That is also how you can test if it is a reply or a new thread.
- Please create separate feature requests for new stuff, A single issue to collect possible actions/events/conditions is fine too, but I simply want to port what exists first in this issue. The problem with the view message event is that there can be easily 20, 30, 50 messages on a single page. That is a huge performance hit when start the rules "thing" for all of these. Also, user has unread messages would be a condition, not an event ;)
Comment #117
BenK commentedHey Berdir,
Thanks for the explanation. Makes sense.
I see about you're about the view message event on long threads. Yes, I agree, I don't want to hold up the port for any new features.
One thought is whether the view message event only needs to fire on the last message in the thread (and then we assume that all the other prior messages have been read). But anyway, that's a discussion for another thread.
I'll look forward to testing a new patch when you have a chance! :-)
--Ben
Comment #118
BenK commentedHad a nice chat with Berdir in IRC. He asked me to post a quick list of the outstanding items on Rules integration. So here's the list we discussed in IRC. Berdir will then make decisions about which items he wants to pursue now and which he wants to postpone:
A. Tagging a thread from within rules
B. If a user is blocked, avoid fatal error
C. Rules has its own tokens (which work well), but can PM tokens be available too?
D. Slight change of name for reply action
E. Can a field added to PM can be specified from within Rules?
F. Create Rules conditions that also work on a user (not just on a Private Message event). For instance, a user "has unread messages" condition. Would be useful in conjunction with data comparison (i.e. send user an email if more than 20 unread messages).
--Ben
Comment #119
berdirAttaching an new patch, not perfect yet but a huge improvement.
A. Tagging and checking if a tag exists works..
B. Fixed, the rules_log() calls where wrong.
C. TODO
D. Changed
E. In theory yes, but there seems to be a problem, I've openend a support issue for rules.module: #909252: How to access properties that are added to bundles.
F. Added an action to load the number of unread messages of a user. This can be be compared with a data comparison.
Also:
- All properties are can now be accessed through privatemsg_message::something, except recipient. Still need to think about that one.
- Also added an action to send a message to a role.
Note that this requires both the patch to privatemsg.module *and* the tar.gz.
Comment #121
BenK commentedSweet! This looks great. I'm looking forward to trying this out as soon as it passes the automated testing...
--Ben
Comment #122
berdirIgnore the test failures, they are not related to this :)
A recent core patch broke them. Happens quite often these days :)
Comment #123
berdir#119: core_changes.patch queued for re-testing.
Comment #124
BenK commentedHey Berdir and all,
I've completed testing of the latest patch... it's working great! Shown below is my report on each of our remaining issues:
A. Tagging is working very well. I was able to use tags as both a rules action and a rules condition. And I was able to successfully tag both the message sender and message recipient.
B. Confirmed this is fixed. I blocked all sending to users with the administrator role and then created a rule to "reply to" an admin user when a message was sent by him. Everything worked properly (the reply wasn't sent) and my rules debug message even said that the reply was blocked. Nice work. (I wasn't able to test the "Send a message" action with this, however, because of a separate error in "G" below. But that's a different issue.)
C. TODO... Looking forward to testing this if we can find a way to make it work. For instance, when testing the "Send to a role" action, it would be cool to have a privatemsg token available for the recipient username.
D. Confirmed this is fixed.
E. Okay, we'll wait to see if this is solved on the thread you referenced.
F. I'm having some trouble understanding how to test this properly. I might not understand how this is intended to be configured in conjunction with the data comparison condition.
I can create an action to load the number of unread messages of a user and my rules debug message says that it is successfully loading. But if I then try to "Set a data value" and make it equal to the loaded number of unread messages, I get the following error:
I also tried to create a rule set that would first load the number of unread messages and then perform a data comparison condition in a subsequent rule, but the recipient's number of unread messages was not available within the rule set (only the sender's unread messages).
So can you let me know how this is intended to be configured? I might just not be understanding the proper rules setup (specifically, how to run the data comparison condition after the load unread messages action happens).
Here's the common use case I'm trying to test: On the "A message is sent" event, check whether the message recipient has more than 5 unread messages. If he does, send him an e-mail reminding him to check his messages.
Also:
G. "All properties are can now be accessed through privatemsg_message::something, except recipient." I think there might be an error with how this is working for "privatemsg_message:author". Is it supposed to have two colons in a row (as you typed), not just one? Because in the data selector autocomplete field it is shown with one colon. Here's the error I'm experiencing: On the "A message is sent" event, I tried to configure a simple "Send a message" action... with the intent being to send an automated rules message back to the original message author. To do this, I selected the "privatemsg_message:author" as the recipient of this rules message. But upon triggering this rule (by sending a new message), I got the following error in my rules debug info:
H. The "Send a message to role" action is working great! I tested it several ways and experienced no problems at all. Nice work!
I. When I create a rule on the "A message is sent" event, I see the following configuration options in the rules settings:
What is the purpose of this? The checkboxes are all unchecked by default. I tried checking the boxes but it didn't seem to do anything. And what is "the caller"? I'm not clear on the intent of these settings. ;-)
--Ben
Comment #125
berdirC. Ok, added like we discussed it, with the {token} format. The description needs work, what do you suggest?
E. I explicitly specified the bundle name, this works now.
F. This looks broken to me. A loaded variable should be available to the conditions, I'm sure it was at some point (and is in D6). I suggest you open a bug report for rules and reference to it from here.
G. Yeah, only a single colon. Confirmed, no idea what's the problem here. I suggest to open an issue for rules module as well.
I. I have absolutely no clue :) Maybe they are returned to the function that executed the event but I don't see why that needs to be controlled through the UI. ask fago :)
Comment #126
berdirand now with patch. Not that this both requires an updated patch and the tar.gz (cvs isn't able to make a correct patch, because the files exist in HEAD and it automatically tries to diff against them, apparently..)
Also, addition to G. I'm also getting a number of notices like this one : "Notice: Undefined variable: arg_num in RulesPlugin->getArgument() (line 619 of /home/berdir/Projekte/d7/drupal/sites/all/modules/rules/rules/includes/rules.core.inc)."
Comment #127
BenK commentedHey Berdir,
I did some more testing and here's my report on the small number of remaining issues:
C. I couldn't get Private message tokens working successfully from within rules. It does look like the {} are being replaced by [] in the sent rules message, but they are not being evaluated as PM tokens. In other words, the recipient sees them as the token name with brackets instead of parentheses. However, in your description you mentioned using this format: {privatemsg:recipient:name}. Is that correct? Because PM tokens use this format: [privatemsg_message:recipient:name]. So all PM tokens use "privatemsg_message" as the prefix, but your rules description says to use just "privatemsg". I tried the tokens both ways and couldn't get either to work. But as discussed, I'd prefer to have the actual token names be consistent whether the site admin is using rules or not. If I'm somehow not configuring this correctly, let me know.
E. I successfully have rules tokens for extra fields that were added to PM. These tokens work great! :-) Maybe I misunderstood, but I also thought there would also be form fields available within the rules UI to enter text in those specific fields. I don't see those. But maybe that's impossible?
F. Here's the link to the issue I created: http://drupal.org/node/922154. Fago hasn't responded yet. He doesn't seem to respond to me as fast as he responds to you! ;-)
G. As discussed in IRC, "privatemsg-message:author" is working great now. But "privatemsg-message:thread-id" isn't working (at least for me). Very puzzling why it seems to work for you. Maybe the hyphen in thread-id is the source of the problem? Should we maybe try changing this to "tid" (or something else without a hyphen) and see if it solves the problem? I don't have a sense of how difficult it would be to try this change.
I. Okay, I'll ask fago about this one, too. But we can drop this off our list for now since it seems to deal totally with Rules UI. Maybe I'll wait until he answers my first issue (before creating this one) so that I don't overwhelm him.
--Ben
Comment #128
berdirC. Yes, {privatemsg_message:recipient:name} is correct. Updated the description. However, tokens are working fine for me, are you sure that the author does have permissions to use tokens and you are not sending the message to yourself? In that case, tokens aren't replaced. Not sure if that is a bug or a feature because it is a special case of being the author of the message :)
E. Uff :) I *tried* to get this working and it seems to work (at least for simple text fields, I've only tested those). But it requires quite a lot of complex code to get it right. Maybe there would be easier ways but I don't know them :) Making the fields visible is quite easy, processing them is the hard part so that they are in the correct format for fields.module. I think we shouldn't spend too much time on this at this point...
G. Sorry for the confusion here, I was using an old version of entity.module. It should work with this patch now. I have to always use _ in the code and it's always using - in the UI.
Note hat you need to rebuild the cache after updating the module. (The fastest way to do that is using drush: "drush cc all")
Comment #129
BenK commentedHey Berdir,
I've tested the latest patch and here are my notes:
C. I can't fully test this at the moment because of the new errors with E. and G. described below. Once we get the 'Send' and 'Reply' actions working again, I will test this.
E. Here's what I've noticed in regard to the extra fields on the rules UI form:
1) Extra fields are showing as "required" on rules form, even when they're not.
2) As you suspected, non-text fields are not showing up on the Rules form. Let's not worry about this.
3) The 'Private message thread id' field is showing up on the 'Send a message' action form. And it's required. But I don't think it is applicable to this action (it only matters for the 'Reply' action). And also, I'm testing this action on the 'Message is sent' event. When the original manually entered message is sent (the non-rules message), it is not being sent successfully (when the rule is used) and the following error is displaying:
So as of now, both the "send a message" and "reply to a message" actions are no longer working. I've double-checked I've emptied the cache.
G. The thread-id is now working when using the 'Tag a message' action. But when trying to use the thread-id with the 'Reply' action, I'm getting the following notice in my Rules debug info:
And the following error message is appearing at the top of the page:
--Ben
Comment #130
berdirOk, reverted the fields handling stuff for now, let's get something working commited :)
There is also an updated core_changes patch because I found a bug related to format handling when sending messages through the API.
I tested that send new, reply and tagging works....
Comment #131
BenK commentedI did some thorough testing of the latest patch and all issues are resolved! It's working terrifically. This is RTBC. I know you had to work through some tough challenges on this one, so thanks so much for that. Great work! :-)
Comment #132
liliplanet commentedPerhaps this fabulous module to be available for 6.x please?
Comment #133
berdirYay, commited!
@Liliplanet: This is already in 6.x-2.x-dev.
Comment #135
arisaves commentedCurious -- has the patch above been comitted to dev?