For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /product-design/v2/calls-feature/calls-schema.md.

Calls Schema

Source of truth: callytics-common/src/db/schema/calls.ts (verified 2026-06-15) 表名: calls | 主键: telephony_session_id Coaching 字段:practicalCoachingScenario / practicalCoachingFeedback / reviewCategory / reviewReason 物理在 calls 表内,逻辑归 coaching-schema.md(本页标 ↗)


1. 表说明

Calls 表镜像 RingCentral Call Log API 响应(UserCallLogRecord)+ AI 分析结果:

  • RC 字段名在 TypeScript property 里原样保留;SQL 列用 snake_case,Drizzle 自动映射
  • RC 元数据由 transcribe-processor Lambda 写入(通话管道早期)
  • AI 分析字段由 ai-analysis-processor Lambda 在分析完成后 direct write
  • 所有枚举字段都是 text 列 + 注释里写约束,无 DB CHECK,无 const 数组 — 合法值靠写入方(AI pipeline)遵守

写入者列说明:

  • code = transcribe-processor / message-processor 等管道自动写入(RC 元数据 / 隔离字段 / pipeline 时间戳)
  • ai = ai-analysis-processor 写入(AI 分析字段 / cost)

2. Schema 全字段

90 列按存储顺序列出。Writer 列:code = transcribe-processor / message-processor 等管道;ai = ai-analysis-processor;ai (transcribe-processor) 等表示某 Lambda 专写。AI 枚举字段(callState / customerType 等)全在 §3 AI 枚举清单展开。

