Implement business plans

This commit is contained in:
2026-03-02 00:00:53 +00:00
parent d22924f6aa
commit b3e183eb0a
26 changed files with 4109 additions and 39 deletions

View File

@@ -11,7 +11,7 @@ from django.urls import reverse
from signalbot import Command, Context, SignalBot
from core.clients import ClientBase, signalapi
from core.messaging import ai, history, media_bridge, natural, replies, utils
from core.messaging import ai, history, media_bridge, natural, replies, reply_sync, utils
from core.models import Chat, Manipulation, PersonIdentifier, PlatformChatLink, QueuedMessage
from core.util import logs
@@ -358,6 +358,13 @@ class HandleMessage(Command):
ts = c.message.timestamp
source_value = c.message.source
envelope = raw.get("envelope", {})
signal_source_message_id = str(
envelope.get("serverGuid")
or envelope.get("guid")
or envelope.get("timestamp")
or c.message.timestamp
or ""
).strip()
destination_number = sent_message.get("destination")
bot_uuid = str(getattr(c.bot, "bot_uuid", "") or "").strip()
@@ -639,16 +646,36 @@ class HandleMessage(Command):
identifier.user, identifier
)
session_cache[session_key] = chat_session
reply_ref = reply_sync.extract_reply_ref(self.service, raw)
reply_target = await reply_sync.resolve_reply_target(
identifier.user,
chat_session,
reply_ref,
)
sender_key = source_uuid or source_number or identifier_candidates[0]
message_key = (chat_session.id, ts, sender_key)
message_text = identifier_text_overrides.get(session_key, relay_text)
if message_key not in stored_messages:
await history.store_message(
origin_tag = reply_sync.extract_origin_tag(raw)
local_message = await history.store_message(
session=chat_session,
sender=sender_key,
text=message_text,
ts=ts,
outgoing=is_from_bot,
source_service=self.service,
source_message_id=signal_source_message_id,
source_chat_id=str(
destination_number_norm or dest_norm or sender_key or ""
),
reply_to=reply_target,
reply_source_service=str(
reply_ref.get("reply_source_service") or ""
),
reply_source_message_id=str(
reply_ref.get("reply_source_message_id") or ""
),
message_meta=reply_sync.apply_sync_origin({}, origin_tag),
)
stored_messages.add(message_key)
# Notify unified router to ensure service context is preserved
@@ -658,6 +685,7 @@ class HandleMessage(Command):
text=message_text,
ts=ts,
payload=msg,
local_message=local_message,
)
# TODO: Permission checks