# question_answer.dspy - 我的待办里直接回答冒泡问题(回答后问题关闭、任务恢复执行) import json as _json user_id = await get_user() if not user_id: return _json.dumps({"success": False, "error": "未登录"}, ensure_ascii=False) question_id = ((params_kw or {}).get('question_id') or '').strip() answer = ((params_kw or {}).get('answer') or '').strip() if not question_id: return _json.dumps({"success": False, "error": "缺少 question_id"}, ensure_ascii=False) if not answer: return _json.dumps({"success": False, "error": "回答内容不能为空"}, ensure_ascii=False) res = await question_answer(question_id, answer, answered_by=user_id, answer_source='human') ok = False msg = '' if isinstance(res, tuple) or isinstance(res, list): ok = bool(res[0]) if len(res) > 0 else False msg = str(res[1]) if len(res) > 1 else '' elif isinstance(res, dict): if 'success' in res: ok = bool(res.get('success')) elif 'ok' in res: ok = bool(res.get('ok')) else: ok = True msg = str(res.get('message') or res.get('error') or '') else: ok = bool(res) if ok: return _json.dumps({"success": True, "message": msg or "回答已提交,问题关闭,任务恢复执行"}, ensure_ascii=False) return _json.dumps({"success": False, "error": msg or "回答提交失败"}, ensure_ascii=False)