#FieldTypeNullableEnum / ValuesWriter用途
1telephonySessionIdtext (PK)NOT NULL—codeRC telephony session ID(每通通话唯一,主键)
2idtextNULL—codeRC 内部 call log record ID
3sessionIdtextNULL—codeRC session ID
4startTimetimestamptzNOT NULL—code通话开始时间
5durationintegerNULL—code通话时长(秒)
6typetextNULLVoice | Faxcode通话类型
7transporttextNULLPSTN | VoIPcode传输方式
8directiontextNOT NULLInbound | Outboundcode通话方向
9resulttextNULLAccepted | Missed | No Answer | Busy | Voicemail | Hang Up | ...codeRC 通话结果
10actiontextNULLPhone Call | VoIP Call | Incoming Fax | ...codeRC 动作类型
11reasontextNULLAccepted | Connected | Busy | BlindTransfer | ...code挂断原因
12reasonDescriptiontextNULL—code原因的自由文本描述
13shortRecordingbooleanNULLtrue / falsecode录音过短(< 30s)无法存储时为 true
14deletedbooleanNULLtrue / falsecode软删除标记(ISync 用)
15lastModifiedTimetimestamptzNULL—codeRC 最后修改此记录的时间
16fromPhoneNumbertextNULL—code主叫号码(from RC from 对象拍平)
17fromNametextNULL—code主叫名
18fromExtensionIdtextNULL—code主叫分机 ID
19fromExtensionNumbertextNULL—code主叫分机号
20fromLocationtextNULL—code主叫位置
21fromDeviceIdtextNULL—code主叫设备 ID
22toPhoneNumbertextNULL—code被叫号码(from RC to 对象拍平)
23toNametextNULL—code被叫名
24toExtensionIdtextNULL—code被叫分机 ID
25toExtensionNumbertextNULL—code被叫分机号
26toLocationtextNULL—code被叫位置
27toDeviceIdtextNULL—code被叫设备 ID
28extensionIdtextNULL—codecall record 所属分机(owner)
29recordingIdtextNULL—code录音 ID(from RC recording 对象)
30recordingTypetextNULL—code录音类型
31recordingContentUritextNULL—code录音内容 URI
32billingCostIncludednumericNULL—code套餐内话费(from RC billing 对象)
33billingCostPurchasednumericNULL—code额外购买话费
34messageIdtextNULL—code关联的语音留言/传真消息 ID(from RC message 对象)
35messageTypetextNULL—code消息类型
36delegateIdtextNULL—code代理(秘书)ID(from RC delegate 对象)
37delegateNametextNULL—code代理名
38legsjsonbNULL—codeRC Detailed view 的完整 legs 数组
39rawCallLogjsonbNULL—code完整 Call Log API 响应(不截断)
40accountIdtextNOT NULL—codeRC account ID(多租户隔离审计字段)
41legacySiteIdtext (SQL site_id)NOT NULL—code@deprecated — 与 account_id 冗余,保留向后兼容。注意 TS 名 legacySiteId ↔ SQL 列 site_id
42franchiseIdtextNOT NULL—code品牌标识
43storeIdtextNULL—codeDynamoDB StoresV2 store UUID,终态隔离键。由 ai-analysis-processor + transcribe-processor 经 resolvePhoneIdentity() 写入。Phase 3 rollout 前为 NULL
44clientIdtextNULL—code我们的复合键 {franchise}-{siteId}
45durationMsintegerNULL—code时长(毫秒,高精度)
46internalTypetextNULL—code内部通话类型分类(TollFreeNumber / Local 等)
47partyExtensionIdtextNULL—codeWebhook party 分机 ID
48callStatetextNULL6 值,见 §3ai通话状态(驱动下游 gate 决策)
49staffNametextNULL—ai员工姓名(AI 从对话识别)
50staffConfidencenumericNULL0-1ai员工识别置信度
51originalStaffNametextNULL—ai首次修订前的原始员工名(审计)
52amendmentHistoryjsonbNULL[{from, to, amendedBy, amendedAt, reason}]ai修订历史
53customerTypetextNULL5 值,见 §3ai客户类型
54customerConfidencenumericNULL0-1ai客户类型置信度
55customerEvidencetextNULL—ai判断客户类型的证据
56primaryTopicTypetextNULL—ai主题类型分类
57primaryCategorytextNULL4 值,见 §3ai主题大类
58primarySubcategorytextNULL—ai主题子分类
59primaryOutcomeResulttextNULL6 值,见 §3ai主结果
60primaryOutcomeReasoningtextNULL—ai结果判断的推理过程
61creditCardCapturedtextNULLyes | no | naai是否采集到信用卡
62primaryEvidencetextNULL—ai支持主题判断的转录证据
63secondaryTopicsjsonb (string[])NULL—ai二级主题子分类列表
64revenuePrioritytextNULL4 值,见 §3ai收入优先级
65revenuePriorityEvidencetextNULL—ai收入优先级判断的证据
66executiveSummarytextNULL—aiAI 生成的通话摘要
67followUpNeededtextNULLyes | noai是否需要跟进
68followUpReasonsjsonb (string[])NULL—ai需要跟进的原因列表
69practicalCoachingScenario ↗textNULL—aiAI 识别的辅导场景 — 详见 coaching-schema.md
70practicalCoachingFeedback ↗jsonbNULL{timestamp, what_was_said, context, ...}aiAI 详细辅导反馈 — 详见 coaching-schema.md
71reviewCategory ↗textNULL6 值,见 coaching-schema.mdaiAI 通话质量评估 — 详见 coaching-schema.md
72reviewReason ↗textNULL—aireviewCategory ≠ NOT_REQUIRED 时的说明(1-2 句话)— 详见 coaching-schema.md
73inputTokensintegerNULL—ai输入 token 数
74outputTokensintegerNULL—ai输出 token 数
75reasoningTokensintegerNULL—ai推理 token 数(部分模型支持)
76totalTokensintegerNULL—ai总 token 数
77estimatedCostUsdnumericNULL—ai预估成本(USD)
78aiModelUsedtextNULL—ai实际使用的 AI 模型 ID
79s3AnalysisPathtextNULL—aiAI 分析结果在 S3 的完整路径
80callLogFetchedAttimestamptzNULL—transcribe-processorRC call log 已拉取存储(Disconnected 事件的首步)。Pipeline 进度时间戳:NULL=未到达,NOT NULL=到达时间
81recordingAvailableAttimestamptzNULL—transcribe-processor确认 RC 录音可下载
82transcribeStartedAttimestamptzNULL—transcribe-processor开始下载 + 转录
83transcribeCompletedAttimestamptzNULL—transcribe-processor转录完成
84aiAnalysisStartedAttimestamptzNULL—ai-analysis-processor开始 AI 分析
85aiAnalysisCompletedAttimestamptzNULL—ai-analysis-processorAI 分析完成
86contactsCompletedAttimestamptzNULL—contacts-analyzer / ai-analysis-processortask 已生成;或 AI 分析跳过(voicemail / no-answer)
87leadIdtextNULL—codeLead ID(用于关联 contacts 表)
88contactPhonetextNULL—code客户电话号码(用于关联 contacts 表)
89syncedAttimestamptzNOT NULLDEFAULT NOW()code首次同步此记录的时间
90updatedAttimestamptzNOT NULLDEFAULT NOW(), $onUpdatecode最后更新时间(Drizzle db.update() 自动刷新)

