Last active
March 23, 2019 18:14
-
-
Save ryanburnette/268d66be7748917ad4540caeb846ca99 to your computer and use it in GitHub Desktop.
thoughts about integrating akismet api w/ my express-based form endpoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/chrisfosterelli/akismet-api#readme | |
https://akismet.com/development/api/#detailed-docs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment