@@ -213,12 +213,21 @@ def get_message(instance):
213213 return instance .get ('messages' )[- 1 ].get ('content' )
214214
215215 @staticmethod
216- def generate_chat (chat_id , application_id , message , client_id ):
216+ def generate_chat (chat_id , application_id , message , client_id , asker = None ):
217217 if chat_id is None :
218218 chat_id = str (uuid .uuid1 ())
219219 chat = QuerySet (Chat ).filter (id = chat_id ).first ()
220220 if chat is None :
221- Chat (id = chat_id , application_id = application_id , abstract = message [0 :1024 ], client_id = client_id ).save ()
221+ asker_dict = {'user_name' : '游客' }
222+ if asker is not None :
223+ if isinstance (asker , str ):
224+ asker_dict = {
225+ 'user_name' : asker
226+ }
227+ elif isinstance (asker , dict ):
228+ asker_dict = asker
229+ Chat (id = chat_id , application_id = application_id , abstract = message [0 :1024 ], client_id = client_id ,
230+ asker = asker_dict ).save ()
222231 return chat_id
223232
224233 def chat (self , instance : Dict , with_valid = True ):
@@ -232,7 +241,8 @@ def chat(self, instance: Dict, with_valid=True):
232241 application_id = self .data .get ('application_id' )
233242 client_id = self .data .get ('client_id' )
234243 client_type = self .data .get ('client_type' )
235- chat_id = self .generate_chat (chat_id , application_id , message , client_id )
244+ chat_id = self .generate_chat (chat_id , application_id , message , client_id ,
245+ asker = instance .get ('form_data' , {}).get ("asker" ))
236246 return ChatMessageSerializer (
237247 data = {
238248 'chat_id' : chat_id , 'message' : message ,
0 commit comments