新增大量WhatsApp适配器相关代码,包括账号管理、会话处理、消息收发、验证授权、媒体处理、互动命令、审批流程、健康检测等完整功能模块,搭建基础的Baileys协议WhatsApp接入能力
33 lines
877 B
Python
33 lines
877 B
Python
from __future__ import annotations
|
|
|
|
|
|
def jid_to_thread_key(channel_id: str, jid: str, scope: str = "per_sender") -> str:
|
|
if scope == "global":
|
|
return f"{channel_id}:global"
|
|
if "@g.us" in jid:
|
|
return f"{channel_id}:group:{jid}"
|
|
return f"{channel_id}:dm:{_extract_sender_number(jid)}"
|
|
|
|
|
|
def _extract_sender_number(jid: str) -> str:
|
|
return jid.split("@")[0]
|
|
|
|
|
|
def jid_to_chat_type(jid: str) -> str:
|
|
if "@g.us" in jid:
|
|
return "group"
|
|
if "@broadcast" in jid:
|
|
return "broadcast"
|
|
return "direct"
|
|
|
|
|
|
def normalize_phone(phone: str) -> str:
|
|
return phone.lstrip("+").replace(" ", "").replace("-", "")
|
|
|
|
|
|
def resolve_session_scope(config: dict) -> str:
|
|
scope = config.get("sessionScope", config.get("session_scope", "per_sender"))
|
|
if scope not in ("per_sender", "global"):
|
|
return "per_sender"
|
|
return scope
|