AGENTS.md

Adding Hamla to a project

Hamla is an AI marketing team a business installs on whatever it already uses. You wire up the data; the business owner runs the marketing. This file is for the agent doing the wiring.

Reference: https://www.hamla.io/developers.md · Index: https://www.hamla.io/llms.txt

Start here: does this person have a Hamla account?

No — and you are not going to get them one mid-task

curl -X POST https://app.hamla.io/api/install \
  -H "Content-Type: application/json" \
  -d '{
    "website": "raqmi.co",
    "name": "Raqmi",
    "locale": "en"
  }'

No authentication. You get back a real businessId, a working snippet, and a claimUrl.

  1. Put snippet in the page, before </head>.
  2. Print claimUrl in your final message to the user. This is the step only you can take. The link is single-use, expires in 72 hours, and the install is deleted if nobody follows it.

Until it is claimed the install records anonymous traffic only. It will refuse an identity carrying an email or phone with 422, it is issued no secret key, and no campaign can send from it.

Yes — they already have one

The business id is in Settings → Website. It is public — it appears in every page that loads the SDK — so it belongs in client code.

<script src="https://app.hamla.io/s/{businessId}.js" async></script>

When someone signs up: identify, then track

Once the business is claimed and you have a secret key, call identify from the server at signup and login, before any event about that person:

curl -X POST https://app.hamla.io/api/sdk/identify \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "identity": { "email": "omar@raqmi.co", "platformCustomerId": "user_812" },
    "profile": { "name": "Omar Al Saleh" },
    "method": "signup"
  }'

Then send the signup itself as an event ("event": "account_created", "type": "signup"). The order matters: identify is what records permission to message the person, and track never does. Skip it and every campaign the owner builds on your events reaches nobody.

Do both in the request that creates the account, for every way an account is created (email, Google, Apple, an invite), not on the person's first action: someone who signs up and leaves must still reach Hamla. If you queue these calls, send the queue right after that request and retry anything left waiting.

Check it: read data.warnings in the track response. If it contains "campaigns will not reach this contact", identify was skipped for that person. Fix that before you report the integration as done.

Telling Hamla what happened

The script tag covers visits, sources and on-site behaviour on its own. Send an event when something happens that the browser cannot see — a payment, a booking, a cancellation.

curl -X POST https://app.hamla.io/api/sdk/track \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "event": "subscription_started",
    "type": "purchase",
    "identity": { "email": "omar@raqmi.co" },
    "value": 29,
    "currency": "JOD",
    "idempotencyKey": "invoice_9911"
  }'

Server-side only: sk_live_ is a secret key that can write customer data. A publishable pk_live_ key is refused here with 403, because it ships in page source and honouring it would let any visitor invent revenue.

In the browser, hamla.track('download_ebook', { asset: 'guide.pdf' }) needs no key at all.

event is yours, type is Hamla's

Name the event whatever your domain calls it, in whatever language. type is the vocabulary Hamla acts on:

type means effect
purchase Money received Adds to revenue, counts as an order
refund Money returned Subtracts from revenue
booking Committed, not yet paid No revenue
lead Identity captured No revenue
checkout_started Started, not finished No revenue
fulfilled They received it No revenue
cancelled It ended No revenue
signup Account created No revenue
trial Free trial started No revenue
contact Reached out No revenue
application Applied No revenue

Omit type and Hamla infers it from the name and the money. Send it when you know it.

Make the events start campaigns

Events alone send nothing. You are not done until every moment that should reach someone has a campaign listening for it. Connect the MCP server (https://app.hamla.io/mcp, OAuth; the owner signs in), then for each such event:

  1. createCampaign with trigger app_event, connectionType hamla/events and eventName exactly as your code sends it. Write the message for the person in that event's identity.
  2. requestCampaignLaunch. It returns a link; the owner approves the launch in Hamla. You never launch on your own.
  3. Fire the event once for a test person and confirm with queryContacts that it reached their timeline.

No MCP in your environment? Give the owner the list of events and what each should send, so they can ask Hamla to build them.

Use the event in the message: each key of its properties is {{event.<key>}} (properties.appName → {{event.appName}}). Send every property a message will show from the first version (the other person's first name, the item, a link): a campaign is checked against the latest real event, so a property added later can't be used until an event carrying it arrives. A link property must always have a value; send a general page when there is nothing specific. Each event sends its own message, right away, every time it happens. Campaigns that start from a segment or a schedule are paced: a limited number of automatic campaigns per person per day and week across the business (https://docs.hamla.io/reference/timing), so start a promotion that should wait its turn from a segment. Launching needs an active plan.

Do not