Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Last active March 23, 2019 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburnette/268d66be7748917ad4540caeb846ca99 to your computer and use it in GitHub Desktop.
Save ryanburnette/268d66be7748917ad4540caeb846ca99 to your computer and use it in GitHub Desktop.
thoughts about integrating akismet api w/ my express-based form endpoints
var akismet = require('akismet-api');
var client = akismet.client({
key: process.env.AKISMET_API_KEY,
blog: process.env.AKISMET_BLOG_URL
});
module.exports = client;
// verify akismet api key
client.verifyKey()
.then(function(valid) {
if (valid) {
console.log('Valid key!');
}
else {
console.log('Invalid key!');
}
})
.catch(function(err) {
console.log('Check failed: ' + err.message);
});
// check for spam in form submission
client.checkSpam({
user_ip : '123.123.123.123', // Required!
user_agent : 'MyUserAgent 1.0 Webkit', // Required!
referrer : req.headers.HTTP_REFERER, // Required!
permalink : 'https://myblog.com/myPost',
comment_type : 'contact-form',
comment_author : 'John Smith',
comment_author_email : 'john.smith@gmail.com',
comment_content : 'Very nice blog! Check out mine!'
}).then(function (err,spam) {
})
catch(function (err) {
}).;
client.submitSpam({
user_ip : '123.123.123.123', // Required!
user_agent : 'MyUserAgent 1.0 Webkit', // Required!
referrer : 'https://google.com', // Required!
permalink : 'https://myblog.com/myPost',
comment_type : 'comment',
comment_author : 'John Smith',
comment_author_email : 'john.smith@gmail.com',
comment_author_url : 'https://johnsblog.com',
comment_content : 'Very nice blog! Check out mine!',
is_test : true // Default value is false
}, function(err) {
if (!err) {
console.log('Spam reported!');
}
});
client.submitHam({
user_ip : '123.123.123.123', // Required!
user_agent : 'MyUserAgent 1.0 Webkit', // Required!
referrer : 'https://google.com', // Required!
permalink : 'https://myblog.com/myPost',
comment_type : 'comment',
comment_author : 'John Smith',
comment_author_email : 'john.smith@gmail.com',
comment_author_url : 'https://johnsblog.com',
comment_content : 'Very nice blog! Check out mine!',
is_test : true // Default value is false
}, function(err) {
if (!err) {
console.log('Non-spam reported!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment