letschatty 0.4.349__py3-none-any.whl → 0.4.351__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. letschatty/models/ai_microservices/__init__.py +4 -4
  2. letschatty/models/ai_microservices/expected_output.py +29 -2
  3. letschatty/models/ai_microservices/lambda_events.py +155 -28
  4. letschatty/models/ai_microservices/lambda_invokation_types.py +4 -1
  5. letschatty/models/ai_microservices/n8n_ai_agents_payload.py +3 -1
  6. letschatty/models/analytics/events/__init__.py +3 -3
  7. letschatty/models/analytics/events/chat_based_events/ai_agent_execution_event.py +71 -0
  8. letschatty/models/analytics/events/chat_based_events/chat_funnel.py +13 -69
  9. letschatty/models/analytics/events/company_based_events/asset_events.py +2 -9
  10. letschatty/models/analytics/events/event_type_to_classes.py +3 -7
  11. letschatty/models/analytics/events/event_types.py +50 -11
  12. letschatty/models/chat/chat.py +2 -13
  13. letschatty/models/chat/chat_with_assets.py +1 -6
  14. letschatty/models/chat/client.py +2 -0
  15. letschatty/models/chat/continuous_conversation.py +1 -1
  16. letschatty/models/company/CRM/funnel.py +33 -365
  17. letschatty/models/company/__init__.py +1 -7
  18. letschatty/models/company/assets/ai_agents_v2/ai_agents_decision_output.py +1 -1
  19. letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent_in_chat.py +4 -0
  20. letschatty/models/company/assets/ai_agents_v2/chatty_ai_mode.py +2 -2
  21. letschatty/models/company/assets/ai_agents_v2/get_chat_with_prompt_response.py +1 -0
  22. letschatty/models/company/assets/ai_agents_v2/pre_qualify_config.py +28 -1
  23. letschatty/models/company/assets/automation.py +19 -10
  24. letschatty/models/company/assets/chat_assets.py +2 -3
  25. letschatty/models/company/assets/company_assets.py +0 -2
  26. letschatty/models/company/assets/sale.py +3 -3
  27. letschatty/models/company/empresa.py +1 -2
  28. letschatty/models/data_base/collection_interface.py +101 -29
  29. letschatty/models/data_base/mongo_connection.py +92 -9
  30. letschatty/models/messages/chatty_messages/schema/chatty_content/content_document.py +2 -4
  31. letschatty/models/messages/chatty_messages/schema/chatty_content/content_media.py +3 -4
  32. letschatty/models/utils/custom_exceptions/custom_exceptions.py +14 -1
  33. letschatty/services/ai_agents/smart_follow_up_context_builder_v2.py +5 -2
  34. letschatty/services/chat/chat_service.py +11 -47
  35. letschatty/services/chatty_assets/__init__.py +12 -0
  36. letschatty/services/chatty_assets/asset_service.py +190 -13
  37. letschatty/services/chatty_assets/assets_collections.py +137 -0
  38. letschatty/services/chatty_assets/base_container.py +3 -2
  39. letschatty/services/chatty_assets/base_container_with_collection.py +35 -26
  40. letschatty/services/chatty_assets/collections/__init__.py +38 -0
  41. letschatty/services/chatty_assets/collections/ai_agent_collection.py +19 -0
  42. letschatty/services/chatty_assets/collections/ai_agent_in_chat_collection.py +32 -0
  43. letschatty/services/chatty_assets/collections/ai_component_collection.py +21 -0
  44. letschatty/services/chatty_assets/collections/chain_of_thought_collection.py +30 -0
  45. letschatty/services/chatty_assets/collections/chat_collection.py +21 -0
  46. letschatty/services/chatty_assets/collections/contact_point_collection.py +21 -0
  47. letschatty/services/chatty_assets/collections/fast_answer_collection.py +21 -0
  48. letschatty/services/chatty_assets/collections/filter_criteria_collection.py +18 -0
  49. letschatty/services/chatty_assets/collections/flow_collection.py +20 -0
  50. letschatty/services/chatty_assets/collections/product_collection.py +20 -0
  51. letschatty/services/chatty_assets/collections/sale_collection.py +20 -0
  52. letschatty/services/chatty_assets/collections/source_collection.py +21 -0
  53. letschatty/services/chatty_assets/collections/tag_collection.py +19 -0
  54. letschatty/services/chatty_assets/collections/topic_collection.py +21 -0
  55. letschatty/services/chatty_assets/collections/user_collection.py +20 -0
  56. letschatty/services/chatty_assets/example_usage.py +44 -0
  57. letschatty/services/chatty_assets/services/__init__.py +37 -0
  58. letschatty/services/chatty_assets/services/ai_agent_in_chat_service.py +73 -0
  59. letschatty/services/chatty_assets/services/ai_agent_service.py +23 -0
  60. letschatty/services/chatty_assets/services/chain_of_thought_service.py +70 -0
  61. letschatty/services/chatty_assets/services/chat_service.py +25 -0
  62. letschatty/services/chatty_assets/services/contact_point_service.py +29 -0
  63. letschatty/services/chatty_assets/services/fast_answer_service.py +32 -0
  64. letschatty/services/chatty_assets/services/filter_criteria_service.py +30 -0
  65. letschatty/services/chatty_assets/services/flow_service.py +25 -0
  66. letschatty/services/chatty_assets/services/product_service.py +30 -0
  67. letschatty/services/chatty_assets/services/sale_service.py +25 -0
  68. letschatty/services/chatty_assets/services/source_service.py +28 -0
  69. letschatty/services/chatty_assets/services/tag_service.py +32 -0
  70. letschatty/services/chatty_assets/services/topic_service.py +31 -0
  71. letschatty/services/chatty_assets/services/user_service.py +32 -0
  72. letschatty/services/continuous_conversation_service/continuous_conversation_helper.py +11 -0
  73. letschatty/services/events/__init__.py +6 -0
  74. letschatty/services/events/events_manager.py +218 -1
  75. letschatty/services/factories/analytics/ai_agent_event_factory.py +161 -0
  76. letschatty/services/factories/analytics/events_factory.py +66 -30
  77. letschatty/services/factories/lambda_ai_orchestrartor/lambda_events_factory.py +46 -8
  78. letschatty/services/messages_helpers/get_caption_or_body_or_preview.py +6 -4
  79. letschatty/services/validators/analytics_validator.py +0 -11
  80. {letschatty-0.4.349.dist-info → letschatty-0.4.351.dist-info}/METADATA +1 -1
  81. {letschatty-0.4.349.dist-info → letschatty-0.4.351.dist-info}/RECORD +83 -53
  82. letschatty/models/analytics/events/chat_based_events/chat_client.py +0 -19
  83. letschatty/models/company/integrations/product_sync_status.py +0 -28
  84. letschatty/models/company/integrations/shopify/company_shopify_integration.py +0 -62
  85. letschatty/models/company/integrations/shopify/shopify_product_sync_status.py +0 -18
  86. letschatty/models/company/integrations/shopify/shopify_webhook_topics.py +0 -40
  87. letschatty/models/company/integrations/sync_status_enum.py +0 -9
  88. {letschatty-0.4.349.dist-info → letschatty-0.4.351.dist-info}/LICENSE +0 -0
  89. {letschatty-0.4.349.dist-info → letschatty-0.4.351.dist-info}/WHEEL +0 -0
