How it connects to Contacts
Chat Identification is the link between your website’s sign-in and the Contacts module in Mihu.- A contact matches: the chat opens on that contact. It shows up in their conversations next to their calls, WhatsApp messages and e-mails, and the AI agent can use what the contact record holds: name, appointments, notes, history.
- No contact matches: a new contact is created with the verified name and e-mail or phone number when the visitor sends their first message. The next visit is matched to it.
- No valid signature: the visitor is an anonymous web visitor and is never attached to an existing contact.
How it works
- You create an identity secret for your widget in Mihu. It lives on your server only.
- When a signed-in customer loads a page, the page asks your server who they are. Your server signs their e-mail or phone number with the secret (HMAC-SHA256) and returns it with the result — the hash.
- The page hands the e-mail or phone, the
hashand optionally anameto the widget withmihu.identify(...). - Mihu recomputes the signature. If it matches, the chat belongs to the contact with that e-mail or phone number.
Identifying a visitor creates nothing by itself. The contact and the conversation appear in Mihu with the visitor’s first message, so signed-in customers who never open the chat do not fill your inbox.
Before you start
- A published web chat widget, already embedded on your site with its script tag.
- A website with its own sign-in, and server-side code that knows the signed-in user’s e-mail or phone number.
1. Create the identity secret
Open Web Widgets, select your widget and scroll down to Ship it and update it. The Chat Identification card sits next to the embed snippet — click Create secret. The card then walks you through the same three steps as this page, with your secret and copy-ready code. You get a value that starts withwis_. Store it where your server keeps its other secrets (an environment variable, a secrets manager).
2. Add an endpoint that signs the signed-in customer
The hash is the hex HMAC-SHA256 of one identifier, keyed with your identity secret:
Add one small route to your own server. It reads the customer from the current session, signs their e-mail (or phone number) and returns it as JSON.
req.user.phone instead and return it as phone.
3. Pass the identity to the widget
Add this next to the widget’s script tag. It asks your endpoint who is signed in and hands the answer to the widget. It can run as soon as the page loads: calls made before the widget is ready are queued and delivered once it is.fetch again after the customer signs in.
Server-rendered pages
If your server renders the HTML, you can skip the endpoint: compute the hash while rendering and print the values straight into the page for the signed-in customer.
With a phone number instead of an e-mail:
email and phone, Mihu uses the one the hash belongs to; the other is ignored.
The widget sends an identity once per chat, so calling mihu.identify on every page view is fine.
Test it
-
Pick a contact that already exists in Mihu and compute the hash for their e-mail:
-
Open a page with your widget, open the browser console and run:
- Send a message in the chat. In Mihu the conversation appears on that contact.
When the customer signs in during a chat
Callmihu.identify(...) again after sign-in. A running anonymous chat moves to the known contact immediately and keeps its messages.
Security notes
- Sign on the server, per request, for the signed-in user only. Your endpoint takes the customer from the session — never an e-mail or phone number sent by the browser.
- The hash for an e-mail or phone number does not change until you replace the secret. Print it only into pages of the customer it belongs to.
- Replacing the secret is instant and safe: customers are simply anonymous until your server signs with the new one.
- Sites without a sign-in cannot use Chat Identification; their visitors chat anonymously, and the AI agent can still collect a name or an e-mail as ordinary conversation details.