meta whatsapp chat
This commit is contained in:
parent
54f75387eb
commit
5ced0d0812
10 changed files with 1015 additions and 25 deletions
|
|
@ -20,8 +20,12 @@ from .whatsapp_onboarding import (
|
|||
customer_token_for_phone,
|
||||
developer_config,
|
||||
disconnect_account,
|
||||
download_account_media,
|
||||
list_account_messages,
|
||||
list_accounts,
|
||||
mask_identifier,
|
||||
register_phone_number,
|
||||
send_account_message,
|
||||
list_templates,
|
||||
refresh_account,
|
||||
signup_public_config,
|
||||
|
|
@ -150,6 +154,26 @@ class SendWhatsAppTextRequest(BaseModel):
|
|||
phone_number_id: str = Field(min_length=4, max_length=64)
|
||||
|
||||
|
||||
class CustomerSendRequest(BaseModel):
|
||||
to: str = Field(min_length=8, max_length=20)
|
||||
message_type: str = "text"
|
||||
text: str | None = Field(default=None, max_length=4096)
|
||||
reply_to: str | None = None
|
||||
template_name: str | None = None
|
||||
template_language: str = "en"
|
||||
media_link: str | None = None
|
||||
media_caption: str | None = None
|
||||
media_filename: str | None = None
|
||||
interactive_body: str | None = None
|
||||
interactive_buttons: list[dict[str, str]] | None = None
|
||||
reaction_message_id: str | None = None
|
||||
reaction_emoji: str | None = None
|
||||
|
||||
|
||||
class RegisterPhoneRequest(BaseModel):
|
||||
pin: str | None = Field(default=None, max_length=6)
|
||||
|
||||
|
||||
class SignupCompleteRequest(BaseModel):
|
||||
event: str = Field(min_length=1, max_length=80)
|
||||
code: str | None = Field(default=None, max_length=2048)
|
||||
|
|
@ -202,6 +226,48 @@ async def whatsapp_account_refresh(
|
|||
return await refresh_account(db, user, account_id)
|
||||
|
||||
|
||||
@router.get("/accounts/{account_id}/messages")
|
||||
def whatsapp_account_messages(
|
||||
account_id: str,
|
||||
limit: int = Query(default=300, ge=1, le=500),
|
||||
db: Session = Depends(get_db),
|
||||
user: UserAccount = Depends(current_user),
|
||||
) -> list[dict]:
|
||||
return list_account_messages(db, user, account_id, limit)
|
||||
|
||||
|
||||
@router.post("/accounts/{account_id}/messages/send")
|
||||
async def whatsapp_account_send(
|
||||
account_id: str,
|
||||
payload: CustomerSendRequest,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserAccount = Depends(current_user),
|
||||
) -> dict:
|
||||
return await send_account_message(db, user, account_id, payload.model_dump())
|
||||
|
||||
|
||||
@router.get("/accounts/{account_id}/media/{media_id}")
|
||||
async def whatsapp_account_media(
|
||||
account_id: str,
|
||||
media_id: str,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserAccount = Depends(current_user),
|
||||
) -> Response:
|
||||
content, mime_type = await download_account_media(db, user, account_id, media_id)
|
||||
return Response(content=content, media_type=mime_type)
|
||||
|
||||
|
||||
@router.post("/accounts/{account_id}/phones/{phone_id}/register")
|
||||
async def whatsapp_register_phone(
|
||||
account_id: str,
|
||||
phone_id: str,
|
||||
payload: RegisterPhoneRequest,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserAccount = Depends(current_user),
|
||||
) -> dict:
|
||||
return await register_phone_number(db, user, account_id, phone_id, payload.pin)
|
||||
|
||||
|
||||
@router.post("/accounts/{account_id}/disconnect")
|
||||
async def whatsapp_account_disconnect(
|
||||
account_id: str,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue