fix: report AI table binding validation failures
This commit is contained in:
@@ -150,16 +150,51 @@ func (c *Controller) Handle(ctx context.Context, in SettingInput) (string, error
|
||||
}
|
||||
kind := action + "_table"
|
||||
err = c.repo.SaveBinding(ctx, ResourceBinding{Kind: kind, TenantKey: in.TenantKey, BaseID: link.BaseID, SheetID: link.SheetID, ViewID: link.ViewID, OperatorID: in.UnionID, CreatedByStaffID: in.StaffID})
|
||||
if err == nil {
|
||||
_ = c.repo.DeleteSettingSession(ctx, in.TenantKey, in.StaffID)
|
||||
return fmt.Sprintf("✅ %s已解析并保存为待验证配置。", map[string]string{"question": "问题AI表格", "faq": "FAQ表格"}[action]), nil
|
||||
if err != nil {
|
||||
return tableBindingFailureReply(action, err), nil
|
||||
}
|
||||
_ = c.repo.DeleteSettingSession(ctx, in.TenantKey, in.StaffID)
|
||||
return fmt.Sprintf("✅ %sSchema验证通过并已激活,DobotAI将短暂重启加载Dispatcher。", map[string]string{"question": "问题AI表格", "faq": "FAQ表格"}[action]), nil
|
||||
default:
|
||||
return "未知设置项。发送 /setting 查看菜单。", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
func tableBindingFailureReply(action string, err error) string {
|
||||
label := map[string]string{"question": "问题AI表格", "faq": "FAQ表格"}[action]
|
||||
if label == "" {
|
||||
label = "AI表格"
|
||||
}
|
||||
code := "table_validation_failed"
|
||||
guidance := "请检查链接是否来自目标表格中的任意记录,并确认字段名称和类型符合提示要求。"
|
||||
raw := ""
|
||||
if err != nil {
|
||||
raw = strings.ToLower(err.Error())
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(raw, "schema_http_401"), strings.Contains(raw, "schema_http_403"), strings.Contains(raw, "schema_token_failed"):
|
||||
code = "table_permission_denied"
|
||||
guidance = "请确认机器人应用已开通钉钉AI表格接口权限,并确认当前管理员对目标表格有访问和编辑权限。"
|
||||
case strings.Contains(raw, "missing_field"):
|
||||
code = "table_schema_missing_field"
|
||||
guidance = "目标表缺少必需字段,请按上一条提示补齐字段后重试。"
|
||||
case strings.Contains(raw, "duplicate_field"):
|
||||
code = "table_schema_duplicate_field"
|
||||
guidance = "目标表存在重名必需字段,请保留唯一字段后重试。"
|
||||
case strings.Contains(raw, "field_type_mismatch"):
|
||||
code = "table_schema_field_type_mismatch"
|
||||
guidance = "目标表的必需字段类型不正确,请按上一条提示调整字段类型后重试。"
|
||||
case strings.Contains(raw, "schema_network_failed"), strings.Contains(raw, "schema_request_failed"), strings.Contains(raw, "schema_read_failed"):
|
||||
code = "table_schema_network_failed"
|
||||
guidance = "钉钉AI表格接口暂时不可用,请稍后重试。"
|
||||
case strings.Contains(raw, "schema_decode_failed"), strings.Contains(raw, "schema_empty"):
|
||||
code = "table_schema_response_invalid"
|
||||
guidance = "未读取到可用字段,请确认链接指向AI表格中的具体数据表。"
|
||||
}
|
||||
return fmt.Sprintf("❌ %s验证失败,新配置未激活。\n错误码:%s\n%s\n当前设置仍在10分钟等待期内,可直接重新发送链接卡片;发送“取消”退出。", label, code, guidance)
|
||||
}
|
||||
|
||||
func tableBindingInstructions(action string) string {
|
||||
if action == "faq" {
|
||||
return "请在10分钟内直接发送FAQ表中任意一条记录的链接(钉钉显示为链接卡片也可以直接发送)。\n\n" +
|
||||
|
||||
Reference in New Issue
Block a user