Synchronize email activities and quotation events with OKKI CRM as follow-up trail records. Automatically matches emails to CRM customers via domain lookup and vector search, creates trail records (email type=102, quotation type=101), and deduplicates entries. Requires OKKI CRM API access and optional vector search setup. Use when you need to automatically log email communications and quotation events in your CRM.
OKKI 双向同步:邮件和报价单自动写入 OKKI CRM 跟进记录。
这是一个集成模块,不作为独立 skill 运行,而是 hook 到现有的 imap-smtp-email 和 quotation-workflow skills 中,实现:
主文件: scripts/okki-sync.js(同步镜像至 $WORKSPACE/skills/imap-smtp-email/okki-sync.js)
javascript
const okkiSync = require(./scripts/okki-sync);
// 客户匹配(两阶段:域名 → 向量搜索)
const customer = await okkiSync.matchCustomer(email, subject, body);
// → { companyid, name, matchtype, confidence } | null
// 创建邮件跟进记录(trail_type=102)
const result = await okkiSync.createEmailTrail(companyId, {
uid, // 去重 key
from, // 发件人
to, // 收件人
subject, // 主题
date, // 时间
body, // 正文摘要
direction, // in | out
attachments // [{ filename }]
});
// 创建报价单跟进记录(trail_type=101)
const result = await okkiSync.createQuotationTrail(companyId, {
uid, // 去重 key
quotationNo, // 报价单编号
date, // 日期
products, // [{ name, quantity, unit_price }]
totalAmount, // USD 9730.00
validUntil // 有效期
});
// 完整邮件同步流程(匹配 + 创建 trail)
const result = await okkiSync.syncEmailToOkki(emailData);
bash
| 类型 | 编号 | 说明 |
|---|---|---|
| QUOTATION | 101 | 快速记录 / 报价单 |
| 依赖 | 路径 | 说明 |
|---|---|---|
| OKKI CLI | $WORKSPACE/xiaoman-okki/api/okki.py | OKKI API 客户端(trail add 命令) |
| 向量搜索 |
javascript
// $WORKSPACE/skills/imap-smtp-email/scripts/smtp.js
// L13: require(../okki-sync)
// L131+: 发送成功后异步调用
const { syncEmailToOkki } = require(../okki-sync);
syncEmailToOkki({
uid: smtp-${Date.now()}-${toHash},
from, to, subject, date,
body: text,
direction: out,
attachments
}).then(r => console.log(OKKI sync:, r))
.catch(e => console.warn(OKKI sync failed:, e.message));
bash
| 文件 | 说明 |
|---|---|
| /tmp/okki-sync-processed.json | 去重记录(已处理的 UID → metadata) |
| /tmp/okki-unmatched-emails.log |
matchCustomer(email, subject?, body?)
├── 提取域名(extractDomain)
├── 是否公共域名?(gmail/yahoo/hotmail/outlook/qq/163/126 等)
│ ├── YES → 跳过域名匹配,直接向量搜索
│ └── NO → 域名精确匹配(OKKI CLI company list -k
│ ├── 精确命中 → confidence=0.95,返回
│ ├── 部分匹配 → confidence=0.7,返回
│ └── 无匹配 → 向量搜索
└── 向量搜索(search-customers.py
├── 命中 → confidence=topMatch.score,返回
└── 无匹配 → 写入 unmatched log,返回 null
端到端测试结果(2026-03-24)
generate-all.sh cable-germany.json QT-E2E-002 | 88050865152265 | ✅ 通过 |链路 命令 Trail ID 结果 链路A 邮件→OKKI smtp.js send --to service@tkscable.com 88050591907961 ✅ 通过 链路B 报价单→OKKI
| 链路C 公共域名 | test@gmail.com 匹配失败 | — | ✅ 通过(unmatched 日志写入) |
| 去重验证 | 相同 UID 重复触发 | — | ✅ 通过(返回 duplicate) |
设置说明
如需将此模块集成到新 skill 中:
| 时间 | 操作 | Agent | 备注 |
|---|---|---|---|
| 2026-03-24 09:56 | reviewcompleted | WILSON | 任务审阅完成,批准执行 |
| 2026-03-24 11:30 |
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 okki-email-sync-1775989561 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 okki-email-sync-1775989561 技能
skillhub install okki-email-sync-1775989561
文件大小: 11.37 KB | 发布时间: 2026-4-13 11:15