hub WhatsApp Gateway

On-Site Documentation

Python SDK Examples

Requests and Flask examples for WhatsApp Gateway customer integrations.

Python

Python SDK Examples

SDK examples are available now. Official package releases are being prepared.

Configuration

BASE_URL = 'https://evoapi.faisak.com'
API_KEY = 'wg_live_replace_with_your_key'

Send Operational Message

import requests

payload = {
    'instance_id': 'demo-support-line',
    'phone': '+9665XXXXXXX',
    'message': 'The scheduled maintenance window has started.',
    'message_purpose': 'operational',
}

response = requests.post(
    f'{BASE_URL}/api/send-message',
    headers={
        'Authorization': f'Bearer {API_KEY}',
        'Content-Type': 'application/json',
    },
    json=payload,
    timeout=15,
)

data = response.json()

Allowed purposes are transactional, operational, support, internal_team, and authentication. Marketing, cold outreach, and bulk campaigns are not allowed.

Handle Errors

if not data.get('success'):
    error_code = data.get('error', 'unknown_error')
    message = data.get('message', 'Request failed.')

    # Common examples:
    # module_not_enabled, message_purpose_not_allowed,
    # recipient_suppressed, sending_throttled
    raise RuntimeError(f'{error_code}: {message}')

Verify Webhook Signature

import hmac
import hashlib

def verify_webhook_signature(timestamp, raw_body, signature, secret):
    digest = hmac.new(
        secret.encode(),
        f'{timestamp}.{raw_body}'.encode(),
        hashlib.sha256,
    ).hexdigest()

    expected = f'sha256={digest}'
    return hmac.compare_digest(expected, signature)

Flask Webhook Receiver

from flask import Flask, request, abort

app = Flask(__name__)
WEBHOOK_SECRET = 'replace_with_webhook_signing_secret'

@app.post('/webhooks/whatsapp-gateway')
def whatsapp_gateway_webhook():
    raw_body = request.get_data(as_text=True)
    timestamp = request.headers.get('X-WhatsApp-Gateway-Timestamp', '')
    signature = request.headers.get('X-WhatsApp-Gateway-Signature', '')

    if not verify_webhook_signature(timestamp, raw_body, signature, WEBHOOK_SECRET):
        abort(401)

    event = request.get_json(force=True)

    if event.get('event') == 'message.received':
        # Handle event['from'] and event['message_text'].
        pass

    if event.get('event') == 'recipient.opted_out':
        # Suppress event['from'] in your application.
        pass

    return 'ok', 200