51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from .types import BotFrameworkActivity
|
||
|
|
|
||
|
|
|
||
|
|
def build_dm_session_key(activity: BotFrameworkActivity, bot_app_id: str) -> str:
|
||
|
|
from_id = activity.from_id or "unknown"
|
||
|
|
return f"msteams:dm:{bot_app_id}:{from_id}"
|
||
|
|
|
||
|
|
|
||
|
|
def build_group_session_key(activity: BotFrameworkActivity) -> str:
|
||
|
|
return f"msteams:group:{activity.conversation_id}"
|
||
|
|
|
||
|
|
|
||
|
|
def build_channel_session_key(activity: BotFrameworkActivity) -> str:
|
||
|
|
return f"msteams:channel:{activity.conversation_id}"
|
||
|
|
|
||
|
|
|
||
|
|
def build_thread_session_key(activity: BotFrameworkActivity) -> str:
|
||
|
|
thread_root = activity.reply_to_id or "unknown"
|
||
|
|
return f"msteams:thread:{activity.conversation_id}:{thread_root}"
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_session_key(activity: BotFrameworkActivity, bot_app_id: str) -> str:
|
||
|
|
ct = activity.conversation_type
|
||
|
|
|
||
|
|
if ct == "personal":
|
||
|
|
return build_dm_session_key(activity, bot_app_id)
|
||
|
|
|
||
|
|
if ct == "channel":
|
||
|
|
if activity.is_channel_thread:
|
||
|
|
return build_thread_session_key(activity)
|
||
|
|
return build_channel_session_key(activity)
|
||
|
|
|
||
|
|
return build_group_session_key(activity)
|
||
|
|
|
||
|
|
|
||
|
|
def build_dm_conversation_label(activity: BotFrameworkActivity, bot_app_id: str) -> str:
|
||
|
|
return f"msteams:dm:{activity.from_id}"
|
||
|
|
|
||
|
|
|
||
|
|
def build_group_conversation_label(activity: BotFrameworkActivity) -> str:
|
||
|
|
return f"msteams:group:{activity.conversation_id}"
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_conversation_label(activity: BotFrameworkActivity) -> str:
|
||
|
|
ct = activity.conversation_type
|
||
|
|
if ct == "personal":
|
||
|
|
return f"msteams:dm:{activity.from_id}"
|
||
|
|
return f"msteams:{activity.conversation_id}"
|