修复快捷咨询串入人工会话及上下文切换
This commit is contained in:
@@ -42,11 +42,20 @@ def human_poll(sid, after, typing_map):
|
||||
def human_send(data):
|
||||
sid = data.get('sid')
|
||||
side = data.get('side', 'customer')
|
||||
content = (data.get('content') or '').strip()
|
||||
if not sid or not content:
|
||||
content = data.get('content') or ''
|
||||
if not sid or not isinstance(content, str) or not content.strip() or side not in ('customer', 'agent'):
|
||||
return ({'ok': False}, 400)
|
||||
content = content.strip()
|
||||
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
conn = connect()
|
||||
conn.execute('BEGIN IMMEDIATE')
|
||||
row = conn.execute('SELECT conv_id, status FROM human_sessions WHERE id=?', (sid,)).fetchone()
|
||||
if not row:
|
||||
conn.close()
|
||||
return ({'ok': False, 'error': 'session_not_found'}, 404)
|
||||
if row[1] == 'closed' or (data.get('conv_id') is not None and data['conv_id'] != row[0]):
|
||||
conn.close()
|
||||
return ({'ok': False, 'error': 'conversation_changed'}, 409)
|
||||
conn.execute('INSERT INTO human_messages(session_id, side, content, ctime) VALUES(?,?,?,?)', (sid, side, content, now))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user