Skip to content
Ozgur Ozcitak edited this page May 3, 2019 · 14 revisions

Creating the Client

    var akismet = require('akismet').client(options);

where options must include the blog url and Akismet API key. Rest of the options are optional and default values are as shown below:

Name Description Default Value
blog Blog URL <none>
apiKey Akismet API key <none>
host Akismet API server rest.akismet.com
endPoint API endpoint apiKey.rest.akismet.com
port Server port 80
userAgent User agent string passed to the API server Generic Node.js/1.0.0 | Akismet/3.1.7
charSet Text encoding utf-8

For example:

    var akismet = require('akismet').client({ 
      blog: 'http://my.blog.com', 
      apiKey: 'myakismetapikey123' 
    });

Verifying the API Key

    akismet.verifyKey(callback);

where callback takes two arguments: err and verified. verified will be true if the API key was successfully verified.

For example:

    akismet.verifyKey(function(err, verified) {
      if (verified) 
        util.log('API key successfully verified.');
      else 
        util.log('Unable to verify API key.');
    });

Checking for Spam

    akismet.checkComment(args, callback);

where args contain query string parameters as key/value pairs. callback takes two arguments: err and spam. spam will be true if the Akismet API identifies the comment as spam.

For example:

    akismet.checkComment({ 
        user_ip: '1.1.1.1', 
        permalink: 'http://www.my.blog.com/my-post',
        comment_author: 'spammer',
        comment_content: 'spamming your comments'
      }, function(err, spam) {
        if(spam)
          util.log('Spam caught.');
        else
          util.log('Not spam');
    });

Sending Feedback to Akismet

    akismet.submitSpam(args, callback);
    akismet.submitHam(args, callback);

If the Akismet API returns false positives or false negatives you can send feedback to the API with these functions. Their usage is the same as checkComment. args contain query string parameters as key/value pairs. callback takes an err argument.

For example:

    akismet.submitSpam({ 
        user_ip: '1.1.1.1', 
        permalink: 'http://www.my.blog.com/my-post',
        comment_author: 'spammer',
        comment_content: 'spamming your comments'
      }, function(err) {
        util.log('Spam reported to Akismet.');
    });
Clone this wiki locally