@@ -213,12 +213,21 @@ def get_message(instance):
213
213
return instance .get ('messages' )[- 1 ].get ('content' )
214
214
215
215
@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 ):
217
217
if chat_id is None :
218
218
chat_id = str (uuid .uuid1 ())
219
219
chat = QuerySet (Chat ).filter (id = chat_id ).first ()
220
220
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 ()
222
231
return chat_id
223
232
224
233
def chat (self , instance : Dict , with_valid = True ):
@@ -232,7 +241,8 @@ def chat(self, instance: Dict, with_valid=True):
232
241
application_id = self .data .get ('application_id' )
233
242
client_id = self .data .get ('client_id' )
234
243
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" ))
236
246
return ChatMessageSerializer (
237
247
data = {
238
248
'chat_id' : chat_id , 'message' : message ,
0 commit comments