Droid
Email checker with Droid CLI. Verify emails in Droid AI assistant.
Droid 是一個面向開發者的 AI 驅動終端助手。瞭解如何在 Droid 工作流中整合 EmailVerify 進行郵箱驗證。
什麼是 Droid?
Droid 是一個現代 AI 終端助手,提供:
- 智慧命令建議
- 程式碼生成和解釋
- Shell 自動化
- 多模型支援(GPT-4, Claude, 本地模型)
設定
安裝 EmailVerify CLI
npm install -g @emailverify/cli
bv config set api-key YOUR_API_KEY環境設定
export EMAILVERIFY_API_KEY=your-api-key使用 Droid
快速驗證
您: 使用 emailverify 驗證 john@example.com
Droid:
運行: bv verify john@example.com --json
{
"email": "john@example.com",
"status": "valid",
"score": 0.88,
"result": {
"deliverable": true,
"disposable": false,
"role": false
}
}
✅ 郵箱有效(88% 置信度)批次操作
您: 驗證 contacts.csv 中的所有郵箱並建立報告
Droid:
我會處理 CSV 並驗證每個郵箱。
讀取 contacts.csv... 找到 250 條記錄。
進度: ████████████████████ 100%
摘要報告:
┌──────────────┬───────┬────────┐
│ 狀態 │ 數量 │ % │
├──────────────┼───────┼────────┤
│ 有效 │ 198 │ 79.2% │
│ 無效 │ 32 │ 12.8% │
│ 未知 │ 12 │ 4.8% │
│ 一次性 │ 8 │ 3.2% │
└──────────────┴───────┴────────┘
生成的檔案:
- contacts_valid.csv (198 個郵箱)
- contacts_invalid.csv (32 個郵箱)
- contacts_review.csv (20 個郵箱)
您想讓我解釋任何無效郵箱嗎?程式碼生成
您: 建立一個用於郵箱驗證的 Node.js API 端點
Droid:
// routes/verify.ts
import { Router } from 'express';
import rateLimit from 'express-rate-limit';
const router = Router();
// 速率限制:每分鐘 100 次請求
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100,
message: { error: '請求過多' }
});
router.post('/verify', limiter, async (req, res) => {
const { email } = req.body;
if (!email) {
return res.status(400).json({ error: '郵箱地址是必需的' });
}
try {
const response = await fetch('https://api.emailverify.ai/v1/verify', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.EMAILVERIFY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
const result = await response.json();
return res.json({
email,
isValid: result.status === 'valid',
score: result.score,
flags: {
disposable: result.result.disposable,
role: result.result.role,
}
});
} catch (error) {
return res.status(500).json({ error: '驗證服務不可用' });
}
});
export default router;已儲存到 routes/verify.ts
Shell 自動化
您: 建立一個每日驗證新註冊使用者的 cron 任務
Droid:
# 建立驗證腳本
cat > /usr/local/bin/verify-daily-signups.sh << 'EOF'
#!/bin/bash
set -e
LOG_FILE="/var/log/email-verification.log"
DB_HOST="${DB_HOST:-localhost}"
DB_NAME="${DB_NAME:-myapp}"
echo "$(date): 開始每日郵箱驗證" >> $LOG_FILE
# 從資料庫獲取未驗證的郵箱
emails=$(psql -h $DB_HOST -d $DB_NAME -t -c \
"SELECT email FROM users WHERE email_verified IS NULL AND created_at > NOW() - INTERVAL '1 day'")
count=0
invalid=0
for email in $emails; do
result=$(bv verify "$email" --json 2>/dev/null)
status=$(echo "$result" | jq -r '.status')
if [ "$status" = "valid" ]; then
psql -h $DB_HOST -d $DB_NAME -c \
"UPDATE users SET email_verified = true WHERE email = '$email'"
else
psql -h $DB_HOST -d $DB_NAME -c \
"UPDATE users SET email_verified = false, email_status = '$status' WHERE email = '$email'"
((invalid++))
fi
((count++))
sleep 0.1 # 速率限制
done
echo "$(date): 已驗證 $count 個郵箱,$invalid 個無效" >> $LOG_FILE
EOF
chmod +x /usr/local/bin/verify-daily-signups.sh
# 新增到 crontab(每天凌晨 2 點運行)
(crontab -l 2>/dev/null; echo "0 2 * * * /usr/local/bin/verify-daily-signups.sh") | crontab -
echo "✅ Cron 任務已建立。將在每天凌晨 2 點運行。"整合測試
您: 編寫郵箱驗證的整合測試
Droid:
// __tests__/email-verification.test.ts
import { describe, it, expect, beforeAll } from 'vitest';
describe('郵箱驗證整合測試', () => {
const API_URL = 'https://api.emailverify.ai/v1/verify';
let apiKey: string;
beforeAll(() => {
apiKey = process.env.EMAILVERIFY_API_KEY!;
if (!apiKey) {
throw new Error('未設定 EMAILVERIFY_API_KEY');
}
});
async function verifyEmail(email: string) {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
return response.json();
}
it('對已知有效郵箱返回 valid', async () => {
const result = await verifyEmail('test@gmail.com');
expect(result.status).toBe('valid');
expect(result.score).toBeGreaterThan(0.5);
});
it('檢測一次性郵箱', async () => {
const result = await verifyEmail('test@mailinator.com');
expect(result.result.disposable).toBe(true);
});
it('檢測角色郵箱', async () => {
const result = await verifyEmail('info@example.com');
expect(result.result.role).toBe(true);
});
it('處理無效網域', async () => {
const result = await verifyEmail('user@thisisnotarealdomain12345.xyz');
expect(result.status).toBe('invalid');
});
it('返回正確的結構', async () => {
const result = await verifyEmail('user@example.com');
expect(result).toHaveProperty('email');
expect(result).toHaveProperty('status');
expect(result).toHaveProperty('score');
expect(result).toHaveProperty('result');
expect(result.result).toHaveProperty('deliverable');
expect(result.result).toHaveProperty('disposable');
expect(result.result).toHaveProperty('role');
});
});Droid 別名
將這些新增到您的 Droid 設定:
# ~/.droid/aliases.yml
aliases:
vmail:
description: "驗證郵箱地址"
command: "bv verify $1 --color"
vmail-json:
description: "驗證郵箱並輸出 JSON"
command: "bv verify $1 --json | jq ."
vmail-batch:
description: "從檔案驗證郵箱"
command: "bv verify --file $1 --output results.csv"
vmail-check:
description: "快速檢查郵箱是否有效(返回 0 或 1)"
command: "bv verify $1 --quiet"使用方法:
droid vmail user@example.com
droid vmail-batch contacts.txt