This document provides comprehensive API documentation for the Hellotext WordPress plugin. The plugin integrates WooCommerce with Hellotext's customer engagement platform, tracking customer activities and synchronizing profiles.
The plugin follows a clean architecture pattern with distinct layers:
- Api/ - HTTP clients for external communication
- Adapters/ - Transform WooCommerce data to Hellotext payloads
- Events/ - Event handlers for WooCommerce hooks
- Services/ - Business logic for profile and session management
- Misc/ - WordPress integration (settings, scripts)
The plugin uses a cookie-based session system (hello_session) to track anonymous users and associate their activities with Hellotext profiles.
The main HTTP client for communicating with the Hellotext API.
Makes an HTTP request to the Hellotext API.
Parameters:
$method- HTTP method (GET, POST, PATCH, PUT, DELETE)$path- API endpoint path$data- Request payload
Returns:
[
'request' => [
'method' => string,
'path' => string,
'data' => array
],
'status' => int, // HTTP status code
'body' => array|null // Decoded JSON response
]Example:
use Hellotext\Api\Client;
use Hellotext\Constants;
$response = Client::post(Constants::API_ENDPOINT_PROFILES, [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john@example.com'
]);get(string $path, ?array $data = null): arraypost(string $path, ?array $data = null): arraypatch(string $path, ?array $data = null): arrayput(string $path, ?array $data = null): arraydelete(string $path, ?array $data = null): array
Creates a client instance with a custom API suffix. Useful for testing.
Example:
$client = Client::with_sufix('/v2');Tracks customer activities and sends them to Hellotext.
public function __construct(?string $session = null)Creates a new event tracker. If no session is provided, it attempts to retrieve it from the hello_session cookie.
Tracks an event with the given action and payload.
Parameters:
$action- Event action name (use constants fromConstants::EVENT_*)$payload- Event data
Example:
use Hellotext\Api\Event;
use Hellotext\Constants;
$event = new Event();
$event->track(Constants::EVENT_PRODUCT_VIEWED, [
'object_parameters' => [
'reference' => '123',
'name' => 'Product Name',
'price' => ['amount' => 2999, 'currency' => 'USD']
]
]);Adapters transform WooCommerce objects into Hellotext-compatible payloads.
Transforms WooCommerce products.
public function __construct(int|\WC_Product $product)Accepts either a product ID or a WC_Product instance.
Returns the adapted product payload.
Returns:
[
'reference' => int, // Product ID
'source' => 'woo',
'name' => string,
'categories' => string[],
'price' => [
'amount' => int, // Price in cents
'currency' => string
],
'tags' => string[],
'image_url' => string,
'url' => string // Product permalink
]Example:
use Hellotext\Adapters\ProductAdapter;
$adapter = new ProductAdapter($product_id);
$payload = $adapter->get();Transforms WooCommerce orders.
public function __construct(\WC_Order $order)Returns the adapted order payload.
Returns:
[
'reference' => int, // Order ID
'source' => 'woo',
'status' => string, // Order status
'subtotal' => ['amount' => int, 'currency' => string],
'total' => ['amount' => int, 'currency' => string],
'tax' => ['amount' => int, 'currency' => string],
'shipping' => ['amount' => int, 'currency' => string],
'discount' => ['amount' => int, 'currency' => string],
'items' => array[], // Order items
'url' => string
]Transforms WooCommerce refunds.
public function __construct(\WC_Order_Refund $refund)Returns the adapted refund payload.
Converts prices to Hellotext format (cents-based).
public function __construct(float|string|null $price)Returns price in cents with currency.
Returns:
[
'amount' => int, // Price in cents
'currency' => string // e.g., 'USD'
]Manages Hellotext profile creation and association.
public function __construct(?int $user_id, array $billing = [])Parameters:
$user_id- WordPress user ID (null for guest checkout)$billing- Billing data from checkout
Executes the profile creation/association flow:
- Checks if profile exists
- Creates new profile if needed
- Associates profile with session
- Updates session metadata
Example:
use Hellotext\Services\CreateProfile;
$service = new CreateProfile($user->ID);
$service->process();
// For guest checkout with billing data
$service = new CreateProfile(null, [
'first_name' => 'Jane',
'last_name' => 'Smith',
'email' => 'jane@example.com',
'phone' => '+1234567890'
]);
$service->process();Manages session encryption and cookies.
Creates a new session identifier.
Returns: UUID session string
Encrypts a session string using AES-256-CBC.
Decrypts an encrypted session string.
Sets the hello_session cookie with proper expiration and security flags.
Example:
use Hellotext\Services\Session;
$session = Session::create();
Session::set_cookie($session);
// Later, encrypt for storage
$encrypted = Session::encrypt($session);
add_post_meta($order_id, 'hellotext_session', $encrypted);All plugin constants are centralized in this class.
Constants::API_VERSION // 'v1'
Constants::API_ENDPOINT_TRACK // '/v1/track/events'
Constants::API_ENDPOINT_PROFILES // '/profiles'
Constants::API_ENDPOINT_SESSIONS // '/sessions'
Constants::API_ENDPOINT_WEBCHATS // '/v1/wordpress/webchats'
Constants::API_ENDPOINT_INTEGRATIONS_WOO // '/integrations/woo'Constants::ENCRYPTION_METHOD // 'aes-256-cbc'
Constants::SESSION_COOKIE_NAME // 'hello_session'Constants::OPTION_BUSINESS_ID // 'hellotext_business_id'
Constants::OPTION_ACCESS_TOKEN // 'hellotext_access_token'
Constants::OPTION_WEBCHAT_ID // 'hellotext_webchat_id'
Constants::OPTION_WEBCHAT_PLACEMENT // 'hellotext_webchat_placement'
Constants::OPTION_WEBCHAT_BEHAVIOUR // 'hellotext_webchat_behaviour'Constants::META_PROFILE_ID // 'hellotext_profile_id'
Constants::META_SESSION // 'hellotext_session'Constants::EVENT_ORDER_PLACED // 'order.placed'
Constants::EVENT_ORDER_CONFIRMED // 'order.confirmed'
Constants::EVENT_ORDER_CANCELLED // 'order.cancelled'
Constants::EVENT_ORDER_DELIVERED // 'order.delivered'
Constants::EVENT_PRODUCT_PURCHASED // 'product.purchased'
Constants::EVENT_PRODUCT_VIEWED // 'product.viewed'
Constants::EVENT_CART_ADDED // 'cart.added'
Constants::EVENT_CART_REMOVED // 'cart.removed'
Constants::EVENT_REFUND_RECEIVED // 'refund.received'
Constants::EVENT_COUPON_REDEEMED // 'coupon.redeemed'Triggers profile creation/association.
Parameters:
$payload- Either user ID (int) or billing data (array)
Usage:
// For logged-in user
do_action('hellotext_create_profile', $user_id);
// For guest with billing data
do_action('hellotext_create_profile', [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john@example.com',
'phone' => '+1234567890'
]);The plugin automatically hooks into these WooCommerce actions:
woocommerce_after_order_details- Track order placementwoocommerce_order_status_changed- Track order status updateswoocommerce_order_refunded- Track refundswoocommerce_add_to_cart- Track cart additionswoocommerce_cart_item_removed- Track cart removalswoocommerce_applied_coupon- Track coupon usagewp_footer- Inject tracking scripts and webchat
For testing information, see DEVELOPMENT.md.
The plugin respects the following environment variables:
APP_ENV- Environment mode:production,development, ortestHELLOTEXT_API_URL- Override API URL (development only)
Example (.htaccess):
SetEnv APP_ENV development
SetEnv HELLOTEXT_API_URL https://api-dev.hellotext.comMost methods that interact with external APIs will throw exceptions on failure. Always wrap critical API calls in try-catch blocks:
try {
$adapter = new ProductAdapter($product_id);
$payload = $adapter->get();
} catch (\Exception $e) {
error_log('Hellotext: Failed to adapt product - ' . $e->getMessage());
}All API requests include an Authorization: Bearer header with either:
- Business ID for event tracking
- Access Token for profile/session management
Sessions are encrypted using AES-256-CBC before storage in the database. The encryption key is derived from WordPress security keys.
All user input is sanitized using WordPress functions (sanitize_text_field(), etc.) before processing.
This plugin is licensed under GPL v2. See LICENSE for details.