|
|
@ -8,6 +8,7 @@ import requests
|
|
|
|
from django.forms.models import model_to_dict
|
|
|
|
from django.forms.models import model_to_dict
|
|
|
|
from django.core.serializers.json import DjangoJSONEncoder
|
|
|
|
from django.core.serializers.json import DjangoJSONEncoder
|
|
|
|
from django.db.models import Case, When, F, Max, DateTimeField
|
|
|
|
from django.db.models import Case, When, F, Max, DateTimeField
|
|
|
|
|
|
|
|
from django.db import transaction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -331,7 +332,7 @@ class OsitcomChatRoom(WebsocketConsumer):
|
|
|
|
if not self.visitor:
|
|
|
|
if not self.visitor:
|
|
|
|
self.close()
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
|
|
|
|
if self.scope['url_route']['kwargs'].get('chat_id'): #Case where admin is accessing a specific conversation between the conversations of this visior
|
|
|
|
if self.scope['url_route']['kwargs'].get('chat_id'): #Case where admin is accessing a specific conversation between the conversations of this visitor
|
|
|
|
self.chat_room = get_object_or_404(ChatRoom, id=self.scope['url_route']['kwargs'].get('chat_id'))
|
|
|
|
self.chat_room = get_object_or_404(ChatRoom, id=self.scope['url_route']['kwargs'].get('chat_id'))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
chat_room_guest = ChatRoomGuest.objects.filter(visitor=self.visitor).last() #Case where the visitor will always acesss his last conversation
|
|
|
|
chat_room_guest = ChatRoomGuest.objects.filter(visitor=self.visitor).last() #Case where the visitor will always acesss his last conversation
|
|
|
@ -371,35 +372,40 @@ class OsitcomChatRoom(WebsocketConsumer):
|
|
|
|
self.load_chat_handler(event)
|
|
|
|
self.load_chat_handler(event)
|
|
|
|
|
|
|
|
|
|
|
|
if event_type == 'start_conversation':
|
|
|
|
if event_type == 'start_conversation':
|
|
|
|
chat_room = ChatRoom.objects.create(
|
|
|
|
try:
|
|
|
|
name=f"Support: {self.session_id}",
|
|
|
|
with transaction.atomic():
|
|
|
|
date_created = datetime.now()
|
|
|
|
chat_room = ChatRoom.objects.create(
|
|
|
|
)
|
|
|
|
name=f"Support: {self.session_id}",
|
|
|
|
if text_data_json.get('guest_name'):
|
|
|
|
date_created = datetime.now()
|
|
|
|
self.visitor.name = text_data_json.get('guest_name')
|
|
|
|
)
|
|
|
|
self.visitor.save()
|
|
|
|
if text_data_json.get('guest_name'):
|
|
|
|
if text_data_json.get('guest_mobile_number'):
|
|
|
|
self.visitor.name = text_data_json.get('guest_name')
|
|
|
|
self.visitor.mobile_number = text_data_json.get('guest_mobile_number')
|
|
|
|
self.visitor.save()
|
|
|
|
self.visitor.save()
|
|
|
|
if text_data_json.get('guest_mobile_number'):
|
|
|
|
chat_room_guest = ChatRoomGuest.objects.create(
|
|
|
|
self.visitor.mobile_number = text_data_json.get('guest_mobile_number')
|
|
|
|
room=chat_room,
|
|
|
|
self.visitor.save()
|
|
|
|
visitor=self.visitor
|
|
|
|
chat_room_guest = ChatRoomGuest.objects.create(
|
|
|
|
)
|
|
|
|
room=chat_room,
|
|
|
|
self.chat_room = chat_room
|
|
|
|
visitor=self.visitor
|
|
|
|
async_to_sync(self.channel_layer.group_discard)(
|
|
|
|
)
|
|
|
|
self.group, self.channel_name
|
|
|
|
self.chat_room = chat_room
|
|
|
|
)
|
|
|
|
async_to_sync(self.channel_layer.group_discard)(
|
|
|
|
self.group = f"{self.session_id}_{self.chat_room.id}"
|
|
|
|
self.group, self.channel_name
|
|
|
|
async_to_sync(self.channel_layer.group_add)(
|
|
|
|
)
|
|
|
|
self.group, self.channel_name
|
|
|
|
self.group = f"{self.session_id}_{self.chat_room.id}"
|
|
|
|
)
|
|
|
|
async_to_sync(self.channel_layer.group_add)(
|
|
|
|
event = {
|
|
|
|
self.group, self.channel_name
|
|
|
|
'type': 'start_conversation_handler',
|
|
|
|
)
|
|
|
|
'chat_room_id': chat_room.id
|
|
|
|
event = {
|
|
|
|
}
|
|
|
|
'type': 'start_conversation_handler',
|
|
|
|
async_to_sync(self.channel_layer.group_send)(
|
|
|
|
'chat_room_id': chat_room.id
|
|
|
|
self.group, event
|
|
|
|
}
|
|
|
|
)
|
|
|
|
async_to_sync(self.channel_layer.group_send)(
|
|
|
|
|
|
|
|
self.group, event
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print('Error starting conversation')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if event_type == 'typing':
|
|
|
|
if event_type == 'typing':
|
|
|
|
event = {
|
|
|
|
event = {
|
|
|
|