22 lines
637 B
Python
22 lines
637 B
Python
|
|
import httpx
|
||
|
|
|
||
|
|
GRAPH_API_VERSION = "v20.0"
|
||
|
|
GRAPH_API_BASE = f"https://graph.facebook.com/{GRAPH_API_VERSION}"
|
||
|
|
|
||
|
|
|
||
|
|
async def send_text_message(phone_number_id: str, access_token: str, to: str, text: str) -> None:
|
||
|
|
url = f"{GRAPH_API_BASE}/{phone_number_id}/messages"
|
||
|
|
payload = {
|
||
|
|
"messaging_product": "whatsapp",
|
||
|
|
"to": to,
|
||
|
|
"type": "text",
|
||
|
|
"text": {"body": text},
|
||
|
|
}
|
||
|
|
async with httpx.AsyncClient() as client:
|
||
|
|
response = await client.post(
|
||
|
|
url,
|
||
|
|
json=payload,
|
||
|
|
headers={"Authorization": f"Bearer {access_token}"},
|
||
|
|
)
|
||
|
|
response.raise_for_status()
|