### Install ALTCHA Dependencies Source: https://context7.com/altcha-org/tutorials/llms.txt Install the necessary ALTCHA packages and the Astro Node adapter for server-side rendering. Then, start the development server. ```bash # Install ALTCHA packages npm install altcha altcha-lib # Install Astro Node adapter for server-side rendering npm install @astrojs/node # Start development server npm run dev ``` -------------------------------- ### Start development server Source: https://github.com/altcha-org/tutorials/blob/main/invisible-captcha/README.md Execute this command to launch the local development server. ```sh bun run dev ``` -------------------------------- ### Install project dependencies Source: https://github.com/altcha-org/tutorials/blob/main/invisible-captcha/README.md Run this command to install all required packages defined in the project configuration. ```sh bun install ``` -------------------------------- ### Start the development server Source: https://github.com/altcha-org/tutorials/blob/main/astro/README.md Run this command in the terminal to launch the local development environment. ```bash npm run dev ``` -------------------------------- ### Install Dependencies for Invisible Captcha Server Source: https://context7.com/altcha-org/tutorials/llms.txt Navigate to the 'invisible-captcha' directory and run this command to install project dependencies using Bun. ```bash # Navigate to invisible-captcha directory cd invisible-captcha # Install dependencies bun install ``` -------------------------------- ### Start Invisible Captcha Development Server Source: https://context7.com/altcha-org/tutorials/llms.txt Run this command to start the Hono-based spam filter server with hot reloading using Bun. The server will be accessible at http://localhost:3000. ```bash # Start development server with hot reloading bun run dev ``` -------------------------------- ### Invisible Captcha with Spam Filter API using Hono Source: https://context7.com/altcha-org/tutorials/llms.txt Use the ALTCHA Spam Filter API with Hono and Bun runtime for server-side content classification. This example classifies form submissions without a visible widget and requires API keys and referrer configuration. ```typescript // src/index.ts import { Hono } from 'hono'; const API_KEY = 'ckey_your_api_key_here'; const REFERRER = 'https://yourdomain.com/'; const app = new Hono(); async function makeSpamFilterRequest( body: { email?: string; fields?: Record; ipAddress?: string; } ) { const resp = await fetch(`https://eu.altcha.org/api/v1/classify?apiKey=${API_KEY}`, { body: JSON.stringify(body), headers: { 'content-type': 'application/json', 'referer': REFERRER }, method: 'POST', }); if (resp.status !== 200) { throw new Error('Unexpected server response'); } return resp.json(); } app.get('/', (c) => { return c.text('Hello Hono!'); }); app.post('/submit', async (c) => { const ipAddress = c.req.header('x-forwarded-for')?.split(',')[0]; const body = await c.req.parseBody(); const { classification } = await makeSpamFilterRequest({ email: String(body.email), fields: { name: String(body.name), message: String(body.message), }, ipAddress, }); if (classification === 'BAD') { return c.json({ error: 'Cannot submit spam.', success: false, }, 400); } // Process legitimate submissions return c.json({ success: true, }); }); export default app; ``` -------------------------------- ### Fetch Challenge from ALTCHA API Source: https://context7.com/altcha-org/tutorials/llms.txt Use this cURL command to fetch a proof-of-work challenge from the ALTCHA API. Replace 'ckey_your_api_key_here' with your actual API key. The response includes algorithm, challenge, salt, and signature details. ```bash # Fetch a challenge from ALTCHA API curl -X GET "https://eu.altcha.org/api/v1/challenge?apiKey=ckey_your_api_key_here" ``` -------------------------------- ### Astro Configuration for Server-Side Rendering Source: https://context7.com/altcha-org/tutorials/llms.txt Configure Astro with the Node adapter in standalone mode to enable POST request handling, which is necessary for server-side ALTCHA verification. ```javascript // astro.config.mjs import { defineConfig } from 'astro/config'; import node from "@astrojs/node"; export default defineConfig({ output: "server", adapter: node({ mode: "standalone" }) }); ``` -------------------------------- ### ALTCHA Widget Integration with Astro Source: https://context7.com/altcha-org/tutorials/llms.txt Embed the ALTCHA widget in an Astro page for client-side challenge and verify the solution server-side using altcha-lib. Requires API keys for configuration. ```astro --- // src/pages/index.astro import { verifySolution } from "altcha-lib"; // Configure your own API Key: https://altcha.org/docs/api/api_keys const ALTCHA_API_KEY = "ckey_your_api_key_here"; const ALTCHA_API_SECRET = "csec_your_api_secret_here"; if (Astro.request.method === "POST") { try { const data = await Astro.request.formData(); const altchaPayload = data.get("altcha")?.toString(); if (!altchaPayload) { throw new Error("Altcha payload missing."); } if (await verifySolution(altchaPayload, ALTCHA_API_SECRET)) { console.log('Verification successful', Object.fromEntries(data)); // Process form data here } else { console.log('Verification failed'); // Handle verification failure } } catch (error) { if (error instanceof Error) { console.error(error.message); } } } --- ALTCHA Form Example
``` -------------------------------- ### Submit Content for Spam Classification Source: https://context7.com/altcha-org/tutorials/llms.txt Submit form content to the ALTCHA Classify API for spam detection. This cURL command includes email, fields, and IP address in JSON format. Ensure to set the correct Content-Type and Referer headers. The response indicates if the content is classified as 'GOOD' or 'BAD'. ```bash # Submit content for spam classification curl -X POST "https://eu.altcha.org/api/v1/classify?apiKey=ckey_your_api_key_here" \ -H "Content-Type: application/json" \ -H "Referer: https://yourdomain.com/" \ -d '{ "email": "user@example.com", "fields": { "name": "John Doe", "message": "Hello, I would like to inquire about your services." }, "ipAddress": "192.168.1.1" }' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.