Skip to main content

Install in your CRM

The Staff assistant needs three things, plus one call when someone signs out:

Older names

CRMs set up with window.SaarthiStaff and @saarthi/sdk keep working: window.SaarthiStaff is the same object as window.SarthiStaff, and the old package still signs valid tokens. The token's aud stays "saarthi-staff" either way.

  1. In the console: switch it on, list your CRM's addresses and create the staff secret.
  2. On your CRM's server: one route that signs a short staff token for the employee at the keyboard.
  3. In your CRM's pages: one script tag.
Employee's browser ──GET /sarthi-staff-token (your CRM's login)──▶ Your CRM's server
Employee's browser ◀──{ token } signed with your staff secret────── Your CRM's server
Employee's browser ──start the assistant with the token───────────▶ Sarthi
Employee's browser ◀──"Hi Kavya! Ask me about orders…"───────────── Sarthi

Your CRM vouches for who is at the keyboard; your staff list in Sarthi decides what they may read.

1. Switch it on in the console​

Owners and admins, in Staff assistant → Set up. Getting started, at the top of the page, lists seven steps and ticks each one by itself; each step's button takes you to where you do it: Turn the assistant on, Add your CRM website, Create the staff secret, Add the code to your CRM, Make an access group, Add a person and Try it. When all seven are done, the card folds into one line (Show steps opens it again); if a step comes undone, say the assistant is switched off, it opens by itself.

  1. Turn the assistant on (the switch on The assistant). Sarthi makes your staff key, like wst_acme_3f9c1a: the public id your CRM's pages use. It never changes, and it only works from your CRM websites.
  2. Add your CRM websites.
  3. Press Create staff secret and put it on your CRM's server (see the staff secret).
  4. Give your developer the snippets under Add it to your CRM (CRM page, CRM server (Node), Other languages and On sign-out): your staff key and Sarthi's address are already filled in.
  5. Make an access group.
  6. Add the people who may use it, one by one or many at once.
  7. Try it as one of them, before anyone signs in.

Add the code to your CRM ticks when the first employee signs in through your CRM: "Kavya signed in from crm.acme.in, 2 minutes ago". Until then the page checks again every 30 seconds, and if a sign-in was refused, the step says why, with See what's wrong to take you to Last sign-in problem. Since it waits for your developer, it's the step Getting started suggests last. Try it ticks once anyone has used Try as.

The same page sets:

SettingWhat it does
Assistant nameShown at the top of the panel. Unless you choose one (up to 60 characters), it is your workspace's name followed by "assistant", like "Acme Logistics assistant".
GreetingThe first message. Unless you write one (up to 300 characters), it is made from the person's first name and what their group can read. The monitoring notice, "Your questions are visible to Acme Logistics's admins.", is always added after it.
LimitsThe daily credit limits, the daily CSV rows per person, and how long chats are kept. See Activity.

