Visitor identity
Link a widget visitor to an account on your website and verify their external ID with a signature.
Main section: Initialization Parameters.
Visitor Data
user contains the data Senler uses to create or update the widget lead. Pass only information about the current visitor that your data-processing policy allows.
| Field | What to pass and how it is used |
|---|---|
external_id |
A stable authenticated-user ID from your system. When it is present, user_hash is required. |
user_hash |
An HMAC-SHA256 signature of external_id, calculated by the site backend with the channel secret and encoded as 64 hexadecimal characters. |
email |
The lead email. A non-empty value is saved on creation and updates an existing lead. |
phone |
Phone number stored in the lead profile’s phone field. A supplied non-empty value updates it; omitting it leaves the stored number unchanged. |
first_name, last_name |
The lead's first and last name. Non-empty values are saved on creation and update. |
avatar_url |
A public HTTPS URL without embedded credentials. An explicitly passed empty, invalid, or local value means no avatar and removes the existing lead's previously saved avatar. |
data |
A plain JSON-compatible object with additional data. On repeat initialization, a non-empty object is shallow-merged into saved data; omitted keys are not deleted. |
Update contact details
When the visitor provides a phone number or email after the widget loads, use updateLead:
await SenlerWidget.updateLead({
phone: "+79990000000",
email: "visitor@example.com",
firstName: "Maria",
});
The method accepts phone, email, firstName, lastName, and avatarUrl. Only supplied fields of the current lead change; the Promise resolves after saving. Omitted fields are retained, and empty values are rejected. This method uses camelCase field names; initialization's user object uses snake_case.
The lead ID comes from the current session. You cannot supply external_id, user_hash, another lead ID, or arbitrary data. The method neither creates a dialog nor switches visitors. To change accounts, sign out and initialize a new instance.
Signing the external ID
Always pass external_id together with user_hash: initialization is rejected without the signature. The cabinet identity-linking switch adds these fields to generated code and exposes the secret and backend examples; it does not enable or disable the verification itself. Never put the secret in HTML, loader configuration, or any other browser code. Linking to an Authorized User shows the complete setup.
For example, a Node.js backend signs the exact external_id value as follows:
import { createHmac } from "node:crypto";
const userHash = createHmac("sha256", channelSecret)
.update(externalId)
.digest("hex");
Send only the externalId and resulting userHash values to the browser as external_id and user_hash. Keep channelSecret on the server.
Credentials are stored separately for each site, channel, and external_id. Reloading restores the same visitor where the browser permits embedded storage. With storage blocked, the session lasts only for the instance. Clearing the stored session also closes other open instances sharing that scope.
Signing out
When a visitor signs out of your website, call await SenlerWidget.resetSession(). The method clears saved widget authentication and destroys the current instance. To continue chatting, initialize a new instance with the next visitor's data, or without external_id for anonymous sign-in.
Chat stops as soon as reset begins. If the browser cannot confirm that saved credentials were cleared, the Promise rejects with session_reset_failed and retryable: true. Keep the current instance, allow browser storage access, and call resetSession() on that instance again. Create the next visitor’s widget only after reset succeeds; chat commands remain stopped during the retry.
This does not delete server-side dialog history or end the website's own session. Ordinary destroy() only removes the instance: use resetSession() to sign out of the widget account.
History and service access
With a signed identity link, history belongs to the same account across devices. Without external_id, Senler creates an anonymous browser session, so previous history is unavailable after switching browser or device.
To avoid assembling user manually, open Code building example in the channel settings. That illustrated guide shows how to select fields, add pairs to user.data, and copy the example. The builder demonstrates the accepted data shape but does not change the channel's primary code.
The user_hash signature verifies the visitor’s identity; the agent’s access to an external service is configured separately. For an installed MCP with per-lead authorization, the backend can save the user token in advance using POST /api/mcp-servers/external-user-credentials. See website user authorization for MCP for the complete sequence, parameters, renewal, and revocation.