Skip to content

Instantly share code, notes, and snippets.

@srinivasiyer
Created June 16, 2022 03:44
Show Gist options
  • Save srinivasiyer/2620af88f6e39ebc053388175a4187e0 to your computer and use it in GitHub Desktop.
Save srinivasiyer/2620af88f6e39ebc053388175a4187e0 to your computer and use it in GitHub Desktop.
@tracer.wrap(
service=DatadogService.CHANNELS_SERVICES.value,
name=DatadogOperation.SERVICE_METHOD.value,
resource="ConversationsService.get_conversation",
)
async def get_conversation(
self,
*,
user_group_id: int,
conversation_id: int,
chat_account_id: int,
api_access_token: str,
conversation_display_id: Optional[int],
) -> Conversation:
span = tracer.current_span()
add_tag_to_span(span, "user_group_id", user_group_id)
add_tag_to_span(span, "conversation_id", conversation_id)
add_tag_to_span(span, "chat_account_id", chat_account_id)
add_tag_to_span(span, "api_access_token", api_access_token)
self.__log.info(
statement="get_conversation Init",
description="",
references={"conversation_id": conversation_id},
)
if conversation_display_id is None:
chat_db_conversation: chatDbConversationModel = (
await self.__chat_db_conversations_repository.fetch_one(
conversation_id=conversation_id
)
)
if chat_db_conversation is None:
self.__log.error(
statement="CONVERSATIONS_SERVICE__CONVERSATION_NOT_FOUND",
description="",
references={"conversation_id": conversation_id},
)
raise Exception("CONVERSATIONS_SERVICE__CONVERSATION_NOT_FOUND")
conversation_display_id = chat_db_conversation.display_id
self.__log.info(
statement="get_conversation found chat_db_conversation",
description="",
references={"conversation_id": conversation_id},
)
conversation_model = (
await self.__conversations_repository.fetch_conversation_details(
conversation_id=conversation_display_id,
chat_account_id=chat_account_id,
api_access_token=api_access_token,
)
)
self.__log.info(
statement="get_conversation found conversation_model",
description="",
references={"conversation_id": conversation_id},
)
conversation_assignee = None
if conversation_model.meta.assignee is not None:
conversation_assignee = Assignee(
id=conversation_model.meta.assignee.id,
availability_status=conversation_model.meta.assignee.availability_status,
email=conversation_model.meta.assignee.email,
name=conversation_model.meta.assignee.name,
role=conversation_model.meta.assignee.role,
)
self.__log.info(
statement="get_conversation returning",
description="",
references={"conversation_id": conversation_id},
)
return Conversation(
id=conversation_model.id,
display_id=conversation_display_id,
inbox_id=conversation_model.inbox_id,
chat_account_id=conversation_model.account_id,
hiver_user_group_id=user_group_id,
status=conversation_model.status,
sender=Sender(
id=conversation_model.meta.sender.id,
name=conversation_model.meta.sender.name,
email=conversation_model.meta.sender.email,
phone_number=conversation_model.meta.sender.phone_number,
),
website_url=conversation_model.additional_attributes.referer,
messages=[],
assignee=conversation_assignee,
timestamp=conversation_model.timestamp,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment