letschatty 0.4.305__py3-none-any.whl → 0.4.343__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.
- letschatty/models/ai_microservices/expected_output.py +35 -1
- letschatty/models/ai_microservices/lambda_events.py +66 -5
- letschatty/models/ai_microservices/lambda_invokation_types.py +3 -0
- letschatty/models/analytics/events/__init__.py +1 -1
- letschatty/models/analytics/events/chat_based_events/chat_funnel.py +69 -13
- letschatty/models/analytics/events/company_based_events/asset_events.py +9 -2
- letschatty/models/analytics/events/event_type_to_classes.py +6 -3
- letschatty/models/analytics/events/event_types.py +13 -5
- letschatty/models/chat/chat.py +13 -2
- letschatty/models/chat/chat_with_assets.py +6 -1
- letschatty/models/chat/client.py +0 -2
- letschatty/models/chat/continuous_conversation.py +1 -1
- letschatty/models/company/CRM/funnel.py +365 -33
- letschatty/models/company/__init__.py +3 -1
- letschatty/models/company/assets/ai_agents_v2/ai_agent_message_draft.py +58 -0
- letschatty/models/company/assets/ai_agents_v2/chain_of_thought_in_chat.py +5 -3
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent.py +30 -2
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent_in_chat.py +91 -1
- letschatty/models/company/assets/ai_agents_v2/pre_qualify_config.py +111 -0
- letschatty/models/company/assets/ai_agents_v2/statuses.py +33 -0
- letschatty/models/company/assets/assignment/__init__.py +14 -0
- letschatty/models/company/assets/assignment/assignment_assets.py +75 -0
- letschatty/models/company/assets/automation.py +10 -1
- letschatty/models/company/assets/chat_assets.py +12 -2
- letschatty/models/company/assets/company_assets.py +3 -0
- letschatty/models/company/assets/launch/__init__.py +12 -0
- letschatty/models/company/assets/launch/launch.py +128 -0
- letschatty/models/company/assets/launch/scheduled_communication.py +44 -0
- letschatty/models/company/assets/launch/subscription.py +63 -0
- letschatty/models/company/assets/sale.py +3 -3
- letschatty/models/company/assets/users/user.py +5 -1
- letschatty/models/company/company_messaging_settgins.py +2 -1
- letschatty/models/company/form_field.py +182 -12
- letschatty/models/messages/chatty_messages/schema/chatty_content/content_document.py +4 -2
- letschatty/models/messages/chatty_messages/schema/chatty_content/content_media.py +4 -3
- letschatty/models/utils/custom_exceptions/custom_exceptions.py +24 -0
- letschatty/services/ai_agents/smart_follow_up_service_v2.py +10 -0
- letschatty/services/chat/chat_service.py +79 -14
- letschatty/services/factories/analytics/events_factory.py +5 -3
- letschatty/services/users/user_factory.py +14 -8
- letschatty/services/validators/analytics_validator.py +11 -0
- {letschatty-0.4.305.dist-info → letschatty-0.4.343.dist-info}/METADATA +2 -1
- {letschatty-0.4.305.dist-info → letschatty-0.4.343.dist-info}/RECORD +45 -36
- {letschatty-0.4.305.dist-info → letschatty-0.4.343.dist-info}/WHEEL +1 -1
- {letschatty-0.4.305.dist-info → letschatty-0.4.343.dist-info}/LICENSE +0 -0
|
@@ -27,6 +27,20 @@ class ExpectedOutputSmartTag(BaseModel):
|
|
|
27
27
|
chain_of_thought: ChainOfThoughtInChatRequest = Field(
|
|
28
28
|
description="REQUIRED: Your reasoning process and response decision explanation"
|
|
29
29
|
)
|
|
30
|
+
# Unsubscribe intent detection (for launch agents)
|
|
31
|
+
unsubscribe_intent: bool = Field(
|
|
32
|
+
default=False,
|
|
33
|
+
description="True if user expressed intent to unsubscribe from communications (e.g., 'no more messages', 'unsubscribe', 'stop', 'rechazar mensajes')"
|
|
34
|
+
)
|
|
35
|
+
# Acceptance criteria evaluation (for agents with data collection + acceptance_criteria)
|
|
36
|
+
acceptance_criteria_met: Optional[bool] = Field(
|
|
37
|
+
default=None,
|
|
38
|
+
description="True if user meets acceptance criteria, False if not, None if cannot be determined yet or no criteria configured"
|
|
39
|
+
)
|
|
40
|
+
acceptance_criteria_reason: Optional[str] = Field(
|
|
41
|
+
default=None,
|
|
42
|
+
description="Reason explaining why acceptance criteria is met or not met"
|
|
43
|
+
)
|
|
30
44
|
|
|
31
45
|
@staticmethod
|
|
32
46
|
def get_json_schema() -> dict:
|
|
@@ -100,9 +114,21 @@ class ExpectedOutputSmartTag(BaseModel):
|
|
|
100
114
|
},
|
|
101
115
|
"required": ["trigger", "trigger_id", "chatty_ai_agent_id", "chain_of_thought", "title"],
|
|
102
116
|
"additionalProperties": False
|
|
117
|
+
},
|
|
118
|
+
"unsubscribe_intent": {
|
|
119
|
+
"type": "boolean",
|
|
120
|
+
"description": "True if user expressed intent to unsubscribe from communications (e.g., 'no more messages', 'unsubscribe', 'stop', 'rechazar mensajes')"
|
|
121
|
+
},
|
|
122
|
+
"acceptance_criteria_met": {
|
|
123
|
+
"anyOf": [{"type": "boolean"}, {"type": "null"}],
|
|
124
|
+
"description": "True if user meets acceptance criteria, False if not, null if cannot be determined yet"
|
|
125
|
+
},
|
|
126
|
+
"acceptance_criteria_reason": {
|
|
127
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
128
|
+
"description": "Reason explaining why acceptance criteria is met or not met"
|
|
103
129
|
}
|
|
104
130
|
},
|
|
105
|
-
"required": ["automation", "conversation_topics", "data_collection", "chain_of_thought"],
|
|
131
|
+
"required": ["automation", "conversation_topics", "data_collection", "chain_of_thought", "unsubscribe_intent", "acceptance_criteria_met", "acceptance_criteria_reason"],
|
|
106
132
|
"additionalProperties": False
|
|
107
133
|
}
|
|
108
134
|
|
|
@@ -143,6 +169,12 @@ class ExpectedOutputIncomingMessage(BaseModel):
|
|
|
143
169
|
action: IncomingMessageDecisionAction
|
|
144
170
|
messages: List[str] = Field(description="Array of message strings to send to the customer. Required for send/suggest actions, optional for escalate action, empty array for skip/remove actions.")
|
|
145
171
|
chain_of_thought: ChainOfThoughtInChatRequest = Field(description="REQUIRED: Your reasoning process and response decision explanation")
|
|
172
|
+
confidence: Optional[int] = Field(
|
|
173
|
+
default=None,
|
|
174
|
+
ge=0,
|
|
175
|
+
le=100,
|
|
176
|
+
description="Confidence level 0-100"
|
|
177
|
+
)
|
|
146
178
|
|
|
147
179
|
def to_incoming_message_decision_output(self) -> IncomingMessageAIDecision:
|
|
148
180
|
messages_drafts = [
|
|
@@ -161,3 +193,5 @@ class ExpectedOutputIncomingMessage(BaseModel):
|
|
|
161
193
|
return incoming_decision
|
|
162
194
|
|
|
163
195
|
|
|
196
|
+
class ExpectedOutputSmartFollowUp(BaseModel):
|
|
197
|
+
action: Optional[str] = None
|
|
@@ -5,8 +5,9 @@ from typing import Dict, Any, List, Optional
|
|
|
5
5
|
from letschatty.models.base_models.ai_agent_component import AiAgentComponentType
|
|
6
6
|
from letschatty.models.utils.types.identifier import StrObjectId
|
|
7
7
|
from .lambda_invokation_types import InvokationType, LambdaAiEvent
|
|
8
|
-
from .expected_output import ExpectedOutputIncomingMessage, ExpectedOutputSmartTag, ExpectedOutputQualityTest, IncomingMessageAIDecision
|
|
8
|
+
from .expected_output import ExpectedOutputIncomingMessage, ExpectedOutputSmartTag, ExpectedOutputQualityTest, ExpectedOutputSmartFollowUp, IncomingMessageAIDecision
|
|
9
9
|
from ...models.company.assets.ai_agents_v2.ai_agents_decision_output import IncomingMessageDecisionAction
|
|
10
|
+
from ...models.company.assets.ai_agents_v2.chatty_ai_agent_in_chat import HumanInterventionReason
|
|
10
11
|
|
|
11
12
|
class SmartTaggingCallbackMetadata(BaseModel):
|
|
12
13
|
chat_id: StrObjectId
|
|
@@ -60,10 +61,23 @@ class SmartTaggingCallbackEvent(LambdaAiEvent):
|
|
|
60
61
|
callback_metadata: SmartTaggingCallbackMetadata
|
|
61
62
|
|
|
62
63
|
@model_validator(mode="before")
|
|
63
|
-
def
|
|
64
|
-
if isinstance(
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
def normalize_data(cls, values):
|
|
65
|
+
if not isinstance(values, dict):
|
|
66
|
+
return values
|
|
67
|
+
|
|
68
|
+
data = values.get("data")
|
|
69
|
+
if isinstance(data, str):
|
|
70
|
+
import json
|
|
71
|
+
try:
|
|
72
|
+
data = json.loads(data)
|
|
73
|
+
values["data"] = data
|
|
74
|
+
except (json.JSONDecodeError, TypeError):
|
|
75
|
+
return values
|
|
76
|
+
|
|
77
|
+
if isinstance(data, dict) and "chain_of_thought" in data:
|
|
78
|
+
data["chain_of_thought"]["chatty_ai_agent_id"] = "000000000000000000000000"
|
|
79
|
+
|
|
80
|
+
return values
|
|
67
81
|
|
|
68
82
|
class ChatData(BaseModel):
|
|
69
83
|
chat_id: StrObjectId
|
|
@@ -77,6 +91,11 @@ class FollowUpEvent(LambdaAiEvent):
|
|
|
77
91
|
type: InvokationType = InvokationType.FOLLOW_UP
|
|
78
92
|
data: ChatData
|
|
79
93
|
|
|
94
|
+
|
|
95
|
+
class SmartFollowUpDecisionOutputEvent(LambdaAiEvent):
|
|
96
|
+
type: InvokationType = InvokationType.FOLLOW_UP
|
|
97
|
+
data: ExpectedOutputSmartFollowUp
|
|
98
|
+
|
|
80
99
|
class QualityTestEventData(BaseModel):
|
|
81
100
|
chat_example_id: StrObjectId
|
|
82
101
|
company_id: StrObjectId
|
|
@@ -333,3 +352,45 @@ class UnescalateAIAgentInChatEvent(LambdaAiEvent):
|
|
|
333
352
|
"""
|
|
334
353
|
type: InvokationType = InvokationType.UNESCALATE_AI_AGENT_IN_CHAT
|
|
335
354
|
data: UnescalateAIAgentInChatEventData
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
# Launch Events
|
|
358
|
+
|
|
359
|
+
class LaunchCommunicationEventData(BaseModel):
|
|
360
|
+
"""Data for sending a scheduled launch communication"""
|
|
361
|
+
chat_ids: List[StrObjectId] = Field(description="Batch of chat IDs to send communication to")
|
|
362
|
+
company_id: StrObjectId
|
|
363
|
+
launch_id: StrObjectId
|
|
364
|
+
communication_id: str = Field(description="ID of the communication within the launch")
|
|
365
|
+
communication_type: str = Field(description="Type: pre_launch, post_attended, post_missed, welcome_kit")
|
|
366
|
+
lambda_callback_url: str = Field(description="URL for Lambda to call back after N8N processing")
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
class LaunchCommunicationEvent(LambdaAiEvent):
|
|
370
|
+
"""
|
|
371
|
+
Event to send a scheduled launch communication.
|
|
372
|
+
|
|
373
|
+
Triggered by Copilot when delta_minutes is reached. Lambda processes
|
|
374
|
+
the batch of chats, building context for each and sending to N8N
|
|
375
|
+
for AI adaptation (or sending literal messages directly).
|
|
376
|
+
"""
|
|
377
|
+
type: InvokationType = InvokationType.LAUNCH_COMMUNICATION
|
|
378
|
+
data: LaunchCommunicationEventData
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
class LaunchWelcomeKitEventData(BaseModel):
|
|
382
|
+
"""Data for sending a welcome kit with AI adaptation"""
|
|
383
|
+
chat_id: StrObjectId
|
|
384
|
+
company_id: StrObjectId
|
|
385
|
+
launch_id: StrObjectId
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
class LaunchWelcomeKitEvent(LambdaAiEvent):
|
|
389
|
+
"""
|
|
390
|
+
Event to send a welcome kit with AI adaptation.
|
|
391
|
+
|
|
392
|
+
Triggered when a user subscribes to a launch and the welcome kit
|
|
393
|
+
requires AI adaptation. Lambda builds context and sends to N8N.
|
|
394
|
+
"""
|
|
395
|
+
type: InvokationType = InvokationType.LAUNCH_WELCOME_KIT
|
|
396
|
+
data: LaunchWelcomeKitEventData
|
|
@@ -30,6 +30,9 @@ class InvokationType(StrEnum):
|
|
|
30
30
|
UPDATE_AI_AGENT_MODE_IN_CHAT = "update_ai_agent_mode_in_chat"
|
|
31
31
|
ESCALATE_AI_AGENT_IN_CHAT = "escalate_ai_agent_in_chat"
|
|
32
32
|
UNESCALATE_AI_AGENT_IN_CHAT = "unescalate_ai_agent_in_chat"
|
|
33
|
+
# Launch events
|
|
34
|
+
LAUNCH_COMMUNICATION = "launch_communication"
|
|
35
|
+
LAUNCH_WELCOME_KIT = "launch_welcome_kit"
|
|
33
36
|
|
|
34
37
|
class LambdaAiEvent(BaseModel):
|
|
35
38
|
type: InvokationType
|
|
@@ -4,7 +4,7 @@ from .chat_based_events.business_area import ChatBusinessAreaEvent, BusinessArea
|
|
|
4
4
|
from .chat_based_events.workflow import WorkflowEvent, WorkflowEventData
|
|
5
5
|
from .chat_based_events.chat_status import ChatStatusEvent, ChatStatusEventData, ChatStatusModification, ChatCreatedFrom
|
|
6
6
|
from .chat_based_events.chat_funnel import ChatFunnelEvent, FunnelEventData
|
|
7
|
-
from ...company.CRM.funnel import
|
|
7
|
+
from ...company.CRM.funnel import ChatFunnel, StageTransition, ActiveFunnel
|
|
8
8
|
from .company_based_events.user_events import UserEvent, UserEventData
|
|
9
9
|
from .chat_based_events.quality_scoring import QualityScoringEvent
|
|
10
10
|
from .chat_based_events.message import MessageEvent, MessageData
|
|
@@ -4,37 +4,93 @@ from ..base import Event
|
|
|
4
4
|
from ..event_types import EventType
|
|
5
5
|
from .chat_based_event import CustomerEventData
|
|
6
6
|
from ....utils.types.identifier import StrObjectId
|
|
7
|
-
from ....company.CRM.funnel import
|
|
7
|
+
from ....company.CRM.funnel import StageTransition
|
|
8
8
|
import json
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
class FunnelEventData(CustomerEventData):
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
"""
|
|
13
|
+
Event data for chat funnel events.
|
|
14
|
+
|
|
15
|
+
Fields required per event type:
|
|
16
|
+
- STARTED: funnel_id, chat_funnel_id, stage_transition
|
|
17
|
+
- STAGE_CHANGED: funnel_id, chat_funnel_id, stage_transition (with time_in_previous_stage_seconds)
|
|
18
|
+
- COMPLETED: funnel_id, chat_funnel_id, time_in_funnel_seconds, time_in_last_stage_seconds
|
|
19
|
+
- ABANDONED: funnel_id, chat_funnel_id, time_in_funnel_seconds, time_in_last_stage_seconds
|
|
20
|
+
"""
|
|
21
|
+
funnel_id: StrObjectId = Field(description="The funnel the chat is in")
|
|
22
|
+
chat_funnel_id: StrObjectId = Field(description="Reference to the ChatFunnel record")
|
|
23
|
+
|
|
24
|
+
# For STARTED and STAGE_CHANGED events
|
|
25
|
+
stage_transition: Optional[StageTransition] = Field(
|
|
26
|
+
default=None,
|
|
27
|
+
description="The stage transition details (for STARTED and STAGE_CHANGED)"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# For COMPLETED and ABANDONED events
|
|
31
|
+
time_in_funnel_seconds: Optional[int] = Field(
|
|
32
|
+
default=None,
|
|
33
|
+
description="Total time spent in the funnel (for COMPLETED and ABANDONED)"
|
|
34
|
+
)
|
|
35
|
+
time_in_last_stage_seconds: Optional[int] = Field(
|
|
36
|
+
default=None,
|
|
37
|
+
description="Time spent in the last stage before completion/abandonment"
|
|
38
|
+
)
|
|
39
|
+
|
|
14
40
|
|
|
15
41
|
class ChatFunnelEvent(Event):
|
|
16
|
-
"""
|
|
42
|
+
"""
|
|
43
|
+
Event for tracking chat funnel lifecycle.
|
|
44
|
+
|
|
45
|
+
Events:
|
|
46
|
+
- CHAT_FUNNEL_STARTED: Chat entered a funnel
|
|
47
|
+
- CHAT_FUNNEL_STAGE_CHANGED: Chat moved between stages
|
|
48
|
+
- CHAT_FUNNEL_COMPLETED: Chat completed the funnel
|
|
49
|
+
- CHAT_FUNNEL_ABANDONED: Chat abandoned the funnel
|
|
50
|
+
"""
|
|
17
51
|
data: FunnelEventData
|
|
18
52
|
|
|
19
|
-
# Define valid event types for this event class
|
|
20
53
|
VALID_TYPES: ClassVar[set] = {
|
|
21
|
-
EventType.CHAT_FUNNEL_UPDATED,
|
|
22
54
|
EventType.CHAT_FUNNEL_STARTED,
|
|
55
|
+
EventType.CHAT_FUNNEL_STAGE_CHANGED,
|
|
23
56
|
EventType.CHAT_FUNNEL_COMPLETED,
|
|
24
57
|
EventType.CHAT_FUNNEL_ABANDONED
|
|
25
58
|
}
|
|
26
59
|
|
|
27
|
-
|
|
28
60
|
@field_validator('data')
|
|
29
61
|
def validate_data_fields(cls, v: FunnelEventData, info: ValidationInfo):
|
|
30
62
|
"""Validate that appropriate fields are set based on event type"""
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
63
|
+
event_type = info.data.get('type')
|
|
64
|
+
|
|
65
|
+
# STARTED: requires stage_transition
|
|
66
|
+
if event_type == EventType.CHAT_FUNNEL_STARTED:
|
|
67
|
+
if v.stage_transition is None:
|
|
68
|
+
raise ValueError("stage_transition must be set for CHAT_FUNNEL_STARTED events")
|
|
69
|
+
|
|
70
|
+
# STAGE_CHANGED: requires stage_transition with time_in_previous_stage_seconds
|
|
71
|
+
elif event_type == EventType.CHAT_FUNNEL_STAGE_CHANGED:
|
|
72
|
+
if v.stage_transition is None:
|
|
73
|
+
raise ValueError("stage_transition must be set for CHAT_FUNNEL_STAGE_CHANGED events")
|
|
74
|
+
if v.stage_transition.time_in_previous_stage_seconds is None:
|
|
75
|
+
raise ValueError("time_in_previous_stage_seconds must be set in stage_transition for CHAT_FUNNEL_STAGE_CHANGED events")
|
|
76
|
+
|
|
77
|
+
# COMPLETED: requires time metrics
|
|
78
|
+
elif event_type == EventType.CHAT_FUNNEL_COMPLETED:
|
|
79
|
+
if v.time_in_funnel_seconds is None:
|
|
80
|
+
raise ValueError("time_in_funnel_seconds must be set for CHAT_FUNNEL_COMPLETED events")
|
|
81
|
+
if v.time_in_last_stage_seconds is None:
|
|
82
|
+
raise ValueError("time_in_last_stage_seconds must be set for CHAT_FUNNEL_COMPLETED events")
|
|
83
|
+
|
|
84
|
+
# ABANDONED: requires time metrics
|
|
85
|
+
elif event_type == EventType.CHAT_FUNNEL_ABANDONED:
|
|
86
|
+
if v.time_in_funnel_seconds is None:
|
|
87
|
+
raise ValueError("time_in_funnel_seconds must be set for CHAT_FUNNEL_ABANDONED events")
|
|
88
|
+
if v.time_in_last_stage_seconds is None:
|
|
89
|
+
raise ValueError("time_in_last_stage_seconds must be set for CHAT_FUNNEL_ABANDONED events")
|
|
90
|
+
|
|
35
91
|
return v
|
|
36
92
|
|
|
37
93
|
def model_dump_json(self, *args, **kwargs):
|
|
38
94
|
dump = json.loads(super().model_dump_json(*args, **kwargs))
|
|
39
95
|
dump['data'] = self.data.model_dump_json()
|
|
40
|
-
return dump
|
|
96
|
+
return dump
|
|
@@ -58,6 +58,9 @@ class AssetEvent(Event):
|
|
|
58
58
|
EventType.FUNNEL_STAGE_CREATED,
|
|
59
59
|
EventType.FUNNEL_STAGE_UPDATED,
|
|
60
60
|
EventType.FUNNEL_STAGE_DELETED,
|
|
61
|
+
EventType.FUNNEL_MEMBER_ADDED,
|
|
62
|
+
EventType.FUNNEL_MEMBER_UPDATED,
|
|
63
|
+
EventType.FUNNEL_MEMBER_REMOVED,
|
|
61
64
|
EventType.WORKFLOW_CREATED,
|
|
62
65
|
EventType.WORKFLOW_UPDATED,
|
|
63
66
|
EventType.WORKFLOW_DELETED,
|
|
@@ -70,6 +73,9 @@ class AssetEvent(Event):
|
|
|
70
73
|
EventType.FILTER_CRITERIA_CREATED,
|
|
71
74
|
EventType.FILTER_CRITERIA_UPDATED,
|
|
72
75
|
EventType.FILTER_CRITERIA_DELETED,
|
|
76
|
+
EventType.FORM_FIELD_CREATED,
|
|
77
|
+
EventType.FORM_FIELD_UPDATED,
|
|
78
|
+
EventType.FORM_FIELD_DELETED,
|
|
73
79
|
EventType.COMPANY_CREATED,
|
|
74
80
|
EventType.COMPANY_UPDATED,
|
|
75
81
|
EventType.COMPANY_DELETED
|
|
@@ -77,8 +83,9 @@ class AssetEvent(Event):
|
|
|
77
83
|
|
|
78
84
|
@model_validator(mode='after')
|
|
79
85
|
def validate_data_fields(self):
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
# Asset is not required for deleted/removed events
|
|
87
|
+
if "deleted" not in self.type.value and "removed" not in self.type.value and not self.data.asset:
|
|
88
|
+
raise ValueError("asset must be set for all events except DELETED/REMOVED")
|
|
82
89
|
return self
|
|
83
90
|
|
|
84
91
|
def model_dump_json(self, *args, **kwargs):
|
|
@@ -41,10 +41,9 @@ EVENT_TO_TYPE_CLASSES = {
|
|
|
41
41
|
#CONTINUOUS CONVERSATION
|
|
42
42
|
EventType.CONTINUOUS_CONVERSATION_CREATED : ContinuousConversationEvent,
|
|
43
43
|
EventType.CONTINUOUS_CONVERSATION_UPDATED : ContinuousConversationEvent,
|
|
44
|
-
#FUNNEL
|
|
45
|
-
# Funnel-level events
|
|
44
|
+
#CHAT FUNNEL EVENTS
|
|
46
45
|
EventType.CHAT_FUNNEL_STARTED : ChatFunnelEvent,
|
|
47
|
-
EventType.
|
|
46
|
+
EventType.CHAT_FUNNEL_STAGE_CHANGED : ChatFunnelEvent,
|
|
48
47
|
EventType.CHAT_FUNNEL_COMPLETED : ChatFunnelEvent,
|
|
49
48
|
EventType.CHAT_FUNNEL_ABANDONED : ChatFunnelEvent,
|
|
50
49
|
|
|
@@ -86,6 +85,10 @@ EVENT_TO_TYPE_CLASSES = {
|
|
|
86
85
|
EventType.WORKFLOW_CREATED : AssetEvent,
|
|
87
86
|
EventType.WORKFLOW_UPDATED : AssetEvent,
|
|
88
87
|
EventType.WORKFLOW_DELETED : AssetEvent,
|
|
88
|
+
#FORM FIELDS
|
|
89
|
+
EventType.FORM_FIELD_CREATED : AssetEvent,
|
|
90
|
+
EventType.FORM_FIELD_UPDATED : AssetEvent,
|
|
91
|
+
EventType.FORM_FIELD_DELETED : AssetEvent,
|
|
89
92
|
#AGENTS
|
|
90
93
|
EventType.USER_CREATED : UserEvent,
|
|
91
94
|
EventType.USER_UPDATED : UserEvent,
|
|
@@ -42,10 +42,9 @@ class EventType(StrEnum):
|
|
|
42
42
|
#CONTINUOUS CONVERSATION
|
|
43
43
|
CONTINUOUS_CONVERSATION_CREATED = "chat.continuous_conversation.created"
|
|
44
44
|
CONTINUOUS_CONVERSATION_UPDATED = "chat.continuous_conversation.updated"
|
|
45
|
-
#FUNNEL
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
CHAT_FUNNEL_UPDATED = "chat.funnel.updated"
|
|
45
|
+
#CHAT FUNNEL EVENTS
|
|
46
|
+
CHAT_FUNNEL_STARTED = "chat.funnel.started"
|
|
47
|
+
CHAT_FUNNEL_STAGE_CHANGED = "chat.funnel.stage_changed"
|
|
49
48
|
CHAT_FUNNEL_COMPLETED = "chat.funnel.completed"
|
|
50
49
|
CHAT_FUNNEL_ABANDONED = "chat.funnel.abandoned"
|
|
51
50
|
|
|
@@ -84,13 +83,18 @@ class EventType(StrEnum):
|
|
|
84
83
|
FAST_ANSWER_CREATED = "company.fast_answer.created"
|
|
85
84
|
FAST_ANSWER_UPDATED = "company.fast_answer.updated"
|
|
86
85
|
FAST_ANSWER_DELETED = "company.fast_answer.deleted"
|
|
87
|
-
#
|
|
86
|
+
#FUNNELS
|
|
88
87
|
FUNNEL_CREATED = "company.funnel.created"
|
|
89
88
|
FUNNEL_UPDATED = "company.funnel.updated"
|
|
90
89
|
FUNNEL_DELETED = "company.funnel.deleted"
|
|
90
|
+
#FUNNEL STAGES
|
|
91
91
|
FUNNEL_STAGE_CREATED = "company.funnel_stage.created"
|
|
92
92
|
FUNNEL_STAGE_UPDATED = "company.funnel_stage.updated"
|
|
93
93
|
FUNNEL_STAGE_DELETED = "company.funnel_stage.deleted"
|
|
94
|
+
#FUNNEL MEMBERS
|
|
95
|
+
FUNNEL_MEMBER_ADDED = "company.funnel_member.added"
|
|
96
|
+
FUNNEL_MEMBER_UPDATED = "company.funnel_member.updated"
|
|
97
|
+
FUNNEL_MEMBER_REMOVED = "company.funnel_member.removed"
|
|
94
98
|
#BUSINESS AREA
|
|
95
99
|
BUSINESS_AREA_CREATED = "company.business_area.created"
|
|
96
100
|
BUSINESS_AREA_UPDATED = "company.business_area.updated"
|
|
@@ -118,3 +122,7 @@ class EventType(StrEnum):
|
|
|
118
122
|
FILTER_CRITERIA_CREATED = "company.filter_criteria.created"
|
|
119
123
|
FILTER_CRITERIA_UPDATED = "company.filter_criteria.updated"
|
|
120
124
|
FILTER_CRITERIA_DELETED = "company.filter_criteria.deleted"
|
|
125
|
+
#FORM FIELDS
|
|
126
|
+
FORM_FIELD_CREATED = "company.form_field.created"
|
|
127
|
+
FORM_FIELD_UPDATED = "company.form_field.updated"
|
|
128
|
+
FORM_FIELD_DELETED = "company.form_field.deleted"
|
letschatty/models/chat/chat.py
CHANGED
|
@@ -19,6 +19,7 @@ from ..utils.custom_exceptions.custom_exceptions import MissingAIAgentForSmartFo
|
|
|
19
19
|
from .time_left import TimeLeft
|
|
20
20
|
from ..company.conversation_topic import TopicTimelineEntry
|
|
21
21
|
from ..company.form_field import CollectedData
|
|
22
|
+
from ..company.CRM.funnel import ActiveFunnel
|
|
22
23
|
import json
|
|
23
24
|
import logging
|
|
24
25
|
logger = logging.getLogger(__name__)
|
|
@@ -47,6 +48,7 @@ class Chat(CompanyAssetModel):
|
|
|
47
48
|
chatty_ai_agent: Optional[ChattyAIAgentAssignedToChat] = Field(default=None, description="The id of the chatty ai agent that might or might not be assigned to the chat")
|
|
48
49
|
suggested_messages: List[MessageDraft] = Field(default_factory=list)
|
|
49
50
|
topics_timeline: List[TopicTimelineEntry] = Field(default_factory=list, description="Timeline of conversation topics throughout the conversation")
|
|
51
|
+
active_funnel: Optional[ActiveFunnel] = Field(default=None, description="Current active funnel for this chat")
|
|
50
52
|
model_config = ConfigDict(extra="ignore")
|
|
51
53
|
|
|
52
54
|
@property
|
|
@@ -267,7 +269,17 @@ class Chat(CompanyAssetModel):
|
|
|
267
269
|
@property
|
|
268
270
|
def bought_product_ids(self) -> List[StrObjectId]:
|
|
269
271
|
"""Get all sale ids in the chat"""
|
|
270
|
-
|
|
272
|
+
product_ids: List[StrObjectId] = []
|
|
273
|
+
for sale in self.sales:
|
|
274
|
+
sale_product_ids = getattr(sale, "product_ids", None)
|
|
275
|
+
if sale_product_ids:
|
|
276
|
+
for product_id in sale_product_ids:
|
|
277
|
+
if product_id not in product_ids:
|
|
278
|
+
product_ids.append(product_id)
|
|
279
|
+
elif sale.product_id:
|
|
280
|
+
if sale.product_id not in product_ids:
|
|
281
|
+
product_ids.append(sale.product_id)
|
|
282
|
+
return product_ids
|
|
271
283
|
|
|
272
284
|
@property
|
|
273
285
|
def products(self) -> List[AssignedAssetToChat]:
|
|
@@ -364,4 +376,3 @@ class Chat(CompanyAssetModel):
|
|
|
364
376
|
dump["last_message"] = self.last_message.model_dump_json(serializer=SerializerType.DATABASE) if self.last_message else None
|
|
365
377
|
dump["flow_states"] = [flow_state.model_dump_json(serializer=SerializerType.DATABASE) for flow_state in self.flow_states]
|
|
366
378
|
return dump
|
|
367
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
1
|
from .chat import Chat
|
|
3
2
|
from letschatty.models.company.assets import TagPreview, FlowPreview, ContactPoint, Sale, ChattyAIAgentPreview, ProductPreview
|
|
3
|
+
from letschatty.models.company.CRM.funnel import ActiveFunnel
|
|
4
4
|
|
|
5
5
|
from letschatty.models.utils.types.serializer_type import SerializerType
|
|
6
6
|
from pydantic import BaseModel
|
|
@@ -15,3 +15,8 @@ class ChatWithAssets(BaseModel):
|
|
|
15
15
|
contact_points: List[ContactPoint]
|
|
16
16
|
flows_links_states: List[FlowPreview]
|
|
17
17
|
chatty_ai_agent: Optional[ChattyAIAgentPreview]
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def active_funnel(self) -> Optional[ActiveFunnel]:
|
|
21
|
+
"""Convenience property to access the chat's active funnel"""
|
|
22
|
+
return self.chat.active_funnel
|
letschatty/models/chat/client.py
CHANGED
|
@@ -5,7 +5,6 @@ from ..utils.types.identifier import StrObjectId
|
|
|
5
5
|
from .quality_scoring import QualityScore
|
|
6
6
|
from .highlight import Highlight
|
|
7
7
|
from ..company.assets.chat_assets import AssignedAssetToChat, SaleAssignedToChat, ContactPointAssignedToChat
|
|
8
|
-
from ..company.CRM.funnel import ClientFunnel
|
|
9
8
|
from ..utils.types.serializer_type import SerializerType
|
|
10
9
|
|
|
11
10
|
class Client(CompanyAssetModel):
|
|
@@ -23,7 +22,6 @@ class Client(CompanyAssetModel):
|
|
|
23
22
|
contact_points: List[ContactPointAssignedToChat] = Field(default=list())
|
|
24
23
|
business_area: Optional[StrObjectId] = Field(default=None, description="It's a business related area, that works as a queue for the chats")
|
|
25
24
|
external_id: Optional[str] = Field(default=None)
|
|
26
|
-
funnels : List[ClientFunnel] = Field(default=list())
|
|
27
25
|
exclude_fields = {
|
|
28
26
|
SerializerType.FRONTEND: {"products", "tags", "sales", "contact_points", "highlights"}
|
|
29
27
|
}
|
|
@@ -30,7 +30,7 @@ class ContinuousConversation(ChattyAssetModel):
|
|
|
30
30
|
template_message_waid: Optional[str] = None
|
|
31
31
|
status: Optional[ContinuousConversationStatus] = Field(default=ContinuousConversationStatus.CREATED)
|
|
32
32
|
active: bool = Field(default=True)
|
|
33
|
-
expires_at: datetime = Field(
|
|
33
|
+
expires_at: datetime = Field(default_factory=lambda: datetime.now(ZoneInfo("UTC")) + timedelta(days=10))
|
|
34
34
|
messages: List[MessageDraft]
|
|
35
35
|
creator_id: StrObjectId
|
|
36
36
|
forced_send: bool = Field(default=False)
|