@sharpapi/sharpapi-node-detect-spam 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,273 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # Spam Detector API for Node.js
4
+
5
+ ## 🛡️ Detect spam content with AI accuracy — powered by SharpAPI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-detect-spam.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-spam)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-detect-spam.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI Spam Detector** uses advanced AI to identify spam, malicious content, and unwanted messages. Perfect for content moderation, email filtering, and user-generated content protection.
11
+
12
+ ---
13
+
14
+ ## 📋 Table of Contents
15
+
16
+ 1. [Requirements](#requirements)
17
+ 2. [Installation](#installation)
18
+ 3. [Usage](#usage)
19
+ 4. [API Documentation](#api-documentation)
20
+ 5. [Examples](#examples)
21
+ 6. [License](#license)
22
+
23
+ ---
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 16.x
28
+ - npm or yarn
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ ### Step 1. Install the package via npm:
35
+
36
+ ```bash
37
+ npm install @sharpapi/sharpapi-node-detect-spam
38
+ ```
39
+
40
+ ### Step 2. Get your API key
41
+
42
+ Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
43
+
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ ```javascript
49
+ const { SharpApiDetectSpamService } = require('@sharpapi/sharpapi-node-detect-spam');
50
+
51
+ const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
52
+ const service = new SharpApiDetectSpamService(apiKey);
53
+
54
+ const suspiciousText = `
55
+ URGENT! You have won $1,000,000!!! Click here NOW to claim your prize!
56
+ Send your bank details to claim@fake-site.com immediately!
57
+ Limited time offer!!!
58
+ `;
59
+
60
+ async function checkSpam() {
61
+ try {
62
+ // Submit spam detection job
63
+ const statusUrl = await service.detectSpam(suspiciousText);
64
+ console.log('Job submitted. Status URL:', statusUrl);
65
+
66
+ // Fetch results (polls automatically until complete)
67
+ const result = await service.fetchResults(statusUrl);
68
+ const spamResult = result.getResultJson();
69
+
70
+ console.log('Is spam:', spamResult.is_spam);
71
+ console.log('Confidence score:', spamResult.score);
72
+ } catch (error) {
73
+ console.error('Error:', error.message);
74
+ }
75
+ }
76
+
77
+ checkSpam();
78
+ ```
79
+
80
+ ---
81
+
82
+ ## API Documentation
83
+
84
+ ### Methods
85
+
86
+ #### `detectSpam(text: string): Promise<string>`
87
+
88
+ Analyzes text content to determine if it's spam.
89
+
90
+ **Parameters:**
91
+ - `text` (string, required): The text content to analyze for spam
92
+
93
+ **Returns:**
94
+ - Promise<string>: Status URL for polling the job result
95
+
96
+ **Example:**
97
+ ```javascript
98
+ const statusUrl = await service.detectSpam(userGeneratedContent);
99
+ const result = await service.fetchResults(statusUrl);
100
+ ```
101
+
102
+ ### Response Format
103
+
104
+ The API returns spam detection results with confidence score:
105
+
106
+ ```json
107
+ {
108
+ "is_spam": true,
109
+ "score": 95,
110
+ "confidence": "high",
111
+ "reasons": [
112
+ "Contains urgency language",
113
+ "Requests financial information",
114
+ "Uses excessive punctuation",
115
+ "Contains suspicious URLs"
116
+ ],
117
+ "categories": ["phishing", "financial_scam"]
118
+ }
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Examples
124
+
125
+ ### Basic Spam Detection
126
+
127
+ ```javascript
128
+ const { SharpApiDetectSpamService } = require('@sharpapi/sharpapi-node-detect-spam');
129
+
130
+ const service = new SharpApiDetectSpamService(process.env.SHARP_API_KEY);
131
+
132
+ const userComment = 'Check out my website for amazing deals!!! Click here now!!!';
133
+
134
+ service.detectSpam(userComment)
135
+ .then(statusUrl => service.fetchResults(statusUrl))
136
+ .then(result => {
137
+ const spamCheck = result.getResultJson();
138
+
139
+ if (spamCheck.is_spam) {
140
+ console.log(`⚠️ SPAM DETECTED (${spamCheck.score}% confidence)`);
141
+ console.log('Reasons:', spamCheck.reasons.join(', '));
142
+ } else {
143
+ console.log('✅ Content is clean');
144
+ }
145
+ })
146
+ .catch(error => console.error('Detection failed:', error));
147
+ ```
148
+
149
+ ### Content Moderation Pipeline
150
+
151
+ ```javascript
152
+ const service = new SharpApiDetectSpamService(process.env.SHARP_API_KEY);
153
+
154
+ async function moderateContent(content) {
155
+ const statusUrl = await service.detectSpam(content);
156
+ const result = await service.fetchResults(statusUrl);
157
+ const spamCheck = result.getResultJson();
158
+
159
+ return {
160
+ approved: !spamCheck.is_spam || spamCheck.score < 70,
161
+ confidence: spamCheck.score,
162
+ reasons: spamCheck.reasons,
163
+ action: spamCheck.score >= 90 ? 'block' :
164
+ spamCheck.score >= 70 ? 'review' :
165
+ 'approve'
166
+ };
167
+ }
168
+
169
+ const userPosts = [
170
+ 'Great product! Highly recommend.',
171
+ 'WIN MONEY NOW!!! CLICK HERE!!!',
172
+ 'Thanks for the helpful information.'
173
+ ];
174
+
175
+ for (const post of userPosts) {
176
+ const moderation = await moderateContent(post);
177
+ console.log(`Post: "${post}"`);
178
+ console.log(`Action: ${moderation.action} (${moderation.confidence}% spam)`);
179
+ console.log('---');
180
+ }
181
+ ```
182
+
183
+ ### Batch Spam Checking
184
+
185
+ ```javascript
186
+ const service = new SharpApiDetectSpamService(process.env.SHARP_API_KEY);
187
+
188
+ const messages = [
189
+ { id: 1, text: 'Looking forward to our meeting tomorrow.' },
190
+ { id: 2, text: 'URGENT! Update your password immediately!!!' },
191
+ { id: 3, text: 'Could you send me the project files?' }
192
+ ];
193
+
194
+ const results = await Promise.all(
195
+ messages.map(async (msg) => {
196
+ const statusUrl = await service.detectSpam(msg.text);
197
+ const result = await service.fetchResults(statusUrl);
198
+ const spamCheck = result.getResultJson();
199
+
200
+ return {
201
+ id: msg.id,
202
+ text: msg.text,
203
+ is_spam: spamCheck.is_spam,
204
+ score: spamCheck.score
205
+ };
206
+ })
207
+ );
208
+
209
+ const spamMessages = results.filter(r => r.is_spam);
210
+ console.log(`Found ${spamMessages.length} spam messages out of ${messages.length}`);
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Use Cases
216
+
217
+ - **Content Moderation**: Filter spam from user comments, reviews, and forums
218
+ - **Email Filtering**: Identify and block spam emails
219
+ - **Form Protection**: Prevent spam submissions on contact forms
220
+ - **Social Media**: Detect and remove spam posts and messages
221
+ - **E-commerce**: Filter fake reviews and fraudulent listings
222
+ - **Community Management**: Protect online communities from spam bots
223
+ - **API Protection**: Block automated spam attacks on your services
224
+
225
+ ---
226
+
227
+ ## Detection Capabilities
228
+
229
+ The spam detector identifies various types of unwanted content:
230
+
231
+ - **Phishing attempts**: Fake login pages, credential theft
232
+ - **Financial scams**: Lottery scams, investment fraud, fake prizes
233
+ - **Link spam**: Malicious URLs, affiliate link spam
234
+ - **Advertisement spam**: Unsolicited promotional content
235
+ - **Bot-generated content**: Automated spam messages
236
+ - **Social engineering**: Manipulative or deceptive content
237
+
238
+ ---
239
+
240
+ ## API Endpoint
241
+
242
+ **POST** `/content/detect_spam`
243
+
244
+ For detailed API specifications, refer to:
245
+ - [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVU)
246
+ - [Product Page](https://sharpapi.com/en/catalog/ai/content-marketing-automation/spam-detector)
247
+
248
+ ---
249
+
250
+ ## Related Packages
251
+
252
+ - [@sharpapi/sharpapi-node-detect-profanities](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-profanities) - Profanity detection
253
+ - [@sharpapi/sharpapi-node-proofread](https://www.npmjs.com/package/@sharpapi/sharpapi-node-proofread) - Grammar checking
254
+ - [@sharpapi/sharpapi-node-detect-emails](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-emails) - Email extraction
255
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
256
+
257
+ ---
258
+
259
+ ## License
260
+
261
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
262
+
263
+ ---
264
+
265
+ ## Support
266
+
267
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
268
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
269
+ - **Email**: contact@sharpapi.com
270
+
271
+ ---
272
+
273
+ **Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@sharpapi/sharpapi-node-detect-spam",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for detecting spam content in text",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "keywords": [
10
+ "sharpapi",
11
+ "ai-powered",
12
+ "ai capabilities",
13
+ "api",
14
+ "ai api",
15
+ "api integration",
16
+ "artificial intelligence",
17
+ "natural language processing",
18
+ "restful api",
19
+ "nodejs",
20
+ "software development",
21
+ "content analysis",
22
+ "spam detection",
23
+ "text processing"
24
+ ],
25
+ "author": "Dawid Makowski <contact@sharpapi.com>",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
29
+ },
30
+ "devDependencies": {
31
+ "jest": "^29.7.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/sharpapi/sharpapi-node-detect-spam.git"
39
+ }
40
+ }
@@ -0,0 +1,20 @@
1
+ const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for detecting spam content in text using SharpAPI.com
5
+ */
6
+ class SharpApiDetectSpamService extends SharpApiCoreService {
7
+ /**
8
+ * Parses the provided text for any possible spam content.
9
+ *
10
+ * @param {string} text
11
+ * @returns {Promise<string>} - The status URL.
12
+ */
13
+ async detectSpam(text) {
14
+ const data = { content: text };
15
+ const response = await this.makeRequest('POST', SharpApiJobTypeEnum.CONTENT_DETECT_SPAM.url, data);
16
+ return this.parseStatusUrl(response);
17
+ }
18
+ }
19
+
20
+ module.exports = { SharpApiDetectSpamService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-detect-spam/src/index.js
2
+ const { SharpApiDetectSpamService } = require('./SharpApiDetectSpamService');
3
+
4
+ module.exports = {
5
+ SharpApiDetectSpamService,
6
+ };