A powerful and easy-to-use Python client for interacting with the A1Base API. Give your AI agents a phone number, an email, and real autonomy on the internet.
- Send individual messages via WhatsApp
- Send group messages with attachments
- Retrieve message and thread details
- Get recent messages from threads
- Handle incoming WhatsApp messages
- Built-in security features:
- HTTPS-only communication
- Input sanitization
- Webhook security
- Safe error handling
pip install a1basefrom a1base.client import A1BaseClient
from a1base.models import MessageRequest, GroupMessageRequestclient = A1BaseClient(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET"
)All API communication is enforced over HTTPS to ensure data security in transit. The client automatically validates HTTPS URLs.
Automatic validation of all user inputs:
- Message content validation
- Phone number format verification
- Service type validation
- Required field validation
Secure error handling implementation:
- Custom error types (A1BaseError, AuthenticationError, ValidationError)
- Sanitized error messages
- No sensitive data exposure
- Detailed error information
Send an individual message:
message = MessageRequest(
content="Hello, World!",
from_="+1234567890",
to="+0987654321",
service="whatsapp"
)
response = client.send_individual_message("your_account_id", message)
print(f"Message status: {response.status}")Send a group message:
message = GroupMessageRequest(
content="Hello, Group!",
from_="+1234567890",
thread_id="thread_123",
service="whatsapp"
)
response = client.send_group_message("your_account_id", message)
print(f"Message status: {response.status}")Get all threads:
threads = client.get_all_threads("your_account_id")
print(threads)Get thread details:
thread_details = client.get_thread_details(
account_id="your_account_id",
thread_id="thread_123"
)
print(thread_details)Get recent messages:
messages = client.get_recent_messages(
account_id="your_account_id",
thread_id="thread_123"
)
print(messages)Handle incoming WhatsApp messages using Flask:
from flask import Flask, request, jsonify
from a1base.models import WhatsAppIncomingData
app = Flask(__name__)
@app.post("/whatsapp/incoming")
def handle_incoming_message():
data = WhatsAppIncomingData(**request.json)
# Handle the message
return jsonify({"success": True})This project is licensed under the MIT License - see the LICENSE file for details.