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

41 lines
1.7 KiB
Python

"""Labels resource — WhatsApp Business chat labels.
Backed by ``src/modules/label/label.controller.ts``
(``@Controller('sessions/:sessionId/labels')``). Labels are a WhatsApp Business
feature; the session must be a business account.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from .._http import quote_segment
from ..types import AddLabelRequest, LabelRecord, SuccessResult
if TYPE_CHECKING:
from .._http import HttpExecutor
class LabelsResource:
def __init__(self, http: "HttpExecutor") -> None:
self._http = http
def list(self, session_id: str) -> list[LabelRecord]:
return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/labels")
def get(self, session_id: str, label_id: str) -> LabelRecord:
return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/labels/{quote_segment(label_id)}")
def for_chat(self, session_id: str, chat_id: str) -> list[LabelRecord]:
return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/labels/chat/{quote_segment(chat_id)}")
def add_to_chat(self, session_id: str, chat_id: str, body: AddLabelRequest) -> SuccessResult:
"""Add a label to a chat. Requires an OPERATOR-level key."""
return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/labels/chat/{quote_segment(chat_id)}", body=body)
def remove_from_chat(self, session_id: str, chat_id: str, label_id: str) -> SuccessResult:
"""Remove a label from a chat. Requires an OPERATOR-level key."""
return self._http.request(
"DELETE", f"/api/sessions/{quote_segment(session_id)}/labels/chat/{quote_segment(chat_id)}/{quote_segment(label_id)}"
)