Rules Integration
Flying Drupalist - October 30, 2008 - 03:23
| Project: | Privatemsg |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
Rules integration would allow certain actions to send privatemsg and for privatemsg send to have other actions (such as notify by email).

#1
#2
note to self: make active branch to be DRUPAL-6--1 as this seems that using HEAD is confusing to people
#3
Another 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 ;)
#4
Should I be using this to handle email, or the code in the email thread?
#5
Depends :)
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.
#6
Hi,
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
#7
Thank 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?
Hi <? $recipient?>,
You have received a New Private Message from <? $author?>.
<? $thread_id?>
All the best,
The Team
Just receive empty token values ..
Look forward to your reply and again, thank you.
Lilian
#8
You 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.#9
My 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)
#10
An 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.
#11
Thanks, 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?
#12
I 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.
#13
Yes, sounds like Views integration is what I'm after. Will have to see if I can figure out how to write the theme function.
#14
The rules integration seems to be working fine.
Is it possible to select a different user other than admin (uid 1) as the default sender?
#15
#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.
#16
Thanks 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.
#17
Hello,
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 !
#18
1. 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.
#19
I still don't see the example rules, am I missing somthing ?
#20
Thank you Verdir for your last suggestion ..
I'm still struggling with the following:
Hi <?php print $recipient;?>,
You have received a Private Message on Mysite.com from <?php print $author;?>
<?php print $subject;?>
Continue to http://www.mysite.com/messages to read.
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
#21
Can this be rolled into the next release, as well?
#22
I 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
#23
That's my mistake, I forgot the API. It works perfect now.
#24
I get the following errors after sending a message:
* recoverable fatal error: Object of class stdClass could not be converted to string in /home/transfp6/public_html/gatheringspot-dev/sites/all/modules/rules/rules/modules/php.rules.inc(83) : eval()'d code on line 1.* recoverable fatal error: Object of class stdClass could not be converted to string in /home/transfp6/public_html/gatheringspot-dev/sites/all/modules/rules/rules/modules/php.rules.inc(83) : eval()'d code on line 1.
* recoverable fatal error: Object of class stdClass could not be converted to string in /home/transfp6/public_html/gatheringspot-dev/sites/all/modules/rules/rules/modules/php.rules.inc(83) : eval()'d code on line 3.
This is my subject:
<?php echo $author; ?> sent you a messageAnd this is my message:
Hi there <?php echo $recipient; ?>,
<?php echo $author; ?> sent you a message: <?php echo $subject; ?>
You can read the full message here: http://www.site.net/messages
And this is what I actually get in the mail:
Subject: sent you a message
Hi there ,
sent you a message: TEST 2
You can read the full message here: http://www.site.net/messages
Any ideas?
Andrey.
#25
$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.
#26
Got it. It works well now, thanks.
Andrey.
#27
tried 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 ?
#28
There was a change in the API, I need to re-roll this module.
#29
Hi 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
#30
see next post...
#31
Here 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.)
#32
Rules 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.
#33
Hi 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
#34
Please 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)
#35
And now with attachment...
#36
I'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.
#37
Found a bug. Here's a modified version.
#38
I 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.
#39
what 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.
#40
[deleted]
#41
Zanhsieh,
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
#42
Bit 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!
#43
nbz & 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.
#44
Zanhsieh,
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
#45
Brad,
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).
#46
I'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
#47
Not 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.
#48
Wow 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!
#49
I'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.
#50
I 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.
#51
I 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
#52
You 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.
#53
Thank you for your reply Berdir, I will check that up..
#54
Ah, 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!
#55
subscribe
#56
subscribe
#57
subscribing
#58
Any 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.)
#59
#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'.
#60
Thanks. 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.
#61
We 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.
#62
My 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.
#63
subscribe
#64
This works for me :)
Hi [recipient:realname],
You have received a Private Message on mysite.com from [author:realname]
<?php print $subject;?>
Continue to http://www.mysite.com/messages to read your message.
All the best,
The mysite.com Team
[mid:site-url]
#65
Is 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.
#66
What is the level of this issue, any development?
#67
As 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.
#68
Going 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.
#69
Thanks, 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.