@@ -0,0 +1,73 @@
1
+ """AI Agent In Chat Service - Pre-configured AssetService for CRUD operations only"""
2
+
3
+ from datetime import datetime
4
+ from zoneinfo import ZoneInfo
5
+ from typing import Optional
6
+ from ..asset_service import AssetService, CacheConfig
7
+ from ..collections.ai_agent_in_chat_collection import AIAgentInChatCollection
8
+ from ....models.company.assets.ai_agents_v2.chatty_ai_agent_in_chat import ChattyAIAgentInChat
9
+ from ....models.data_base.mongo_connection import MongoConnection
10
+ from ....models.utils.types.identifier import StrObjectId
11
+ import logging
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class AIAgentInChatService(AssetService[ChattyAIAgentInChat, ChattyAIAgentInChat]):
17
+ """
18
+ Pre-configured service for AI Agent In Chat CRUD operations.
19
+
20
+ For business logic operations (set_to_processing, escalate, etc.),
21
+ use AIAgentInChatEditor instead.
22
+
23
+ No events needed - this is operational state, not a business asset.
24
+ """
25
+
26
+ def __init__(
27
+ self,
28
+ connection: MongoConnection,
29
+ cache_config: CacheConfig = CacheConfig(
30
+ keep_items_always_in_memory=False,
31
+ keep_previews_always_in_memory=False
32
+ )
33
+ ):
34
+ collection = AIAgentInChatCollection(connection)
35
+ super().__init__(
36
+ collection=collection,
37
+ cache_config=cache_config
38
+ )
39
+
40
+ collection: AIAgentInChatCollection # Type annotation for better type checking
41
+
42
+ async def get_by_chat_id(self, chat_id: StrObjectId) -> Optional[ChattyAIAgentInChat]:
43
+ """Get AI agent state for a chat"""
44
+ return await self.collection.get_by_chat_id(chat_id)
45
+
46
+ async def update(self, ai_agent_in_chat: ChattyAIAgentInChat) -> ChattyAIAgentInChat:
47
+ """Update AI agent state"""
48
+ ai_agent_in_chat.updated_at = datetime.now(ZoneInfo("UTC"))
49
+ ai_agent_dict = ai_agent_in_chat.model_dump(by_alias=True, exclude_none=False)
50
+ # Remove _id field as it's immutable in MongoDB
51
+ ai_agent_dict.pop('_id', None)
52
+ result = await self.collection.async_collection.update_one(
53
+ {"chat_id": ai_agent_in_chat.chat_id},
54
+ {"$set": ai_agent_dict}
55
+ )
56
+ if result.matched_count == 0:
57
+ raise ValueError(f"AI agent state for chat {ai_agent_in_chat.chat_id} not found")
58
+ return ai_agent_in_chat
59
+
60
+ async def create(self, ai_agent_in_chat: ChattyAIAgentInChat) -> ChattyAIAgentInChat:
61
+ """Create new AI agent state"""
62
+ ai_agent_dict = ai_agent_in_chat.model_dump(by_alias=True, exclude_none=False)
63
+ result = await self.collection.async_collection.insert_one(ai_agent_dict)
64
+ if not result.inserted_id:
65
+ raise Exception(f"Failed to create AI agent state for chat {ai_agent_in_chat.chat_id}")
66
+ return ai_agent_in_chat
67
+
68
+ async def delete(self, chat_id: StrObjectId) -> None:
69
+ """Delete AI agent state"""
70
+ result = await self.collection.async_collection.delete_one({"chat_id": chat_id})
71
+ if result.deleted_count == 0:
72
+ raise ValueError(f"AI agent state for chat {chat_id} not found")
73
+
@@ -0,0 +1,23 @@
1
+ """AI Agent Service - Pre-configured AssetService for AI Agents"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import AiAgentCollection
5
+ from ....models.company.assets.ai_agents_v2.chatty_ai_agent import ChattyAIAgent, ChattyAIAgentPreview
6
+ from ....models.data_base.mongo_connection import MongoConnection
7
+
8
+
9
+ class AiAgentService(AssetService[ChattyAIAgent, ChattyAIAgentPreview]):
10
+ """Pre-configured service for AI Agent assets with sensible defaults"""
11
+
12
+ def __init__(self,
13
+ connection: MongoConnection,
14
+ cache_config: CacheConfig = CacheConfig(
15
+ keep_items_always_in_memory=False,
16
+ keep_previews_always_in_memory=True
17
+ )):
18
+ collection = AiAgentCollection(connection)
19
+ super().__init__(
20
+ collection=collection,
21
+ cache_config=cache_config
22
+ )
23
+
@@ -0,0 +1,70 @@
1
+ """Chain Of Thought Service - Pre-configured AssetService for CRUD operations only"""
2
+
3
+ from datetime import datetime
4
+ from zoneinfo import ZoneInfo
5
+ from typing import List, Optional
6
+ from ..asset_service import AssetService, CacheConfig
7
+ from ..collections.chain_of_thought_collection import ChainOfThoughtCollection
8
+ from ....models.company.assets.ai_agents_v2.chain_of_thought_in_chat import ChainOfThoughtInChat
9
+ from ....models.data_base.mongo_connection import MongoConnection
10
+ from ....models.utils.types.identifier import StrObjectId
11
+ from ....models.utils.types.serializer_type import SerializerType
12
+ from bson import ObjectId
13
+ import logging
14
+
15
+ logger = logging.getLogger(__name__)
16
+
17
+
18
+ class ChainOfThoughtService(AssetService[ChainOfThoughtInChat, ChainOfThoughtInChat]):
19
+ """
20
+ Pre-configured service for Chain Of Thought CRUD operations.
21
+
22
+ For business logic operations (create for N8N, set as failed, etc.),
23
+ use ChainOfThoughtsEditor instead.
24
+
25
+ No events needed - this is execution state, not a business asset.
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ connection: MongoConnection,
31
+ cache_config: CacheConfig = CacheConfig(
32
+ keep_items_always_in_memory=False,
33
+ keep_previews_always_in_memory=False
34
+ )
35
+ ):
36
+ collection = ChainOfThoughtCollection(connection)
37
+ super().__init__(
38
+ collection=collection,
39
+ cache_config=cache_config
40
+ )
41
+
42
+ collection: ChainOfThoughtCollection # Type annotation for better type checking
43
+
44
+ async def get_by_chat_id(self, chat_id: StrObjectId, skip: int = 0, limit: int = 10) -> List[ChainOfThoughtInChat]:
45
+ """Get chain of thoughts by chat ID, sorted by created_at (newest first)"""
46
+ return await self.collection.get_by_chat_id(chat_id=chat_id, skip=skip, limit=limit)
47
+
48
+ async def get_by_id(self, cot_id: StrObjectId) -> Optional[ChainOfThoughtInChat]:
49
+ """Get chain of thought by ID"""
50
+ return await self.collection.get_by_id(cot_id)
51
+
52
+ async def create(self, cot: ChainOfThoughtInChat) -> ChainOfThoughtInChat:
53
+ """Create new chain of thought"""
54
+ cot_dict = cot.model_dump(by_alias=True, exclude_none=False)
55
+ result = await self.collection.async_collection.insert_one(cot_dict)
56
+ if not result.inserted_id:
57
+ raise Exception(f"Failed to create chain of thought {cot.id}")
58
+ return cot
59
+
60
+ async def update(self, cot: ChainOfThoughtInChat) -> ChainOfThoughtInChat:
61
+ """Update chain of thought"""
62
+ cot.updated_at = datetime.now(ZoneInfo("UTC"))
63
+ cot_dict = cot.model_dump(by_alias=True, exclude_none=False)
64
+ result = await self.collection.async_collection.update_one(
65
+ {"_id": cot.id},
66
+ {"$set": cot_dict}
67
+ )
68
+ if result.matched_count == 0:
69
+ raise ValueError(f"Chain of thought {cot.id} not found")
70
+ return cot
@@ -0,0 +1,25 @@
1
+ """Chat Service - Pre-configured AssetService for Chats"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import ChatCollection
5
+ from ....models.chat.chat import Chat
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+
9
+
10
+ class ChatService(AssetService[Chat, ChattyAssetPreview]):
11
+ """
12
+ Pre-configured service for Chat assets with sensible defaults.
13
+
14
+ Note: No event configuration - Chat events are handled by ChatsEditor, not AssetService.
15
+ """
16
+
17
+ def __init__(self,
18
+ connection: MongoConnection,
19
+ cache_config: CacheConfig = CacheConfig.default()):
20
+ collection = ChatCollection(connection)
21
+ super().__init__(
22
+ collection=collection,
23
+ cache_config=cache_config
24
+ )
25
+
@@ -0,0 +1,29 @@
1
+ """Contact Point Service - Pre-configured AssetService for Contact Points"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import ContactPointCollection
5
+ from ....models.company.assets.contact_point import ContactPoint
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+
9
+
10
+ class ContactPointService(AssetService[ContactPoint, ChattyAssetPreview]):
11
+ """
12
+ Pre-configured service for ContactPoint assets with sensible defaults.
13
+
14
+ Note: No event configuration - ContactPoint events are managed separately by the contact points system.
15
+ """
16
+
17
+ def __init__(self,
18
+ connection: MongoConnection,
19
+ cache_config: CacheConfig = CacheConfig(
20
+ keep_items_always_in_memory=False,
21
+ keep_previews_always_in_memory=False,
22
+ cache_expiration_time=0
23
+ )):
24
+ collection = ContactPointCollection(connection)
25
+ super().__init__(
26
+ collection=collection,
27
+ cache_config=cache_config
28
+ )
29
+
@@ -0,0 +1,32 @@
1
+ """Fast Answer Service - Pre-configured AssetService for Fast Answers"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections.fast_answer_collection import FastAnswerCollection
5
+ from ....models.company.assets import ChattyFastAnswer
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+ from ....models.analytics.events import CompanyAssetType, EventType
9
+
10
+
11
+ class FastAnswerService(AssetService[ChattyFastAnswer, ChattyAssetPreview]):
12
+ """Pre-configured service for Fast Answer assets with sensible defaults"""
13
+
14
+ # Event configuration - enables automatic event handling in API
15
+ asset_type_enum = CompanyAssetType.FAST_ANSWERS
16
+ event_type_created = EventType.FAST_ANSWER_CREATED
17
+ event_type_updated = EventType.FAST_ANSWER_UPDATED
18
+ event_type_deleted = EventType.FAST_ANSWER_DELETED
19
+
20
+ def __init__(self,
21
+ connection: MongoConnection,
22
+ cache_config: CacheConfig = CacheConfig(
23
+ keep_items_always_in_memory=False,
24
+ cache_expiration_time=60*30, # 30 minutes
25
+ keep_previews_always_in_memory=True
26
+ )):
27
+ collection = FastAnswerCollection(connection)
28
+ super().__init__(
29
+ collection=collection,
30
+ cache_config=cache_config
31
+ )
32
+
@@ -0,0 +1,30 @@
1
+ """Filter Criteria Service - Pre-configured AssetService for Filter Criterias"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import FilterCriteriaCollection
5
+ from ....models.company.assets.filter_criteria import FilterCriteria, FilterCriteriaPreview
6
+ from ....models.data_base.mongo_connection import MongoConnection
7
+ from ....models.analytics.events import CompanyAssetType, EventType
8
+
9
+
10
+ class FilterCriteriaService(AssetService[FilterCriteria, FilterCriteriaPreview]):
11
+ """Pre-configured service for Filter Criteria assets with sensible defaults"""
12
+
13
+ # Event configuration - enables automatic event handling in API
14
+ asset_type_enum = CompanyAssetType.FILTER_CRITERIA
15
+ event_type_created = EventType.FILTER_CRITERIA_CREATED
16
+ event_type_updated = EventType.FILTER_CRITERIA_UPDATED
17
+ event_type_deleted = EventType.FILTER_CRITERIA_DELETED
18
+
19
+ def __init__(self,
20
+ connection: MongoConnection,
21
+ cache_config: CacheConfig = CacheConfig(
22
+ keep_items_always_in_memory=False,
23
+ keep_previews_always_in_memory=True
24
+ )):
25
+ collection = FilterCriteriaCollection(connection)
26
+ super().__init__(
27
+ collection=collection,
28
+ cache_config=cache_config
29
+ )
30
+
@@ -0,0 +1,25 @@
1
+ """Flow Service - Pre-configured AssetService for Flows"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import FlowCollection
5
+ from ....models.company.assets.flow import FlowPreview
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+
9
+
10
+ class FlowService(AssetService[FlowPreview, ChattyAssetPreview]):
11
+ """
12
+ Pre-configured service for Flow assets with sensible defaults.
13
+
14
+ Note: No event configuration - Flows are previews only, not full assets with CRUD events.
15
+ """
16
+
17
+ def __init__(self,
18
+ connection: MongoConnection,
19
+ cache_config: CacheConfig = CacheConfig(keep_items_always_in_memory=True)):
20
+ collection = FlowCollection(connection)
21
+ super().__init__(
22
+ collection=collection,
23
+ cache_config=cache_config
24
+ )
25
+
@@ -0,0 +1,30 @@
1
+ """Product Service - Pre-configured AssetService for Products"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import ProductCollection
5
+ from ....models.company.assets.product import Product, ProductPreview
6
+ from ....models.data_base.mongo_connection import MongoConnection
7
+ from ....models.analytics.events import CompanyAssetType, EventType
8
+
9
+
10
+ class ProductService(AssetService[Product, ProductPreview]):
11
+ """Pre-configured service for Product assets with sensible defaults"""
12
+
13
+ # Event configuration - enables automatic event handling in API
14
+ asset_type_enum = CompanyAssetType.PRODUCTS
15
+ event_type_created = EventType.PRODUCT_CREATED
16
+ event_type_updated = EventType.PRODUCT_UPDATED
17
+ event_type_deleted = EventType.PRODUCT_DELETED
18
+
19
+ def __init__(self,
20
+ connection: MongoConnection,
21
+ cache_config: CacheConfig = CacheConfig(
22
+ keep_items_always_in_memory=False,
23
+ keep_previews_always_in_memory=True
24
+ )):
25
+ collection = ProductCollection(connection)
26
+ super().__init__(
27
+ collection=collection,
28
+ cache_config=cache_config
29
+ )
30
+
@@ -0,0 +1,25 @@
1
+ """Sale Service - Pre-configured AssetService for Sales"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import SaleCollection
5
+ from ....models.company.assets.sale import Sale
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+
9
+
10
+ class SaleService(AssetService[Sale, ChattyAssetPreview]):
11
+ """
12
+ Pre-configured service for Sale assets with sensible defaults.
13
+
14
+ Note: No event configuration - Sale events are managed by the sales editor, not AssetService.
15
+ """
16
+
17
+ def __init__(self,
18
+ connection: MongoConnection,
19
+ cache_config: CacheConfig = CacheConfig.default()):
20
+ collection = SaleCollection(connection)
21
+ super().__init__(
22
+ collection=collection,
23
+ cache_config=cache_config
24
+ )
25
+
@@ -0,0 +1,28 @@
1
+ """Source Service - Pre-configured AssetService for Sources"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import SourceCollection
5
+ from ....models.analytics.sources import SourceBase
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+ from ....models.analytics.events import CompanyAssetType, EventType
9
+
10
+
11
+ class SourceService(AssetService[SourceBase, ChattyAssetPreview]):
12
+ """Pre-configured service for Source assets with sensible defaults"""
13
+
14
+ # Event configuration - enables automatic event handling in API
15
+ asset_type_enum = CompanyAssetType.SOURCES
16
+ event_type_created = EventType.SOURCE_CREATED
17
+ event_type_updated = EventType.SOURCE_UPDATED
18
+ event_type_deleted = EventType.SOURCE_DELETED
19
+
20
+ def __init__(self,
21
+ connection: MongoConnection,
22
+ cache_config: CacheConfig = CacheConfig(keep_items_always_in_memory=True)):
23
+ collection = SourceCollection(connection)
24
+ super().__init__(
25
+ collection=collection,
26
+ cache_config=cache_config
27
+ )
28
+
@@ -0,0 +1,32 @@
1
+ """Tag Service - Pre-configured AssetService for Tags"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import TagCollection
5
+ from ....models.company.assets.tag import Tag, TagPreview
6
+ from ....models.data_base.mongo_connection import MongoConnection
7
+ from ....models.analytics.events import CompanyAssetType, EventType
8
+
9
+
10
+ class TagService(AssetService[Tag, TagPreview]):
11
+ """Pre-configured service for Tag assets with sensible defaults"""
12
+
13
+ # Event configuration - enables automatic event handling in API
14
+ asset_type_enum = CompanyAssetType.TAGS
15
+ event_type_created = EventType.TAG_CREATED
16
+ event_type_updated = EventType.TAG_UPDATED
17
+ event_type_deleted = EventType.TAG_DELETED
18
+
19
+ def __init__(self,
20
+ connection: MongoConnection,
21
+ cache_config: CacheConfig = CacheConfig(
22
+ keep_items_always_in_memory=False,
23
+ keep_previews_always_in_memory=True
24
+ )):
25
+ collection = TagCollection(connection)
26
+ super().__init__(
27
+ collection=collection,
28
+ cache_config=cache_config
29
+ )
30
+ # Load all tags into memory by default
31
+ self.load_from_db(company_id=None)
32
+
@@ -0,0 +1,31 @@
1
+ """Topic Service - Pre-configured AssetService for Topics"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections.topic_collection import TopicCollection
5
+ from ....models.analytics.smart_messages.topic import Topic
6
+ from ....models.base_models import ChattyAssetPreview
7
+ from ....models.data_base.mongo_connection import MongoConnection
8
+ from ....models.analytics.events import CompanyAssetType, EventType
9
+
10
+
11
+ class TopicService(AssetService[Topic, ChattyAssetPreview]):
12
+ """Pre-configured service for Topic assets with sensible defaults"""
13
+
14
+ # Event configuration - enables automatic event handling in API
15
+ asset_type_enum = CompanyAssetType.TOPICS
16
+ event_type_created = EventType.TOPIC_CREATED
17
+ event_type_updated = EventType.TOPIC_UPDATED
18
+ event_type_deleted = EventType.TOPIC_DELETED
19
+
20
+ def __init__(self,
21
+ connection: MongoConnection,
22
+ cache_config: CacheConfig = CacheConfig(
23
+ keep_items_always_in_memory=True,
24
+ keep_previews_always_in_memory=True
25
+ )):
26
+ collection = TopicCollection(connection)
27
+ super().__init__(
28
+ collection=collection,
29
+ cache_config=cache_config
30
+ )
31
+
@@ -0,0 +1,32 @@
1
+ """User Service - Pre-configured AssetService for Users"""
2
+
3
+ from ..asset_service import AssetService, CacheConfig
4
+ from ..collections import UserCollection
5
+ from ....models.company.assets.users.user import User, UserPreview
6
+ from ....models.data_base.mongo_connection import MongoConnection
7
+ from ....models.analytics.events import CompanyAssetType, EventType
8
+
9
+
10
+ class UserService(AssetService[User, UserPreview]):
11
+ """Pre-configured service for User assets with sensible defaults"""
12
+
13
+ # Event configuration - enables automatic event handling in API
14
+ asset_type_enum = CompanyAssetType.USERS
15
+ event_type_created = EventType.USER_CREATED
16
+ event_type_updated = EventType.USER_UPDATED
17
+ event_type_deleted = EventType.USER_DELETED
18
+
19
+ def __init__(self,
20
+ connection: MongoConnection,
21
+ cache_config: CacheConfig = CacheConfig(
22
+ keep_items_always_in_memory=False,
23
+ cache_expiration_time_previews=300,
24
+ keep_previews_always_in_memory=True,
25
+ keep_deleted_previews_in_memory=True
26
+ )):
27
+ collection = UserCollection(connection)
28
+ super().__init__(
29
+ collection=collection,
30
+ cache_config=cache_config
31
+ )
32
+
@@ -269,4 +269,15 @@ class ContinuousConversationHelper:
269
269
  central_notif_content = ChattyContentCentral(body=body, status=CentralNotificationStatus.WARNING, calls_to_action=[cta.value for cta in cc.calls_to_action])
