78 lines
1.8 KiB
Python
78 lines
1.8 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
|
||
|
|
from yuxi.channel.extensions.ringcentral.sdk import AsyncRingCentralClient
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
async def list_tasks(
|
||
|
|
client: AsyncRingCentralClient,
|
||
|
|
chat_id: str,
|
||
|
|
*,
|
||
|
|
page: int = 1,
|
||
|
|
per_page: int = 20,
|
||
|
|
) -> dict:
|
||
|
|
return await client.get(
|
||
|
|
f"/restapi/v1.0/glip/chats/{chat_id}/tasks",
|
||
|
|
params={"page": page, "perPage": per_page},
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
async def create_task(
|
||
|
|
client: AsyncRingCentralClient,
|
||
|
|
chat_id: str,
|
||
|
|
subject: str,
|
||
|
|
*,
|
||
|
|
assignees: list[str] | None = None,
|
||
|
|
body: str | None = None,
|
||
|
|
due_date: str | None = None,
|
||
|
|
) -> dict:
|
||
|
|
payload = {"subject": subject}
|
||
|
|
if assignees:
|
||
|
|
payload["assignees"] = [{"id": a} for a in assignees]
|
||
|
|
if body:
|
||
|
|
payload["body"] = body
|
||
|
|
if due_date:
|
||
|
|
payload["dueDate"] = due_date
|
||
|
|
return await client.post(
|
||
|
|
f"/restapi/v1.0/glip/chats/{chat_id}/tasks",
|
||
|
|
body=payload,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
async def get_task(
|
||
|
|
client: AsyncRingCentralClient,
|
||
|
|
task_id: str,
|
||
|
|
) -> dict:
|
||
|
|
return await client.get(f"/restapi/v1.0/glip/tasks/{task_id}")
|
||
|
|
|
||
|
|
|
||
|
|
async def update_task(
|
||
|
|
client: AsyncRingCentralClient,
|
||
|
|
task_id: str,
|
||
|
|
*,
|
||
|
|
subject: str | None = None,
|
||
|
|
body: str | None = None,
|
||
|
|
due_date: str | None = None,
|
||
|
|
status: str | None = None,
|
||
|
|
) -> dict:
|
||
|
|
payload = {}
|
||
|
|
if subject is not None:
|
||
|
|
payload["subject"] = subject
|
||
|
|
if body is not None:
|
||
|
|
payload["body"] = body
|
||
|
|
if due_date is not None:
|
||
|
|
payload["dueDate"] = due_date
|
||
|
|
if status is not None:
|
||
|
|
payload["status"] = status
|
||
|
|
return await client.patch(
|
||
|
|
f"/restapi/v1.0/glip/tasks/{task_id}",
|
||
|
|
body=payload,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
async def delete_task(client: AsyncRingCentralClient, task_id: str) -> None:
|
||
|
|
await client.delete(f"/restapi/v1.0/glip/tasks/{task_id}")
|