使い方
ContAIct には 2 つの組み込み方法があります。用途に合わせて選んでください。
1 API キーを取得する
アカウント登録後、ダッシュボードの「API キー」から新しいキーを発行してください。
キーは作成直後に一度だけ表示されます。必ずメモしてください。
A ブラウザ JS フロー(推奨)
フロントエンドの JS がトークンを取得し、サーバーサイドでスパム判定します。API キーがブラウザに露出しないため安全です。
① フォーム送信時にトークンを取得(JS)
document.getElementById('contactForm').addEventListener('submit', async (e) => {
e.preventDefault();
const text = document.getElementById('body').value;
const res = await fetch('https://my.contaict.app/api/v1/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ api_key: 'YOUR_API_KEY', text }),
});
const { token } = await res.json();
// hidden フィールドにセットしてフォームをサーバーへ送信
document.getElementById('contaict_token').value = token;
e.target.submit();
});
② サーバーサイドでスパム判定(PHP 例)
$token = $_POST['contaict_token'] ?? '';
$ch = curl_init('https://my.contaict.app/api/v1/analyze');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['token' => $token]),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
$score = $result['score']; // 0〜100
$isSales = $result['is_sales']; // true = 営業・勧誘の疑いあり
if ($score >= 70) {
// スパムとして処理(無視・エラー返却など)
} else {
// 通常のお問い合わせとして処理
mail('admin@example.com', $subject, $body);
}
B Bearer フロー(サーバー間)
サーバーから直接 API を呼び出す方法です。フォームデータ受信後にまとめてスパム判定できます。
$text = $_POST['body'] ?? '';
$ch = curl_init('https://my.contaict.app/api/v1/analyze');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['text' => $text]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer YOUR_API_KEY',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
⚠️ API キーはサーバーサイドのみで使用してください。ブラウザ JS に埋め込むと漏洩リスクがあります。
スコアの見方
| スコア | 目安 |
|---|---|
| 0〜29 | 通常のお問い合わせ |
| 30〜69 | 判断が難しい(要確認) |
| 70〜100 | 営業・勧誘の疑いが強い |
デフォルトの閾値は 70 です。ダッシュボードで API キーごとに調整できます。
さっそく試してみましょう
無料登録