Files
wehub-resource-sync 4ce4204b6c
CI / Lint (push) Failing after 2s
CI / Build (push) Has been skipped
SDK CI / PHP SDK (push) Failing after 1s
Split PHP SDK / PHP SDK tests (push) Failing after 1s
CI / Test (push) Failing after 1s
CI / Dashboard (push) Failing after 0s
SDK CI / JavaScript SDK (push) Failing after 0s
SDK CI / Python SDK (push) Failing after 2s
SDK CI / Java SDK (push) Failing after 1s
Split PHP SDK / Mirror sdk/php -> rmyndharis/openwa-php (push) Has been skipped
CI / Test (PostgreSQL migrations) (push) Failing after 7m47s
CI / Docker Build (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:24:08 +08:00

88 lines
3.6 KiB
Python

"""Groups resource — WhatsApp group management.
Backed by ``src/modules/group/group.controller.ts``.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, TypedDict
from .._http import quote_segment
from ..types import (
CreateGroupRequest,
GroupInfo,
GroupSummary,
InviteCodeResponse,
SuccessResult,
)
if TYPE_CHECKING:
from .._http import HttpExecutor
class ListGroupsQuery(TypedDict, total=False):
limit: int
offset: int
class GroupsResource:
def __init__(self, http: "HttpExecutor") -> None:
self._http = http
def list(self, session_id: str, query: ListGroupsQuery | None = None) -> list[GroupSummary]:
return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/groups", query=query)
def get(self, session_id: str, group_id: str) -> GroupInfo:
return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}")
def create(self, session_id: str, body: CreateGroupRequest) -> GroupInfo:
return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/groups", body=body)
def add_participants(self, session_id: str, group_id: str, participants: list[str]) -> SuccessResult:
return self._http.request(
"POST", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/participants",
body={"participants": participants},
)
def remove_participants(self, session_id: str, group_id: str, participants: list[str]) -> SuccessResult:
return self._http.request(
"DELETE", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/participants",
body={"participants": participants},
)
def promote_participants(self, session_id: str, group_id: str, participants: list[str]) -> SuccessResult:
return self._http.request(
"POST", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/participants/promote",
body={"participants": participants},
)
def demote_participants(self, session_id: str, group_id: str, participants: list[str]) -> SuccessResult:
return self._http.request(
"POST", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/participants/demote",
body={"participants": participants},
)
def set_subject(self, session_id: str, group_id: str, subject: str) -> SuccessResult:
return self._http.request(
"PUT", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/subject", body={"subject": subject}
)
def set_description(self, session_id: str, group_id: str, description: str) -> SuccessResult:
return self._http.request(
"PUT", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/description",
body={"description": description},
)
def leave(self, session_id: str, group_id: str) -> SuccessResult:
return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/leave")
def invite_code(self, session_id: str, group_id: str) -> InviteCodeResponse:
return self._http.request(
"GET", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/invite-code"
)
def revoke_invite_code(self, session_id: str, group_id: str) -> InviteCodeResponse:
return self._http.request(
"POST", f"/api/sessions/{quote_segment(session_id)}/groups/{quote_segment(group_id)}/invite-code/revoke"
)