Guides
Go client
A small, dependency-free client you can copy into a service, and the text-then-template pattern most WhatsApp senders need.
The client
It uses only the standard library. Copy it into your service as its own package.
package inbobo
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
type Client struct {
BaseURL string // https://inbobo.im/transport/api/v1
Token string // tpt_...
HTTP *http.Client
}
func New(baseURL, token string) *Client {
return &Client{BaseURL: baseURL, Token: token, HTTP: &http.Client{Timeout: 20 * time.Second}}
}
// Error is a documented API error. Branch on Code.
type Error struct {
Status int
Code string
Message string
}
func (e *Error) Error() string { return fmt.Sprintf("inbobo: %d %s: %s", e.Status, e.Code, e.Message) }
// Send posts one message and returns its message_id. Reuse the same key when retrying.
func (c *Client) Send(ctx context.Context, key string, request map[string]any) (string, error) {
payload, err := json.Marshal(request)
if err != nil {
return "", err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.BaseURL+"/messages", bytes.NewReader(payload))
if err != nil {
return "", err
}
req.Header.Set("Authorization", "Bearer "+c.Token)
req.Header.Set("Idempotency-Key", key)
req.Header.Set("Content-Type", "application/json")
resp, err := c.HTTP.Do(req)
if err != nil {
return "", err // outcome unknown: the caller retries with the SAME key
}
defer resp.Body.Close()
var body map[string]any
_ = json.NewDecoder(resp.Body).Decode(&body)
if resp.StatusCode != http.StatusAccepted {
return "", &Error{Status: resp.StatusCode, Code: fmt.Sprint(body["code"]), Message: fmt.Sprint(body["message"])}
}
return fmt.Sprint(body["message_id"]), nil
}Text first, template as fallback
Try free text, which is cheaper and friendlier inside the window, and fall back to an approved template when Inbobo answers WINDOW_CLOSED.
// SendNotice sends free text when the 24-hour window is open and falls back to a template when it is not.
func SendNotice(ctx context.Context, c *inbobo.Client, invoiceID, waID, text, documentURL string) (string, error) {
request := map[string]any{
"channel_id": os.Getenv("INBOBO_CHANNEL"),
"to": map[string]any{"wa_id": waID},
"purpose": "document_invoice_delivery",
"consent_reference": "invoice-" + invoiceID,
"attribution": map[string]any{"app_id": "invoice"},
"correlation": map[string]any{"invoice_id": invoiceID}, // comes back on every status callback
"message": map[string]any{"type": "text", "text": text},
}
key := "invoice-" + invoiceID + "-notice"
id, err := c.Send(ctx, key, request)
var apiErr *inbobo.Error
if errors.As(err, &apiErr) && apiErr.Code == "WINDOW_CLOSED" {
request["message"] = map[string]any{"type": "template", "template": map[string]any{
"name": "invoice_ready", "language": "en_US",
"parameters": []map[string]any{{"name": "1", "value": documentURL}},
}}
return c.Send(ctx, key, request) // nothing was created by the rejected call, so the key is free
}
return id, err
}Configuration
INBOBO_URL=https://inbobo.im/transport/api/v1
INBOBO_TOKEN=tpt_...
INBOBO_CHANNEL=ch_12
INBOBO_SIGNING_SECRET=... # for callbacksHandle delivery updates with the callback handler, which includes a complete Go example.