Pipeline 进度时间戳(#80-86)Reconciliation 用 WHERE X_at IS NOT NULL AND Y_at IS NULL AND age > threshold 找卡住的通话。COALESCE 规则:_started_at / _available_at 保留首个值;_completed_at 取最新值。


3. AI 枚举清单

所有 AI 枚举字段都是 text 列 + 注释约束,无 DB CHECK。合法值靠写入方(prompt + Lambda 代码)遵守。Reviewer 验 prompt 输出时按本表对照。

枚举字段值含义
callStatehuman_conversation | voicemail | no_answer | busy_signal | system_error | No Transcript通话状态(驱动下游 gate)
customerTypeprospective_client | existing_member | former_member | returning_visitor | other客户类型
primaryCategoryrevenue_impacting | service | scheduling | other主题大类
primaryOutcomeResultsuccess | attempted | na | cancelled | retained | pending_follow_up主结果
revenuePriorityhigh | medium | low | none收入优先级
followUpNeededyes | no是否需要跟进
creditCardCapturedyes | no | na是否采集到信用卡

reviewCategory 枚举(NOT_REQUIRED ~90-95% | EXEMPLARY | FAILURE | CHURN_RISK | MISSED_OPPORTUNITY | ESCALATION)归 coaching-schema.md。


4. Prompt Output ↔ Schema 字段对照(给 reviewer 用)

Reviewer 用本表验证 prompt 输出 JSON 字段是否落在 calls 表内。

Prompt写入字段备注
01 TriagecallState / staffName / staffConfidence(+ worth_analyzing 不入库,仅 gate Classify/Coaching)Triage 输出在 pipeline.ts:192-193 上调,最终随 Classify 一起 persist 到 calls(见 lambda/ai-analysis-processor/src/core/stages/triage.ts:5)
02 ClassifycustomerType / customerConfidence / customerEvidence / primaryCategory / primarySubcategory / primaryTopicType / primaryOutcomeResult / primaryOutcomeReasoning / primaryEvidence / creditCardCaptured / revenuePriority / revenuePriorityEvidence / executiveSummary / followUpNeeded / followUpReasons / secondaryTopics主要写入 prompt — reviewer 重点验证输出字段 ∈ §2 行 48-72(去掉 Triage 已写的 callState/staffName/staffConfidence)
03 Verify(conditional verification fields,不直接写 calls 表)n/a
04 CoachingpracticalCoachingScenario / practicalCoachingFeedback / reviewCategory / reviewReason见 coaching-schema.md
05 Contact Profile(写 contacts 表,见 contacts-schema.md)n/a
06 Task Decision(写 tasks + task_progress_events,见 tasks-schema.md)n/a
07 Task Playbook(read-only)n/a

5. Appendix A — Re-verification commands

2026-06-01 verified。文档 stale(>30 天)时重跑下方命令并比对。

# 1. calls 表所有 column
grep -E "^\s*[a-zA-Z]+: (text|integer|timestamp|boolean|numeric|jsonb)\(" \
  ../../../../../callytics-common/src/db/schema/calls.ts

# 2. 枚举值(注释里的)
grep -E "/\*\*.*\|" ../../../../../callytics-common/src/db/schema/calls.ts

# 3. Task pipeline design 是否动 calls
grep -i "calls\." ../../tasks-feature/design/task-pipeline-deliverable-codex.md
# 期望: 只 reference 不修改 schema

# 4. Unified pipeline 是否动 calls
grep -i "calls\." ../../unified-pipeline/unified-pipeline-final.md
# 期望: 只 reference 不修改 schema

6. Cross-References