I am currently using the Blog4Umbraco package for v4.0.1
I would like to set up notifications so that when a comment is added to a blog entry the site admin is notified. I can get the notification email working correctly but the URL and comment details are missing.
Obviously this is because there is no actual URL for the comment as it exists as part of the blog entry.
Any ideas on how I can get this notification to at least go to the comments page?
Umbraco has a great event system where you can hook into. On my weblog I wrote a few examples that I've for the Benelux meetup.
In your case you can create an Event Handler for the New event on the document class. This means that every time that a new document is created (blog comment is also a new document) You can check if the DocumentType Alias is BlogPostComment and then send yourself a NotifyMessage.
ExampleCode (Not tested)
[code]using System;
using System.Collections.Generic;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.BusinessLogic;
namespace AutoUnpublish
{
///
/// Helps us with teh businessrule that every news item must be unpublished after 14 days;
///
public class AutoUnpublishNewsHandler : ApplicationBase
{
public AutoUnpublishNewsHandler()
{
Document.New += new Document.NewEventHandler(DocumentNew);
}
private void DocumentNew(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
{
if (sender.ContentType.Alias == "BlogPostComment")
{
//Weblog commant get some properties
string message = string.Format("Weblog comment by {0}, message: {1}", sender.getProperty("name"), sender.getProperty("comment"));
//Send Notification
umbraco.library.SendMail("[email protected]","[email protected]","weblog comment",message,false);
}
}
}
}
[/code]
An easier solution might be to use umbraco's built-in notifications.
Log in to umbraco. Be sure the user you are logging in as has an email address set in the 'Users' section of umbraco.
Then, right-click on the 'Blog' content node in umbraco and select the 'Notifications' menu. Put a checkmark next to the 'Publish' item and click OK.
Now, whenever a page is published anywhere in the blog tree you'll get an email with the details. Since blog comments are new nodes that get published, you'll get an email every time a blog comment is entered.
Notifications work on the current document and all children. That makes it pretty easy to create even a complex notification system for yourself. With a couple clicks you can get notifications on all the pages of your site, except for a few pages or website sections, for instance.
Shouldn't be blank emails if you use the 'Publish' notification. I am doing this on my own blog and it works perfectly. If you set notification on the 'Create' event then obviously it won't have any values at that point in time.
As for the url being an id, those should work just fine, though typically comment nodes have no template assigned to them and therefore they do not display any output if you go to their url. A better approach would be to create a template for the blogPostComment document type (or whatever your comment docType is named). I use the following in my comment template to auto-redirect to the parent node, which is the blogPost itself. That way I can see the comment, but not out of context of the rest of the blog.
This has helped me a bit on my problem. My question is, and this may require some coding. Please let me know if I am wrong, but is there a way to set up the comments section in the Blog package to "hold" the comments for approval prior to posting them. I know now they auto publish. Is there an easy way to put them in that moderation list and when approved is selected then they publish.
The only fear I have with the auto publish comments is possible inappropriate comments being posted on our blog.
Adding notification for a blog comment
I am currently using the Blog4Umbraco package for v4.0.1
I would like to set up notifications so that when a comment is added to a blog entry the site admin is notified. I can get the notification email working correctly but the URL and comment details are missing.
Obviously this is because there is no actual URL for the comment as it exists as part of the blog entry.
Any ideas on how I can get this notification to at least go to the comments page?
Cheers
Paul
Hi Paul,
Umbraco has a great event system where you can hook into. On my weblog I wrote a few examples that I've for the Benelux meetup.
In your case you can create an Event Handler for the New event on the document class. This means that every time that a new document is created (blog comment is also a new document) You can check if the DocumentType Alias is BlogPostComment and then send yourself a NotifyMessage.
ExampleCode (Not tested)
[code]using System;
using System.Collections.Generic;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.BusinessLogic;
namespace AutoUnpublish
{
///
/// Helps us with teh businessrule that every news item must be unpublished after 14 days;
///
public class AutoUnpublishNewsHandler : ApplicationBase
{
public AutoUnpublishNewsHandler()
{
Document.New += new Document.NewEventHandler(DocumentNew);
}
private void DocumentNew(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
{
if (sender.ContentType.Alias == "BlogPostComment")
{
//Weblog commant get some properties
string message = string.Format("Weblog comment by {0}, message: {1}", sender.getProperty("name"), sender.getProperty("comment"));
//Send Notification
umbraco.library.SendMail("[email protected]","[email protected]","weblog comment",message,false);
}
}
}
}
[/code]
Hope this helps you,
Richard
An easier solution might be to use umbraco's built-in notifications.
Log in to umbraco. Be sure the user you are logging in as has an email address set in the 'Users' section of umbraco.
Then, right-click on the 'Blog' content node in umbraco and select the 'Notifications' menu. Put a checkmark next to the 'Publish' item and click OK.
Now, whenever a page is published anywhere in the blog tree you'll get an email with the details. Since blog comments are new nodes that get published, you'll get an email every time a blog comment is entered.
cheers,
doug.
Oh that's much easier indeed. Always thought that Notifications only worked for the current document.
Notifications work on the current document and all children. That makes it pretty easy to create even a complex notification system for yourself. With a couple clicks you can get notifications on all the pages of your site, except for a few pages or website sections, for instance.
cheers,
doug.
The problem with the Umbraco notifications though is that the links I get in the notification email for a blog comment don't point anywhere.
This is because it forms a URL of type
Shouldn't be blank emails if you use the 'Publish' notification. I am doing this on my own blog and it works perfectly. If you set notification on the 'Create' event then obviously it won't have any values at that point in time.
As for the url being an id, those should work just fine, though typically comment nodes have no template assigned to them and therefore they do not display any output if you go to their url. A better approach would be to create a template for the blogPostComment document type (or whatever your comment docType is named). I use the following in my comment template to auto-redirect to the parent node, which is the blogPost itself. That way I can see the comment, but not out of context of the rest of the blog.
[code]
[/code]
You'd need to set the ContentPlaceHolderId's value for your specific template.
cheers,
doug.
Thanks Doug, nice and simple to set that up.
And thanks also to Richard for the Event demo blogs that I'm using elsewhere
This has helped me a bit on my problem. My question is, and this may require some coding. Please let me know if I am wrong, but is there a way to set up the comments section in the Blog package to "hold" the comments for approval prior to posting them. I know now they auto publish. Is there an easy way to put them in that moderation list and when approved is selected then they publish.
The only fear I have with the auto publish comments is possible inappropriate comments being posted on our blog.
Any tips will help. Thanks in advanced.
Have you taken a look at this forum?
http://our.umbraco.org/projects/blog-4-umbraco/using-blog-4-umbraco/7079-Comment-Moderation,-How?p=0#comment36349
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.