Overview
This plugin uses the
Akismet service to check for spam messages. Akismet is also used for popular blogs like Wordpress to prevent spam from appearing in the comments. A key for this service is needed, which can be requested
here for free for personal use.
The plugin requires a key, a site name (usually the name of the blog), and optional provider.
Configuration
You'll need to place the following configuration element in the Config.groovy
akismet {
key = "<your-key>"
site = "<your-website" // eg http://www.jworks.nl/blog
provider = "rest.akismet.com" // or api.antispam.typepad.com
}Provider
Tomas Lin mad the suggestion to support Typepad as well.
Typepad has a more friendly licensing scheme, but it also a little more aggressive on assigning a spam status to some messages (based on some quick testing). Since it has the same API, adding support for it was easy, so this can be configured now with the
provider configuration. It's optional: adding no provider will use akismet, but you can change that to Typepad. You can request a key for typepad
here (+)| Name | Description |
|---|
| rest.akismet.com | Free for personal use |
| api.antispam.typepad.com | Free for all use |
Logging
There is some debug logging available. This can be enabled by adding the following line to the Config.groovy Log4j DSL:
log4j = {
// other logging configuration... debug "nl.jworks.akismet"
}Usage
The Akismet functionality is located in a service. This means you can use it eg. by defining a field in your controller, call the service methods, and you'll get an answer immediately. A small example of this:
class BlogController {
def akismetService def addComment = {
def comment = new Comment(params) if (!akismetService.isSpam(request.remoteAddr, request.getHeader('User-Agent'), request.getHeader('Referer'),
"http://www.dummy.com", "comment", comment.name, comment.emailAddress, comment.website, comment.text)) {
log.info("Comment ${comment.dump()} considered okay. Posting it") // logic here
} else {
log.warn "Comment ${comment.dump()} considered spam."
}
}
}The Akismet Service has the following methods:
| Name | Description |
|---|
| verifyKey | Checks if the configured key is correct |
| isSpam | The core of the service. Checks if the supplied information is considered spam by the Akismet Service. Returns true if the submitted information is spam, false otherwise. |
| submitSpam | Submits new information to Akismet to be considered spam |
| submitHam | Submits false positives to Akismet to be considered NOT spam |
Most of the calls take the same parameters, so I'll document them only once:
| Name | Description |
|---|
| blog (required) | The front page or home URL of the instance making the request. For a blog or wiki this would be the front page. Note: Must be a full URI, including http://. |
| ipAddress (required) | IP address of the comment submitter. |
| userAgent (required) | User agent information. |
| referrer | The content of the HTTP_REFERER header should be sent here. |
| permalink | The permanent location of the entry the comment was submitted to. |
| commentType | May be blank, comment, trackback, pingback, or a made up value like "registration". |
| commentAuthor | Submitted name with the comment |
| commentAuthorEmail | Submitted email address |
| commentAuthorUrl | Commenter URL. |
| commentContent | The content that was submitted. |
For the not required items, you can just supply a null value. When you don't have access to the optional values, just supply null values. It is recommended however to supply as much information as possible.