Skip to content

Developers

Web chat JavaScript API

Use window.Hitapo to open and close the chat window, identify signed-in users, send messages and listen to events.

Once the web chat code loads on your page, the window.Hitapo object is ready. With this API you can control the chat window from your own interface.

Methods

MethodWhat does it do?
Hitapo.open()Opens the chat window.
Hitapo.close()Closes it.
Hitapo.toggle()Closes it if open, opens it if closed.
Hitapo.identify({ name, email, phone, attributes, userHash })Identifies the visitor and optionally adds custom fields. Verifies identity with userHash. Returns a Promise.
Hitapo.sendMessage(text)Sends a message on the visitor's behalf (empty text is ignored).
Hitapo.on(event, fn)Listens to an event; returns a function you call to stop listening.
Hitapo.shutdown()Ends the session: disconnects, forgets the visitor's identity and closes the window. Call it when the user signs out of your site.
Hitapo.versionVersion (e.g. 0.1.0).

Events

EventWhen?Data
readySettings have loaded and the window is ready.—
openThe window opened.—
closeThe window closed.—
messageA new message arrived from an agent or the AI.Message object
unreadThe unread message count changed.Number
Open with your own button and show unread messages
<button id="support">Live support <span id="badge"></span></button>
<script>
  document.getElementById("support").addEventListener("click", function () {
    Hitapo.open();
  });
  Hitapo.on("unread", function (n) {
    document.getElementById("badge").textContent = n > 0 ? n : "";
  });
</script>

Identifying signed-in users

If a customer is signed in on your site, pass their name and email with identify. The conversation is then matched to the right contact, and if Ask for e-mail before chat is on, the form is skipped.

identify
Hitapo.identify({
  name: "Ayşe Yılmaz",
  email: "ayse@example.com",
  phone: "+905551112233",
  attributes: { customerNo: "C-10245", membership: "gold", cartTotal: 1249.9 },
});
  • In the visitor's first session, name, email and phone are only filled in if empty; an identify call during a signed-in session updates them.
  • For security, an email or phone sent without a signature is never used to merge automatically with another contact. It shows as unverified on the profile, and if there's a match, your team only sees it as a suggestion. For automatic merging, use the signed identity verification below.
  • attributes are added to the contact's custom fields and appear on the contact profile. Values can be text (up to 1,000 characters), numbers or true/false; null deletes a field. Field names can contain letters, digits, _, . or - (up to 64 characters). One call can send up to 50 fields and 8 KB.
  • attributes come from the browser on your site, so the visitor can change them. Don't base decisions like prices or permissions on these fields.

Signed identity verification

If you want a signed-in customer's web chat to merge automatically with their existing profile that has the same email or phone (e.g. the same person writing on WhatsApp), add a userHash generated on your server to the identify call.

  1. Step 1:
    In Settings › Channels, open the web chat channel's settings, go to the Install tab and click Show secret in the Identity verification section (Owner or Admin).
  2. Step 2:
    Keep the secret on your server; never put it in the browser or in page code.
  3. Step 3:
    For each signed-in user, compute userHash = HMAC-SHA256(secret, email) as hex. If there's no email, sign the phone number, written exactly as you send it to identify.
  4. Step 4:
    Call Hitapo.identify({ email, userHash }) on the page.
Server (Node.js) + page
const crypto = require("node:crypto");
const userHash = crypto
  .createHmac("sha256", process.env.HITAPO_IDENTITY_SECRET)
  .update(user.email.trim().toLowerCase())
  .digest("hex");

// On the page:
Hitapo.identify({ name: user.name, email: user.email, userHash });
  • Emails are stored in lower case, so compute the signature with the lower-case email too.
  • If the signature is valid, the email counts as verified and is merged with the existing contact that has the same email; the chat window carries on without interruption.
  • The signature covers a single field: the email if one was sent, otherwise the phone. The other field in the same call stays unverified. Automatic merging only happens with a signed email; a signed phone counts as verified but doesn't merge on its own.
  • If the signature is wrong, the call is still accepted, but the details stay unverified.
  • If you change the secret with Rotate, signatures made with the old secret stop working; update the secret on your server too.

Calling before the code loads

The install code loads async. If you need to make calls before it has loaded, add the small snippet below before the install code. Calls are queued and run once the code loads.

Call queue
<script>
  (function (w) {
    var c = (w.Hitapo = w.Hitapo || { q: [] });
    ["open", "close", "toggle", "identify", "sendMessage", "on", "shutdown"].forEach(function (m) {
      c[m] = c[m] || function () { c.q.push([m].concat([].slice.call(arguments))); };
    });
  })(window);
  Hitapo.identify({ name: "Ayşe", email: "ayse@example.com" });
</script>

Advanced window settings

Some options that aren't in the dashboard can be set in the channel's config field with PATCH /api/v1/channels/:id:

KeyDescription
languagetr or en. If empty or auto, the browser language is used.
teaserDelayHow many seconds before the invitation bubble appears. Default 8; 0 turns it off.
teaserTextThe text in the invitation bubble.
privacyUrlLink to your privacy notice (the KVKK “Aydınlatma Metni”) on the pre-chat form (http/https).
avatarUrlImage in the window header.
avatarThe AI assistant's on-screen character: off (default) or anime.
soundfalse turns off the notification sound.
voiceEnabledfalse hides the Talk by voice button.
showBrandingfalse hides the “Powered by Hitapo” line.
Turn off the invitation bubble and link your privacy notice
curl -X PATCH https://api.hitapo.com/api/v1/channels/<CHANNEL_ID> \
  -H "Authorization: Bearer $HITAPO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"config":{"teaserDelay":0,"privacyUrl":"https://www.yoursite.com/privacy"}}'

Last updated: