# Path: golem/core/chat_session.py
# class ChatSession:
# 
#     def __init__(self, interface, unique_id: str, meta=None, profile=None, is_logged=True, is_admin=False, is_test=False):
#         """
#         :param interface: Chat interface object
#         :param unique_id: A string that uniquely identifies the user within the interface
#         :param profile: Profile object
#         :param meta: Any interface-specific data. type: dict
#         """
#         if interface is None:
#             raise ValueError("Interface must be set")
#         elif not isinstance(unique_id, str):
#             raise ValueError("UID must be a string")
#         elif not isinstance(profile, Profile) and profile is not None:
#             raise ValueError("Profile must be instance of class Profile")
#         self.interface = interface
#         self.chat_id = self.interface.prefix + "_" + unique_id
#         self.profile = profile or Profile()
#         self.meta = meta or {}
#         self.is_logged = is_logged
#         self.is_admin = is_admin
#         self.is_test = is_test
# 
#     def to_json(self):
#         return {
#             "interface": self.interface.prefix,
#             "unique_id": self.chat_id.split('_', maxsplit=1)[1],
#             "profile": self.profile.to_json(),
#             "meta": self.meta,
#             "is_logged": self.is_logged,
#             "is_admin": self.is_admin
#         }
# 
#     @staticmethod
#     def from_json(data: dict):
#         interface = create_from_prefix(data['interface'])
#         return ChatSession(
#             interface=interface,
#             unique_id=data['unique_id'],
#             profile=Profile.from_json(data['profile']),
#             meta=data['meta'],
#             is_logged=data['is_logged'],
#             is_admin=data['is_admin']
#         )
# 
# Path: golem/core/logging/abs_logger.py
# class MessageLogger(ABC):
#     def __init__(self):
#         pass
# 
#     @abstractmethod
#     def log_user_message(self, dialog, time, state, message, type_, entities):
#         pass
# 
#     @abstractmethod
#     def log_bot_message(self, dialog, time, state, message):
#         pass
# 
#     def log_error(self, dialog, state, exception):
#         pass
# 
#     def log_user(self, dialog, chat_session):
#         pass


import json
import time
from golem.core.chat_session import ChatSession
from golem.core.logging.abs_logger import MessageLogger
    from elasticsearch import Elasticsearch
    from django.conf import settings
        from golem.core.responses import TextMessage
        if '_message_text' in entities:
            text = entities['_message_text'][0]['value']
            del (entities['_message_text'])

        message = {
            'uid': dialog.session.chat_id,
            'test_id': self.test_id,
            'created': time,
            'is_user': True,
            'text': text,
            'state': state,
            'type': type_,
            'entities': entities
        }
        self._log_message(message)

    def log_bot_message(self, dialog, time, state, message):
        type_ = type(message).__name__ if message else 'TextMessage'
        response = json.loads(
            json.dumps(message, default=lambda obj: obj.__dict__ if hasattr(obj, '__dict__') else str(obj)))

        text = message.text if hasattr(message, 'text') else str(message)

        message = {
            'uid': dialog.session.chat_id,
            'test_id': self.test_id,
            'created': time,
            'is_user': False,
            'text': text,
            'state': state,

# Path: golem/core/chat_session.py
# class ChatSession:
# 
#     def __init__(self, interface, unique_id: str, meta=None, profile=None, is_logged=True, is_admin=False, is_test=False):
#         """
#         :param interface: Chat interface object
#         :param unique_id: A string that uniquely identifies the user within the interface
#         :param profile: Profile object
#         :param meta: Any interface-specific data. type: dict
#         """
#         if interface is None:
#             raise ValueError("Interface must be set")
#         elif not isinstance(unique_id, str):
#             raise ValueError("UID must be a string")
#         elif not isinstance(profile, Profile) and profile is not None:
#             raise ValueError("Profile must be instance of class Profile")
#         self.interface = interface
#         self.chat_id = self.interface.prefix + "_" + unique_id
#         self.profile = profile or Profile()
#         self.meta = meta or {}
#         self.is_logged = is_logged
#         self.is_admin = is_admin
#         self.is_test = is_test
# 
#     def to_json(self):
#         return {
#             "interface": self.interface.prefix,
#             "unique_id": self.chat_id.split('_', maxsplit=1)[1],
#             "profile": self.profile.to_json(),
#             "meta": self.meta,
#             "is_logged": self.is_logged,
#             "is_admin": self.is_admin
#         }
# 
#     @staticmethod
#     def from_json(data: dict):
#         interface = create_from_prefix(data['interface'])
#         return ChatSession(
#             interface=interface,
#             unique_id=data['unique_id'],
#             profile=Profile.from_json(data['profile']),
#             meta=data['meta'],
#             is_logged=data['is_logged'],
#             is_admin=data['is_admin']
#         )
# 
# Path: golem/core/logging/abs_logger.py
# class MessageLogger(ABC):
#     def __init__(self):
#         pass
# 
#     @abstractmethod
#     def log_user_message(self, dialog, time, state, message, type_, entities):
#         pass
# 
#     @abstractmethod
#     def log_bot_message(self, dialog, time, state, message):
#         pass
# 
#     def log_error(self, dialog, state, exception):
#         pass
# 
#     def log_user(self, dialog, chat_session):
#         pass


# Path: golem/core/logging/elastic.py
import json
import time
from golem.core.chat_session import ChatSession
from golem.core.logging.abs_logger import MessageLogger
    from elasticsearch import Elasticsearch
    from django.conf import settings
        from golem.core.responses import TextMessage

        if '_message_text' in entities:
            text = entities['_message_text'][0]['value']
            del (entities['_message_text'])

        message = {
            'uid': dialog.session.chat_id,
            'test_id': self.test_id,
            'created': time,
            'is_user': True,
            'text': text,
            'state': state,
            'type': type_,
            'entities': entities
        }
        self._log_message(message)

    def log_bot_message(self, dialog, time, state, message):
        type_ = type(message).__name__ if message else 'TextMessage'
        response = json.loads(
            json.dumps(message, default=lambda obj: obj.__dict__ if hasattr(obj, '__dict__') else str(obj)))

        text = message.text if hasattr(message, 'text') else str(message)

        message = {
            'uid': dialog.session.chat_id,
            'test_id': self.test_id,
            'created': time,
            'is_user': False,
            'text': text,
            'state': state,

            'type': type_,