hatang
The official Rust client for the Ha Tang (Hạ Tầng) API, the customer support and sales platform for businesses in Vietnam. Call it from your Rust backend (axum, actix-web, workers, CLIs) to:
- Send transactional email: templates, attachments, scheduling, batches of up to 100, idempotency keys.
- Run live chat and the support CRM: answer conversations as an agent, add private notes, send product cards, update customers and export them as CSV.
- Put plans and purchases on the customer's profile: web, App Store and Google Play subscriptions and one-time purchases, so agents and the AI chatbot answer from facts.
- Teach the AI assistant: upsert, batch and sync knowledge documents, and test what it would find.
- Take VietQR payments and orders: create payments and payment links, then verify IPN calls.
- Verify webhooks: Standard Webhooks (Svix) signatures with replay protection, plus chat identity hashes and app store purchase tokens.
# without an async runtime:
Rust 1.89+. An async client (Hatang, reqwest with rustls) and, with the blocking feature, a synchronous one
(hatang::blocking::Hatang) with the same methods.
Quick start
use ;
async
Email, with an attachment and an idempotency key (a retry with the same key sends once):
# async
Blocking (scripts, CLIs, sync frameworks; not inside an async runtime):
let hatang = from_env?;
let hits = hatang.knowledge.search?;
Bodies take any serde::Serialize value: the typed structs, or serde_json::json!({...}) for fields they do not
cover. Every method returns the API's JSON as a serde_json::Value (create calls such as emails.send give
Created { id, .. }). A call that does not succeed returns hatang::Error::Api with status (0 when Ha Tang was not
reached), name (validation_error, not_found…), message and retry_after (the retry-after header).
error.retryable() is true when the same call can succeed later: unreachable, 429 rate_limit_exceeded,
409 concurrent_idempotent_requests or 5xx; wait error.retry_after() when set, otherwise back off. The daily email
quota is not retryable that way: error.is_quota_exceeded() says when it is reached (it resets at midnight UTC).
# async
What is in it
| Namespace | Methods |
|---|---|
chat.subscriptions |
upsert, list, for_customer, purchase_token |
chat.purchases |
upsert, list, for_customer |
chat.customers |
list, get, update, conversations, export_csv |
chat.conversations |
list, list_with, get, update, messages, send, send_products |
chat.products |
list, search, get, create, update, remove |
chat.orders |
list, get, create, update, payment_link |
knowledge |
upsert, batch, sync, get, list, remove, search |
emails, batch |
send, get, list, update, cancel; batch.send |
payments |
create, get, list, cancel |
events |
send |
Helpers
use ;
// Signed chat identity: send this as `hash` with userId to identify() in the widget or the app SDKs.
identity_hash;
// StoreKit appAccountToken / Google Play obfuscatedAccountId for one of your users.
purchase_token;
// Webhooks (whsec_… secret) and payment IPN calls: pass the raw body, before JSON parsing.
let event = construct_webhook_event?;
let ipn = construct_ipn_event?;
Both return Error::Signature when the signature does not match; verify_webhook / verify_ipn return a bool.
headers can be an http::HeaderMap (axum, reqwest, hyper), a HashMap or a slice of (name, value) pairs.
A webhook endpoint in axum:
use ;
async
Configuration
| Builder method | Environment | Default |
|---|---|---|
api_key |
HATANG_API_KEY |
required |
base_url |
HATANG_BASE_URL |
https://api.hatang.dev |
environment |
HATANG_ENVIRONMENT |
the key's own |
timeout |
30 s | |
http_client |
a reqwest::Client of your own (proxies, pools, tests) |
let hatang = builder
.api_key
.timeout
.build?;
# Ok::
License: MIT
About Ha Tang
Ha Tang (Hạ Tầng) is a customer support platform for businesses in Vietnam: one inbox for your website, mobile app, Zalo, Messenger, Instagram, TikTok Shop, WhatsApp and email, with an AI assistant, plus a transactional email API, VietQR payments and e-invoices.
- Product: hatang.dev
- Guide: Ha Tang Rust SDK (Tiếng Việt)
- API reference: hatang
- REST API: hatang.dev/docs/reference/api
- AI coding agents: MCP server and rules
- Changelog: hatang.dev/docs/changelog
- Support: hatang.dev/contact