Set up also warns you when databases aren't in your plan (guides still work), or when there's no AI model that writes queries (Sarthi's team sets that up: contact support). A missing CRM website or staff secret shows in Getting started, with a button to each (or as a warning, when your plan doesn't include the Staff assistant and Getting started isn't shown). Until a staff secret exists, the assistant stays off.

CRM websites​

The assistant only starts on the addresses you list, and every request it makes is checked against them:

What you addWhat it allows
https://crm.acme.inExactly that address.
https://crm.acme.in:8443That address, on that port.
http://localhost:3000Your own machine while developing. http:// is only accepted for localhost and 127.0.0.1.

Up to 10 addresses, each one exact: no wildcards (https://*.acme.in is refused, so list each address), and no paths. Your CRM must be served over https://. Changes save as you make them: an address works as soon as you press Add (or Enter). When you remove an address, everyone signed in there is signed out at once. Adding the address back doesn't bring those sign-ins back: people simply sign in again.

The staff secret​

Create staff secret shows the secret, sk_live_staff_…, once. Put it in an environment variable on your CRM's server, for example SARTHI_STAFF_SECRET. Afterwards Set up only shows its last four characters.

The staff secret stays on your CRM's server

Whoever has it can sign in as anyone on your staff list. Never put it in a web page, a mobile app or a repository.

It is not the SDK secret from Widget & SDK, which signs your website's customers in: the two are kept apart on purpose, and each is refused where the other belongs.

2. Add the token route to your CRM's server​

Add one route that only your CRM's signed-in users can reach. It returns a fresh token for whoever is signed in, and the assistant calls it whenever it needs one.

  • Put it behind your CRM's login, and when nobody is signed in, answer 401. The assistant then shows "Sign in to your CRM to use the assistant." and starts nothing.
  • Never add CORS headers to it, so no other website can fetch a token with your employee's login.
  • Sign a new token on every request, and send Cache-Control: no-store: a token works once.

The token​

A JWT, algorithm HS256, signed with your staff secret:

ClaimRequiredRule
user_idyesYour CRM's id for the person: text up to 128 characters, or a whole number (read as text). It must equal the CRM user id on your staff list, exactly: A101 and a101 are two different people.
emailA valid address. Only used to find a listed person who has no CRM user id yet (see Who is signed in). An empty value is ignored.
audyesExactly "saarthi-staff". It marks the token for the Staff assistant. Without it the token is refused, and with it the website chat refuses the token.
iat, expyesIssued-at and expiry, in seconds. At most 15 minutes apart; the examples use 2 minutes.
nonceyesA random id of 16–64 letters, digits, - or _. Each token works once.
name, plan, attrs, anything elseAccepted, and never used for access. The panel shows the name from your staff list.

Examples​

npm install @mysarthi/sdk
server.js (Express)
import { sign } from '@mysarthi/sdk'; // 1.0.0 is enough

// On the CRM's server, behind its own login. Never add CORS headers to this route.
app.get('/sarthi-staff-token', requireCrmLogin, (req, res) => {
const claims = {
user_id: req.user.id, // the id your CRM uses: the same one you put on Sarthi's staff list
email: req.user.email, // optional: finds a listed person who has no CRM user id yet
aud: 'saarthi-staff', // required: marks the token for the Staff assistant
};
res.set('Cache-Control', 'no-store');
res.json({ token: sign(claims, process.env.SARTHI_STAFF_SECRET, { expiresInSeconds: 120 }) });
});

sign() adds iat, exp and the nonce, and keeps aud as it is. The same package signs your website's customer tokens; only the secret and the aud claim differ.

Any other language works the same with its JWT library: sign the claims in the table above with HS256 and your staff secret.

TypeScript​

The SDK's SarthiClaims type has no aud. TypeScript refuses an unknown property only on an object written straight into the call, so build the claims in a variable first, as in the examples, and pass the variable. Don't give that variable the type SarthiClaims.

saarthi-staff-token.ts
import { sign } from '@mysarthi/sdk';

// Works: the claims are a variable, so the extra aud claim passes the type check.
const claims = { user_id: user.id, email: user.email, aud: 'saarthi-staff' };
const token = sign(claims, process.env.SARTHI_STAFF_SECRET!, { expiresInSeconds: 120 });

// Refused by TypeScript: an object literal written straight into the call can't carry aud.
// sign({ user_id: user.id, aud: 'saarthi-staff' }, secret);

Nothing changes at run time: sign() keeps aud either way. No SDK update is needed; version 1.0.0 is enough.

3. Add the script to your CRM pages​

Put this in your CRM's layout, on every page where employees should have the assistant (Add it to your CRM on Set up has it with your staff key):

Your CRM's layout
<script src="https://api.mysarthi.tech/widget/staff-v1.js" async></script>
<script>
window.SarthiStaff = window.SarthiStaff || { q: [] };
window.SarthiStaff.q.push(['init', {
staffKey: 'wst_acme_3f9c1a',
getStaffToken: () => fetch('/sarthi-staff-token', { credentials: 'same-origin' })
.then((r) => r.json()).then((j) => j.token),
}]);
// From your CRM's own log-out, without waiting for it: window.SarthiStaff?.logout?.();
</script>
  • Nothing calls Sarthi until the panel is opened (an inline assistant starts as soon as it appears). A page where nobody opens it costs nothing.
  • q.push works before and after the script has loaded, so the order of the two tags doesn't matter. Other methods queue the same way: window.SarthiStaff.q.push(['open']).
  • getStaffToken must be a function that returns a fresh token (or a Promise of one). The assistant calls it when it starts, after a reload, and before its 30-minute sign-in runs out. A fixed token can't renew.
  • It is a different script from the website chat, and it never touches window.Sarthi: both can be on the same page.

Options​

OptionWhat it does
staffKeyRequired: your staff key, wst_…. Anything else logs a warning in the browser's console, and nothing appears.
getStaffTokenRequired: a function that fetches a fresh token from your CRM's server.
layout'side' (the default): a small tab on the right edge opens a full-height panel over your page, without moving it. 'inline': the assistant fills an element of your page, with no tab, and starts as soon as it appears. On screens up to 480 px wide, both take the whole screen.
containerFor 'inline': the element, or a CSS selector like '#assistant'. Give it a height: the assistant fills it.
launcherFor 'side': false hides the edge tab, when you open the panel from your CRM's own menu with open(). On by default.
theme'light', 'dark' or 'auto' (the employee's device). Defaults to the chat look in Settings → Workspace, or 'light' if you haven't picked one.
apiBaseWhere the assistant talks to Sarthi. Defaults to the address the script was loaded from; you don't normally set it.
testHooksOnly for automated tests on localhost: it is ignored on every other address. Leave it out.

Methods​

MethodWhat it does
open() · close() · toggle()Opens, closes or toggles the panel. Opening starts the assistant if it hasn't started yet.
ask(text)Opens the panel and asks text, for buttons in your CRM like Ask about this order.
setTheme(theme)'light', 'dark' or 'auto', at once, e.g. from your CRM's own dark-mode switch.
logout()Signs the person out of the assistant in every tab of this browser at once, closes the panel, and tells Sarthi in the background. Call it from your CRM's log-out, without waiting for it (below).
destroy()Removes the assistant from the page, without ending the sign-in: for a single-page app leaving its CRM part.
version'1', once the script has loaded.

Open it from your own menu (with launcher: false):

<button onclick="window.SarthiStaff.q.push(['open'])">Ask the assistant</button>

Ask about the record on screen:

<button onclick="window.SarthiStaff.q.push(['ask', 'Shipments of order AC-1042'])">Ask about this order</button>

Inside a page of your CRM (layout: 'inline'):

<div id="assistant" style="height: 640px"></div>
<script>
window.SarthiStaff = window.SarthiStaff || { q: [] };
window.SarthiStaff.q.push(['init', {
staffKey: 'wst_acme_3f9c1a',
getStaffToken: () => fetch('/sarthi-staff-token', { credentials: 'same-origin' })
.then((r) => r.json()).then((j) => j.token),
layout: 'inline',
container: '#assistant',
}]);
</script>

4. Sign out with your CRM​

When someone signs out of your CRM, call logout() before sending them to your sign-in page:

// In your CRM's own log-out. Safe on pages where the assistant didn't load.
window.SarthiStaff?.logout?.();

It wipes the sign-in from this tab at once, and from the person's other tabs in the same browser, then tells Sarthi in the background, so your log-out never waits for it. A sign-in that was still on its way is cancelled. The other tabs also sign out when your log-out clears the browser's local storage. The person's chats stay: they are theirs, and Your chats shows them next time.

This matters most on shared computers and in single-page CRMs, where signing out doesn't reload the page: without logout(), the next person could carry on with the first person's sign-in until it runs out. After a reload, the assistant also compares the person in the fresh token with the one before: when they differ, it wipes the first person's sign-in and chat from the tab instead of continuing them.

How sign-in works​

  1. Nothing starts until it's needed: the panel is opened, your page calls ask(), or an inline assistant appears.
  2. The assistant asks your route for a token and starts a sign-in for this tab. Sarthi checks the signature, that the token is fresh, unused and marked aud: "saarthi-staff", that the page is on one of your CRM websites, and who the person is on your staff list.
  3. A sign-in lasts 30 minutes, however busy. Shortly before it ends, the assistant asks your route for a fresh token and carries on, so your CRM vouches for the person at least every half hour. If your route stops giving a token, for example because they signed out of your CRM, the assistant stops too. A computer whose clock is wrong can't make it sign in over and over: its timed renewals are at least 5 minutes apart.
  4. Every request is checked again: the person, their group, the switch and your plan. When you disable someone or change their group, their sign-ins end at once, and the assistant signs them in again with the new access, or says why it can't. Stopping the old staff secret, or removing a CRM website, also ends the sign-ins it covers at once.

Chats belong to the person, not to the tab or the computer. A new tab in the same browser continues their latest chat, and Your chats lists all of them, wherever they sign in.

What the browser keeps​

KeyWhereHolds
saarthi-staff:<staffKey>:sessionsessionStorage (this tab only; gone when it closes)The sign-in: its id and token, the CRM user id, when it started and when it ends, and the Sarthi address it was made with
saarthi-staff:<staffKey>:opensessionStorageWhether the panel was open
saarthi-staff:<staffKey>:lastlocalStorageThe CRM user id and the latest chat's id: no secret, and useless without a fresh token for that person
saarthi-staff:signed-outlocalStorageA random value that changes at every logout(), so the browser's other tabs sign out too: no secret

Rows are never kept in the browser, in any storage: after a reload, a table shows its summary with Show again. No cookies. If the browser blocks storage, the assistant simply signs in again on every page.

Who is signed in​

The token says who is at the keyboard. Sarthi finds them on your staff list:

  1. A listed person whose CRM user id equals the token's user_id.
  2. If there is none, and the token has an email: a listed person with that email and no CRM user id yet. Sarthi links the token's user_id to them at this first sign-in, and from then on matches them only by their id.
  3. Anyone else isn't on your list, and gets nothing.

A disabled person, or one with no access group, is refused too. A token whose email belongs to someone listed with a different CRM user id is refused ("doesn't match the staff list"), so nobody can sign in as a colleague by changing their own email afterwards.

Prefer CRM user ids

Adding people by email only is handy when you don't have their ids yet. But an employee who can change their own email in your CRM could set it to a colleague's address before that colleague first signs in, and be linked as them. Add the CRM user id when you can: People warns about everyone who has only an email.

Test it​

Set up → Test a staff token. Paste a token your route produced. Sarthi checks it exactly as a sign-in would and shows whether it's valid, its claims, when it expires, which secret signed it, and who it matches, like Ravi Kumar (Leads (own)), or what is wrong. Testing doesn't use the token up and changes nothing: it never links an email-only person.

ProblemWhat to do
Not a tokenPaste the token itself (three parts separated by dots), not the whole JSON your route answers.
Claims missing or invaliduser_id is missing or longer than 128 characters, or email isn't a valid address.
No staff secretCreate one first: Set up → Staff secret.
No aud: "saarthi-staff"Add the claim to what your route signs.
Signed with your website's SDK secretUse the staff secret from Set up, not the SDK secret from Widget & SDK.
Bad signatureA different staff secret (an old one after a rotation, or a copy with a trailing space), or RS256 instead of HS256.
Expired, or not yet validYour server's clock is off: sync it with NTP.
Lives too longexp is more than 15 minutes after iat.
Already usedEach token works once. Sign a new one for every request, and don't cache it.
Not on the staff listAdd the person on People, with this CRM user id.
Disabled, or no groupEnable them, or give them an access group.
Doesn't match the staff listThe email belongs to someone listed with another CRM user id. Check both records.

Then on the page: open your CRM in a private window, sign in as a listed employee and open the panel. You should see the greeting with their first name and their group's starter questions. Sign out of the CRM and in as someone else: the first person's chat must not appear.

When sign-in fails​

The panel never shows technical detail to an employee. Each message comes with Signed in as … and the email from your CRM's token, so they can tell you exactly who they were:

The employee seesWhat happened
"Sign in to your CRM to use the assistant."Your route gave no token: nobody is signed in, or the route failed.
"You're not on Acme Logistics's staff list for the assistant. Ask your admin to add you."Nobody on your list matches the token.
"Your access to the assistant is switched off. Ask your admin."The person is disabled.
"You don't have an access group yet. Ask your admin."The person has no group.
"Your sign-in doesn't match the staff list. Ask your admin."The token's email belongs to someone listed with another CRM user id.
"Couldn't sign you in to the assistant (…). Ask your admin."The token was refused, with the reason in brackets: use Test a staff token.
"The assistant isn't set up for this address. Ask your admin."The page isn't on your CRM websites (or was just removed).
"Your access to the assistant has ended."The person was disabled or removed, or lost their group, while signed in.
"The assistant is switched off right now."The switch is off, or your plan no longer includes the Staff assistant.
"The assistant is paused right now."The workspace is out of credits.

Refused sign-ins whose token was signed with your staff secret (not on the list, disabled, no group, a mismatch, a token used twice) are on Activity → Recent refusals, with Add to the list for someone who isn't on it. Tokens with a bad signature, no aud or an expired time aren't listed there, because anyone can send a broken token. Whatever the reason, the latest refused sign-in shows as Last sign-in problem on Set up, with its fix.

Rotating the staff secret​

Set up → Staff secret → Rotate. The new secret is shown once. The old one keeps working for 24 hours, so you can update your CRM's server without a gap. If the secret leaked, choose Stop the old secret now instead. It also signs everyone out at once; they sign in again as soon as your CRM uses the new secret (until then, they read "Couldn't sign you in to the assistant (bad_signature). Ask your admin.").

Rotating again within those 24 hours stops the oldest secret at once (only two work at a time), so it signs everyone out at once too.

Content Security Policy​

If your CRM sends a Content-Security-Policy, the pages with the assistant need these:

script-src https://api.mysarthi.tech;
connect-src https://api.mysarthi.tech;
style-src 'unsafe-inline';
DirectiveWhy
script-srcThe assistant's script comes from https://api.mysarthi.tech/widget/staff-v1.js.
connect-srcQuestions, answers (streamed back on the same request), more rows and CSV files all travel to and from api.mysarthi.tech over HTTPS. Your token route is on your CRM's own address.
style-src 'unsafe-inline'Like the website chat, the assistant puts its stylesheet in a <style> element inside its own Shadow DOM, which CSP counts as inline.

It needs no frame-src (it isn't an iframe), no fonts and no WebSocket.

Keep it out of session recordings​

Session-recording tools (Hotjar, Microsoft Clarity, FullStory, LogRocket, PostHog, Sentry Session Replay and others) copy what happens on a page so it can be replayed later. On a CRM page, they could copy the rows your employees see.

The assistant draws inside a closed Shadow DOM, which the page's other scripts can't read, so most recorders only see an empty box. But a recorder that hooks in before the assistant loads, or one that records the screen as pictures, can still capture it. So:

  1. Best: don't record the CRM pages where the assistant runs. Most tools can skip pages by address.

  2. If you must record them, use the inline layout, and put your tool's "don't record" marker on its container, so the whole area is left out:

    ToolOn the container
    Hotjardata-hj-suppress
    Microsoft Claritydata-clarity-mask="True"
    FullStoryclass="fs-exclude"
    LogRocketdata-private
    PostHogclass="ph-no-capture"
    Sentry Session Replayclass="sentry-block"
    Datadog Session Replaydata-dd-privacy="hidden"
    <div id="assistant" class="fs-exclude" data-hj-suppress style="height: 640px"></div>

    For any other tool, look for its setting to block, exclude or hide an element.

  3. Check a recording of such a page afterwards: the assistant's area should be blank or blocked out.

Good to know​

  • Your CRM is trusted. Whoever controls your CRM's server, or holds the staff secret, decides who is at the keyboard. Keep the token route behind your CRM's login; if you suspect a leak, rotate with Stop the old secret now: it also signs everyone out at once.
  • Scripts on your CRM pages run alongside the assistant. A script injected into a CRM page could use the assistant as the employee who is signed in, within their group. The closed panel, tab-only 30-minute sign-ins, the address checks, rate limits, daily limits and Activity limit the damage, but can't prevent it: keep third-party scripts off the pages with the assistant.
  • Screens can be copied. Turning CSV off stops files, not screenshots: give each group only the columns its people may see. See Access groups.