270
270
  central_notif = CentralNotificationFactory.continuous_conversation_status(cc=cc, content=central_notif_content)
271
271
  ChatService.add_central_notification(central_notification=central_notif, chat=chat)
272
+ return cc
273
+
274
+ @staticmethod
275
+ def handle_failed_template_cc(chat: Chat, cc: ContinuousConversation, error_details: str) -> ContinuousConversation:
276
+ """This is for the handling of a failed template CC"""
277
+ cc.set_status(status=ContinuousConversationStatus.FAILED)
278
+ body=f"Continuous conversation failed to be sent: {error_details}"
279
+ logger.debug(f"{body} | CC status: {cc.status} | CC id: {cc.id} | chat id: {chat.identifier}")
280
+ central_notif_content = ChattyContentCentral(body=body, status=CentralNotificationStatus.ERROR, calls_to_action=[cta.value for cta in cc.calls_to_action])
281
+ central_notif = CentralNotificationFactory.continuous_conversation_status(cc=cc, content=central_notif_content)
282
+ ChatService.add_central_notification(central_notification=central_notif, chat=chat)
272
283
  return cc
@@ -0,0 +1,6 @@
1
+ """Events management services"""
2
+
3
+ from .events_manager import EventsManager, events_manager
4
+
5
+ __all__ = ['EventsManager', 'events_manager']
6
+