AkismetApi.Net 4.0.0

dotnet add package AkismetApi.Net --version 4.0.0                
NuGet\Install-Package AkismetApi.Net -Version 4.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AkismetApi.Net" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AkismetApi.Net --version 4.0.0                
#r "nuget: AkismetApi.Net, 4.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AkismetApi.Net as a Cake Addin
#addin nuget:?package=AkismetApi.Net&version=4.0.0

// Install AkismetApi.Net as a Cake Tool
#tool nuget:?package=AkismetApi.Net&version=4.0.0                

Akismet.Net

Complete and full-featured Akismet client for .NET

Existing libraries don't allow for all of the possible options available in the Akismet API and the source code is not public. This library is meant to fix that.

It is also multi-targeted to support as many applications as possible.

NuGet Status

Meant to be a drop-in replacement for the leading Akismet library with minimal changes so the class names are the same. However some properties have been removed because of redundancy.

Example usage:

.NET Framework

var model = new ContactModel();
string ip = Request.Headers["CF-Connecting-IP"] ?? Request.UserHostAddress;
if (String.IsNullOrWhiteSpace(ip))
    ip = Request.ServerVariables["REMOTE_HOST"];
AkismetClient akismet = new AkismetClient("apikeyhere", new Uri("https://www.adamh.us"), "Application Name");
AkismetComment comment = new AkismetComment
{
    CommentAuthor = model.Name,
    CommentAuthorEmail = model.EmailAddress,
    CommentAuthorUrl = "http://www.spamwebsite.com",
    Referrer = Request.UrlReferrer.ToString(),
    UserAgent = Request.UserAgent,
    UserIp = ip,
    CommentContent = model.Message,
    CommentType = AkismentCommentType.ContactForm, // multiple defined values, or use new AkismetCommentType("new-comment-type") for a custom option
    Permalink = "https://www.adamh.us/contact",
    IsTest = "false",
    BlogCharset = "UTF-8",
    BlogLanguage = "en-US",
    CommentDate = DateTime.UtcNow.ToString("O"), // ISO-8601 format
    CommentPostModified = DateTime.UtcNow.ToString("O"), // ISO-8601 format
    UserRole = "administrator",
    RecheckReason = "edit",
    HoneypotFieldName = "honeypot",
    HoneypotFieldValue = "blah"
};

var akismetResult = await akismet.CheckAsync(comment);
bool isSpam = akismetResult.SpamStatus == SpamStatus.Spam; // Options: Ham, Spam, Unspecified (in the case of an error)

// "invalid" and/or combination of X-akismet-alert-code and X-akismet-alert-msg header values
foreach (string err in akismetResult.Errors)
    Console.WriteLine(err);
    
// Other properties:
//    - ProTip (X-akismet-pro-tip header value, if present)
//    - DebugHelp (X-akismet-debug-help header value, if present)

.NET Core/.NET 5+ Usage Modifications

Program.cs / Startup.cs
builder.Services.AddAkismet(
    configuration.ApiKey,
    configuration.AkismetApplicationName,
    configuration.BlogUrl);
Service Class / Controller
public class ContactFormController(AkismetClient akismetClient)

string ip = Request.Headers["CF-Connecting-IP"].ToString() ?? _contextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString() ?? "";
if (String.IsNullOrWhiteSpace(ip))
    ip = _contextAccessor.HttpContext?.GetServerVariable("REMOTE_HOST") ?? "";
AkismetComment comment = new AkismetComment
{
    // ... other properties set as above
    UserAgent = Request.Headers[HeaderNames.UserAgent],
    Referrer = Request.Headers[HeaderNames.Referer]
};
var akismetResult = await akismetClient.CheckAsync(comment)

Notes

If HoneypotFieldName and HoneypotFieldValue are supplied then the library will add these two values to the request:

honeypot_field_name=honeypot&honeypot=blah

⚠️Breaking Changes

Version 4.0 has a breaking change:

  • Dropped RestClient in favor of HttpClient directly
  • .NET Core/.NET 5+ now utilize dependency injection
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on AkismetApi.Net:

Package Downloads
Akismet.Umbraco

Akismet for Umbraco (9+)

Akismet.Umbraco8.Core

Akismet for Umbraco 8

Akismet.UmbracoForms8.Workflow

Akismet Workflow for Umbraco Forms 8

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 40 12/21/2024
3.0.0.1 4,071 1/6/2023
2.0.0 6,968 11/30/2021
1.1.5 1,263 8/6/2021
1.1.4 403 8/5/2021
1.1.3 417 7/26/2021
1.1.2 380 7/20/2021
1.1.1 748 3/24/2021
1.1.0 1,088 3/19/2021
1.0.0.3 416 2/24/2021

Dropped explicit support for .NET Core; dropped dependency on RestSharp