Blazingly fast spam classification API built using Rocket Web Framework.

Overview

Telegram Antispam API

Blazingly fast spam classification API built using Rocket Web Framework.

Rust

Notes

  • The classifier works in aggressive mode, it can sometimes classify non-spam messages/emails as spam (when the input is too small)
  • The dataset provided may contain some NSFW texts or personal info, it's not thoroughly checked.
  • I've included a docker-based example, but you can run it without docker as well.
  • profanity in response is only there to maintain backwards compatibility for ARQ users, it always returns false

Installation:

I would suggest using docker compose for this, but it's upto you!

With Docker compose

$ git clone https://github.com/thehamkercat/telegram-antispam-rs
$ cd telegram-antispam-rs
$ docker-compose build
$ docker-compose up

With Cargo

$ git clone https://github.com/thehamkercat/telegram-antispam-rs
$ cd telegram-antispam-rs
$ cargo run --release

Endpoints:

POST /spam_check HTTP/1.1
Host: localhost:8000
Content-Type: application/json

{
  "text": "subscribe to my youtube channel"
}

HTTP/1.1 200 OK
content-length: 59
content-type: application/json

{
  "spam": 99,
  "ham": 1,
  "is_spam": true,
  "profanity": false,
  "spam_probability": 99
}

A Go port for the same API can be found here

Usage examples:

Python

import requests

url = "http://localhost:8000/spam_check"
data = {"text": "subscribe to my youtube channel"}

result = requests.post(url, json=data).json()

print("Is spam:", result["is_spam"])
print("Spam probability:", result["spam_probability"])

Go

package main

import (
	"bytes"
	"encoding/json"
	"net/http"
)

func main() {
	url := "http://localhost:8000/spam_check"
	data := map[string]string{"text": "subscribe to my youtube channel"}
	jsonData, err := json.Marshal(data)
	if err != nil {
		panic(err)
	}

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
	if err != nil {
		panic(err)
	}

	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	// Do something with the response if needed
}

Rust

use std::collections::HashMap;
use serde::{Deserialize, Serialize};


#[derive(Serialize, Deserialize, Debug)]
struct Resp {
    spam: u8,
    ham: u8,
    is_spam: bool,
    spam_probability: u8,
    profanity: bool
}

#[tokio::main]
async fn main(){
    let client = reqwest::Client::new();
    let mut map = HashMap::new();
    map.insert("text", "Hello please subscribe to my youtube channel!");

    let res = client
        .post("http://localhost:8000/spam_check")
        .json(&map)
        .send()
        .await
        .unwrap();

    let text_response = res.text().await.unwrap();

    let json: Result<Resp, _> = serde_json::from_str(text_response.as_str());
    if json.is_ok() {
        println!("{:?}", json.unwrap());
    }
}

// [dependencies]
// reqwest = { version = "0.11", features = ["json"] }
// serde = {version = "1.0.160", features = ["derive"]}
// serde_json = "1.0.96"
// tokio = { version = "1", features = ["full"] }
You might also like...
A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns.

Discord API Types A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns. Also did

⚡rustygram is a minimal and blazing fast telegram notification framework for Rust
⚡rustygram is a minimal and blazing fast telegram notification framework for Rust

⚡rustygram ⚡rustygram is a minimal and blazing fast telegram notification framework using Rust. Abstracts away the Telegram API complexity so your app

A simple, fast and fully-typed JSPaste API wrapper for Rust

rspaste A simple, fast and fully-typed JSPaste API wrapper for Rust. aidak.tk » Installation Put the desired version of the crate into the dependencie

A tool to calculate mean and standard deviation from multiple tests using PageSpeed Insights API.

psi-sample PSI Test tool is an open source tool to assist web developers that runs Page Speed Insight test manually! Installing To install the psi-tes

A fast & light weight Discord Client made with love using the Rust programming language.
A fast & light weight Discord Client made with love using the Rust programming language.

LemonCord A fast & light-weight Discord Client written in Rust using the wry crate. Features Fast, light-weight, easy to use. 100% Open sourced. No su

A job queue built on sqlx and PostgreSQL.

sqlxmq A job queue built on sqlx and PostgreSQL. This library allows a CRUD application to run background jobs without complicating its deployment. Th

🦜 A hassle-free, highly performant, host it yourself Discord music bot built with Serenity in Rust. Powered by youtube-dl and Genius.

🦜 A hassle-free, highly performant and fast evolving Discord music bot built with Serenity in Rust. Deployment Usage Just create a bot account, copy

A clean, custom-built modular kernel ready to boot on x86_64.
A clean, custom-built modular kernel ready to boot on x86_64.

Lateral is a work-in-progress multitasking monolithic kernel + OS meant as a fun summer project. It has recently expanded into more than I could imagi

A better message queue built by rust

bettermq A better message queue built by rust I start this project to study Rust

Releases(v0.1.0)
Owner
Akshay Rajput
19 y.o Tech enthusiast and aspiring software engineer who's fueled by coffee and driven by curiousity.
Akshay Rajput
IITC-CE Telegram Chat Spam Protection

ADA AntiBot This bot bans spammers in Telegram chat. Run To run you should export environment variables: TELOXIDE_TOKEN - telegram bot token TELEGRAM_

Ingress Intel Total Conversion — Community Edition 4 May 23, 2022
Novus - A blazingly fast and efficient package manager for windows.

Novus - A blazingly fast and efficient package manager for windows. Why Novus Swift Unlike any other package manager, Novus uses multithreaded downloads

Novus 197 Dec 18, 2022
🦀🚀🔥 A blazingly fast and memory-efficient implementation of `if err != nil` 🔥🚀🦀

?????? A blazingly fast and memory-efficient implementation of `if err != nil` ??????

Federico Damián Schonborn 6 Dec 30, 2022
A blazingly fast 🔥 Discord bot written in Rust

rusty-bot ?? A blazingly fast ?? Discord bot written in Rust. Commands name use !rm <count> deletes old messages !meme <subreddit> sends a random meme

Asandei Stefan 2 Oct 14, 2022
Blazingly Fast..!

Rust-Workers Blazingly Fast..! Contribution Guideline Create an .env file in the root of the project and add your mongodb uri to it. MONGODB_URI=<your

Sofi-Tech 6 Nov 17, 2022
🚀 Fast and 100% API compatible postcss replacer, built in Rust

?? Fast and 100% API compatible postcss replacer, built in Rust

迷渡 472 Jan 7, 2023
Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

null 21 Jan 1, 2023
Software adapter for various Chunithm slider controllers with a built-in Brokenithm web controller

slidershim Software adapter for various Chunithm slider controllers with a built-in Brokenithm web controller. Has support for keyboard/gamepad output

Si Yuan 45 Dec 17, 2022
simple lottery maker made with rust, just web framework

Toy project for fun It's just for fun! making plausible lottery numbers for Korea made with rust This lottery web framework generates and presents pla

yacho (bakjuna) 4 Nov 24, 2023
API wrapper for the tankerkönig api

tankerkoenig-rs API wrapper for the tankerkoenig-api written in rust. Gives you ready deserialized structs and a easy to use and strictly typed api. I

Jonathan 2 Feb 27, 2022