Website widget
The widget is a support launcher for your own websites. Visitors search your knowledge base and contact your team without leaving the page. It has two modes:
- Tickets: each new message opens a ticket. Your team answers in the inbox when it can, not in real time, and the visitor reads the reply in the widget (and by email, if you turn that on).
- Chat: live chat while an agent is Online in the admin. When nobody is online, or outside the office hours you set, visitors leave a message, which arrives as a ticket. Visitors don’t need an email or name for their first message. Afterwards, if replies are emailed, anonymous visitors are offered “Get replies by email”.
The same widget is behind the mobile SDKs.
Turn it on
Section titled “Turn it on”In the Motenya admin, open Tickets → Widget. Ticketing must be on for the product. Set:
- Allowed websites: the origins the widget may run on, such as
https://www.example.com. Give each one as scheme, host and, if needed, port, without a path. The widget doesn’t start on any other site. Addhttp://localhost:3000(or your dev server’s port) to test locally. Up to 20 websites. - What it offers: Tickets or Chat. For Chat you can limit live chat to office hours in a time zone.
- What customers can do: whether they may mark their own tickets solved.
- Email replies: whether replies to tickets and chats opened in the widget or the portal are also emailed. Off by default: visitors read replies when they come back to your site, and the widget doesn’t ask for an email to send them to. Mobile apps have their own switch (Tickets → Mobile apps). Emailed tickets and the knowledge base’s support section always get replies by email.
Once it is on, the page shows the code to embed, with your widget id in it. Once a visitor has opened the widget on one of your sites, the admin shows it as installed, with the site and time.
What lives where
Section titled “What lives where”- The admin sets the widget’s behaviour, and changes take effect on every site at once: on or off, the allowed websites, tickets or chat, office hours, identity verification, what customers may do, and your mobile apps with their push notifications and emailed replies.
- Your site’s code sets the look and feel: the accent colour, the launcher, article suggestions, the support portal’s layout, the language and wording, and your CSS. The admin’s Install it section (titled Installation & Configuration once the widget has loaded on a site) helps you choose them: pick the floating widget or the support portal, make your choices on the left, and the code beside them updates as you go. Copy the code yourself (Add the code), or copy a prompt for your coding agent (AI agent) that adds it for you. Save choices only keeps them for next time. A site changes when you replace its code.
Install
Section titled “Install”Paste the code from Tickets → Widget → Install it → Add the code just before </body> on every page where the widget should appear. It is a single <script> tag with your options as data-* attributes:
<script data-motenya-snippet data-widget-id="YOUR_WIDGET_ID" data-loader="https://widget.motenya.app/loader.js" data-position="bottom-right" data-color="#4f46e5"> /* a short inline script: copy it from the admin as it is */</script>Copy it from the admin rather than typing it: the inline part is generated there, and your widget id is already in it.
Privacy: nothing loads until it is opened
Section titled “Privacy: nothing loads until it is opened”The code draws the launcher button itself. Until a visitor opens the widget, nothing is requested from Motenya: no script, no API call, no cookie, so the visitor’s browser sends Motenya nothing, not even its IP address. The widget loads only when the visitor:
- clicks the launcher, or
- clicks one of your own elements marked
data-motenya-open(see Your own button or menu link), or - your page calls
Motenya('open')orMotenya('mount', …).
That first open stores a flag in the browser’s local storage, under motenya:widget:<widget id>:consent. On later visits the widget loads straight away, so the launcher can show the number of unread replies. Removing that key, for example from your own cookie or privacy settings, returns the visitor to the “nothing loads until opened” state. The widget itself uses no cookies, unless you turn on data-cookie-domain.
Calls such as Motenya('identify', { jwt }) or Motenya('setLanguage', 'ro') made before the widget has loaded are kept and run once it loads. They don’t make it load.
Google Tag Manager
Section titled “Google Tag Manager”Add a Custom HTML tag, paste the code as it is, and fire it on All Pages. To sign users in, add another Custom HTML tag that reads the token your site puts in the data layer and calls Motenya('identify', { jwt }) (see Identity verification).
Content Security Policy
Section titled “Content Security Policy”If your site sends a Content Security Policy (a Content-Security-Policy header, or a <meta http-equiv> tag), add the widget’s sources to it. The admin shows the exact lines for your code under Install it → Add the code → Your site uses a Content Security Policy?. Merge each one into your existing directive of the same name; don’t add a second directive.
| Directive | Add | Why |
|---|---|---|
script-src |
https://widget.motenya.app and the inline script’s hash, 'sha256-…' (or your nonce, see below) |
The embed code is an inline script. On the first open it adds the loader, and the loader adds the widget’s script, both from widget.motenya.app. |
connect-src |
https://widget.motenya.app wss://widget.motenya.app |
The widget’s API, and the WebSocket that live chat uses for replies and typing. |
img-src |
the origin of your data-icon image, if it is on another origin |
Only when you use your own launcher icon. |
Nothing else is needed:
- Styles: the widget’s styles are constructable stylesheets inside its shadow root, which
style-srcdoesn’t govern, so you don’t need'unsafe-inline'. The embed code’s launcher is styled from script, whichstyle-srcdoesn’t restrict either. - Fonts, frames, workers: the widget loads no fonts, no third-party frames and no workers. Replies sent as HTML email are shown in a sandboxed
srcdocframe, which inherits your policy: images and inline styles inside such a reply follow yourimg-srcandstyle-src, so a strict policy can show it plainer. If your policy uses Trusted Types (require-trusted-types-for 'script'), those HTML replies can’t be shown.
For example, a policy that already allowed only your own origin becomes:
Content-Security-Policy: default-src 'self'; script-src 'self' https://widget.motenya.app 'sha256-YOUR_HASH_FROM_THE_ADMIN'; connect-src 'self' https://widget.motenya.app wss://widget.motenya.appThe hash, or a nonce
Section titled “The hash, or a nonce”The hash covers exactly the text of the inline script you pasted. It stays valid as long as that text is unchanged, so you only need to update it when you paste a newer version of the code from the admin. Compute it yourself with:
printf '%s' 'THE TEXT BETWEEN <script …> AND </script>' | openssl dgst -sha256 -binary | openssl base64If your site already uses nonces, put your nonce on the code’s tag (<script nonce="…" data-motenya-snippet …>) instead of using the hash. With 'strict-dynamic' in your script-src, the loader and the widget’s script are trusted because the inline script adds them. Without it, keep https://widget.motenya.app in script-src.
On the test environment, the widget’s host is widget.motenya.ro: use it in place of widget.motenya.app everywhere above.
The launcher
Section titled “The launcher”The launcher and the widget’s colour are set through the code’s attributes:
| Attribute | Default | What it does |
|---|---|---|
data-position |
bottom-right |
bottom-right or bottom-left. |
data-offset-x |
20 |
Distance in pixels from the side of the window. |
data-offset-y |
20 |
Distance in pixels from the bottom of the window. Raise it to clear a cookie bar or your own floating button. |
data-icon |
a chat bubble | URL (http or https) of an image shown in the launcher instead, at 32 × 32 px. |
data-color |
#4f46e5 |
The accent colour, as #rrggbb: the launcher, buttons, links and the active tab, in the floating widget and the portal. The widget works out readable text on it. CSS variables win over it. |
data-suggest-articles |
false turns off help-article suggestions on the new-request form, in the floating widget and the portal. |
|
data-label |
“Help” (or “Ajutor”) | The launcher’s accessible name, read by screen readers. |
data-launcher |
none hides the launcher: open the widget from your own button or menu instead. |
For example, a launcher in the bottom-left corner, 32 px from the edges, with your own icon:
<script data-motenya-snippet data-widget-id="YOUR_WIDGET_ID" data-loader="https://widget.motenya.app/loader.js" data-position="bottom-left" data-offset-x="32" data-offset-y="32" data-icon="https://www.example.com/help.svg"> /* … */</script>The panel opens above the launcher, on the same side.
Your own button or menu link
Section titled “Your own button or menu link”Add data-motenya-open to any element, and clicking it opens the widget. It works whether or not the widget has loaded yet:
<a href="#" data-motenya-open>Help & support</a>To use only your own element, add data-launcher="none" to the code: there is then no floating button at all. You can also call Motenya('open') from your own code, for example from a menu that is built in JavaScript.
Unread replies
Section titled “Unread replies”The launcher shows the number of replies the visitor hasn’t read yet. To show the count in your own button or menu, mark an element with data-motenya-unread. The widget fills it with the number, and hides it while there is nothing unread:
<a href="#" data-motenya-open> Support <span class="badge" data-motenya-unread hidden></span></a>The count appears once the widget has loaded: on the first open, then on every visit after it.
Styling
Section titled “Styling”The widget renders in a shadow root, so your site’s CSS can’t break it, and ordinary selectors can’t reach inside it either. You can still restyle it in two ways, from a CSS block anywhere on your page. Your styles win over the code’s data-color.
Colours, fonts and corners: CSS variables
Section titled “Colours, fonts and corners: CSS variables”Set --motenya-* custom properties on :root to theme everything, or on the portal’s or panel’s container to theme just that one. They pass into the widget.
:root { --motenya-accent: #0f766e; /* buttons, active tab, links; wins over data-color */ --motenya-on-accent: #ffffff; /* text and icons on the accent */ --motenya-accent-text: #0f766e; /* the accent as text (links, active tab); defaults to --motenya-accent */ --motenya-text: #1f2937; --motenya-text-muted: #6b7280; --motenya-background: #ffffff; --motenya-surface: #f3f4f6; /* subtle fills: the tab switch, empty states */ --motenya-border: #e5e7eb; --motenya-danger: #b91c1c; --motenya-radius: 8px; --motenya-font: Inter, system-ui, sans-serif; /* the font must be loaded by your page */ --motenya-font-size: 15px;}When you change --motenya-accent, check the contrast of --motenya-on-accent and --motenya-accent-text too. The widget works those out for data-color, but not for the CSS variable.
Anything else: ::part()
Section titled “Anything else: ::part()”Key elements carry a part name. Style them with ::part() on the widget’s host element: #motenya-widget for the floating widget, [data-motenya-inline="portal"] for the support portal, [data-motenya-inline="panel"] for the inline panel.
[data-motenya-inline="portal"]::part(tab-active) { background: #0f766e; color: #fff; }[data-motenya-inline="portal"]::part(table) { font-size: 13px; }[data-motenya-inline="portal"]::part(row):hover { background: #f0fdfa; }#motenya-widget::part(launcher) { width: 64px; height: 64px; }#motenya-widget::part(header) { padding: 16px 24px; }| Part | Element |
|---|---|
launcher, panel, header |
The floating launcher, the panel and its coloured header |
tabs, tab, tab-active, tab-count |
Tab bars, each tab, the selected tab, the portal’s closed count |
button, button-primary, button-secondary, send-button |
Buttons (each has button plus its kind) |
input |
Text fields and text areas |
link, back-link |
Text links, and the portal’s “Back to tickets” link |
portal, portal-bar, table, ticket-list, row, ticket-link |
The portal, its top bar, the ticket table (table layout) or list (list and help-center layouts), a row, a ticket’s subject |
article-search, suggestions |
The help-article search, and the suggested articles under a new request’s subject |
chip, chip-open, chip-pending, chip-solved, chip-closed |
Status labels |
message, message-team, message-customer, bubble |
A message in a thread or chat, and its bubble |
::part() takes pseudo-classes such as :hover and :focus-visible, but not descendant selectors: ::part(row) td doesn’t match. Other element names may change between versions. Part names are kept stable.
Remembering visitors
Section titled “Remembering visitors”A visitor who sends a request without being signed in gets a random token. The widget keeps it in the browser’s local storage, under motenya:widget:<widget id>:visitor, and uses it to show them their requests and replies. Every tab and window on your site shares it, and it survives closing the browser. Motenya stores only a hash of it. It stops working after 180 days without use.
A visitor can always choose Not you? in their list of requests to forget it, and Motenya('logout') forgets it too.
Sharing visitors across subdomains
Section titled “Sharing visitors across subdomains”Local storage belongs to one exact origin: www.example.com and app.example.com each see a different visitor. To share visitors across your subdomains, add data-cookie-domain to the code, with a domain that covers them:
<script data-motenya-snippet data-widget-id="YOUR_WIDGET_ID" data-loader="https://widget.motenya.app/loader.js" data-cookie-domain=".example.com"> /* … */</script>The widget then keeps the visitor’s token, their signed-in session and their last chat in first-party cookies on that domain:
- Cookie settings:
Path=/,SameSite=Lax, andSecureover https. They are renewed for 180 days on each visit. - Existing visitors: a token already in local storage moves into the cookie, so visitors keep their requests.
- Wrong domain: if the domain doesn’t cover the page, the widget says so in the browser console and keeps using local storage.
Before you turn it on:
- Allowed websites: add every subdomain that shows the widget to the widget’s allowed websites in the admin.
- Cookie policy: these are functional cookies set on your domain, so list them in your cookie policy. Their names start with
motenya.widget.. - Readable by your page: like local storage, the cookies are readable by scripts on your pages, because the widget reads them itself. They are never sent to Motenya as cookies. The widget sends the token in a request header.
When visitors sign in
Section titled “When visitors sign in”Requests are filed under the email the visitor gave, in the form or later in a chat. When you sign them in with identity verification as that email, they see all of those requests in the widget, along with any they sent by email. A chat started without an email stays with the browser that started it.
Page API
Section titled “Page API”Every call works before the widget has loaded and after, in either style: Motenya('open') or Motenya.open(). The exception is setMessages: before the widget loads, use the Motenya('setMessages', …) style.
| Call | What it does |
|---|---|
Motenya('open') |
Open the panel. |
Motenya('close') |
Close it. |
Motenya('setLanguage', 'ro') |
Set the widget’s language. Without it, the widget uses the browser’s language, then the knowledge base’s default. See Languages and your own wording. |
Motenya('setMessages', { ro: { newRequest: 'Tichet nou' } }) |
Replace any of the widget’s text, in any language. See Languages and your own wording. |
Motenya('identify', { jwt }) |
Sign the visitor in with a JWT from your server. See Identity verification. |
Motenya('logout') |
End the session and forget this browser’s requests. |
Motenya('mount', '#help') |
Render the panel inline in that element. |
Motenya('mount', '#support', { view: 'portal' }) |
Render the support portal in that element. See Support portal. |
Motenya('unmount') |
Remove the inline panel and the support portal. |
A refused call, such as an invalid token, is a warning in the browser console.
Languages and your own wording
Section titled “Languages and your own wording”The widget speaks English and Romanian. It picks the first language it speaks from:
- the language your page sets with
Motenya('setLanguage', 'ro'), - the visitor’s browser languages, in order,
- your knowledge base’s default language.
Otherwise it uses English. Only the base code counts, so ro-RO is ro. The widget loads the text for a language only when it needs it.
To change any wording, give your own text by language with setMessages. Your text replaces the widget’s for those keys only; everything else stays as it was:
<script> Motenya('setMessages', { en: { newRequest: 'Open a ticket', yourTickets: 'Support history' }, ro: { newRequest: 'Deschide un tichet' }, });</script>- Keys. The keys are listed under All keys below. A key the widget doesn’t know is ignored, with a warning in the browser console.
- Values. Some text has values in braces, such as
Remove {name}orRequest #{number}. Keep the braces and their names; the widget fills them in. Text is plain text, up to 1,000 characters, never HTML. - Counts. Text with a count has a form for each plural category of the language, such as
resultCount_oneandresultCount_otherin English, orresultCount_one,resultCount_fewandresultCount_otherin Romanian. A form you leave out falls back to_other. - Other languages. More languages are on the way. Until yours ships, you can add it yourself: text for a language the widget doesn’t speak makes it speak that language. Keys you don’t give show in English. For example,
Motenya('setLanguage', 'de')withMotenya('setMessages', { de: { … } })gives a German widget. Once we ship that language, our text fills the keys you didn’t give, and your text still wins for the keys you did. - When. Call it before or after the widget loads; the change shows at once. Later calls add to earlier ones, key by key.
All keys
Section titled “All keys”Every key, with its English text
| Key | English |
|---|---|
open |
Open help |
close |
Close |
back |
Back |
contactUs |
Contact us |
homeTitle |
How can we help? |
stillNeedHelp |
Still need help? |
contactHint |
Send us a message and we’ll get back to you. |
searchLabel |
Search the help center |
searchPlaceholder |
Search for answers |
searchHint |
Type a question or a few words. |
searching |
Searching… |
resultCount_one |
{count} article |
resultCount_other |
{count} articles |
noResults |
No articles match “{query}”. |
resultsLabel |
Articles |
opensInNewTab |
(opens in a new tab) |
searchFailed |
Search isn’t working right now. Try again in a moment. |
searchRateLimited |
Too many searches. Wait a minute, then try again. |
retry |
Try again |
email |
|
name |
Name |
subject |
Subject |
message |
Message |
send |
Send |
sending |
Sending… |
requestNumber |
Request #{number} |
requestRateLimited |
Too many requests. Wait a minute, then try again. |
requestFailed |
Your request couldn’t be sent. Try again in a moment. |
problemEmail |
Check the email address. |
problemName |
Enter your name (up to 100 characters). |
problemSubjectEmpty |
Enter a subject. |
problemSubjectTooLong |
The subject is too long. |
problemBodyEmpty |
Write your message. |
problemBodyTooLong |
The message is too long. |
problemFile |
A file couldn’t be attached. Remove it and try again. |
problemForm |
Something in the form isn’t right. Check it and try again. |
yourRequests |
Your requests |
newRequest |
New request |
noRequests |
No requests from this browser yet. |
allRequests |
See all your requests |
requestsFailed |
Your requests couldn’t be loaded. Try again in a moment. |
requestNotFound |
This request isn’t available. |
loading |
Loading… |
notYou |
Not you? |
you |
You |
emailMessage |
Email message |
statusOpen |
Open |
statusPending |
Awaiting your reply |
statusSolved |
Solved |
statusClosed |
Closed |
openUnread_one |
Open help ({count} new reply) |
openUnread_other |
Open help ({count} new replies) |
yourReply |
Your reply |
sendReply |
Send reply |
markSolved |
Mark as solved |
markedSolved |
Marked as solved |
solvedNote |
Need anything else? Reply to it and it opens again. |
replyRateLimited |
Too many messages. Wait a minute, then try again. |
actionFailed |
That didn’t go through. Try again in a moment. |
replyBodyEmpty |
Write your reply or attach a file. |
replyBodyTooLong |
The reply is too long. |
replyInvalid |
Something in the reply isn’t right. Check it and try again. |
attachFiles |
Attach files |
removeFile |
Remove {name} |
uploading |
Uploading… |
fileTooLarge |
Larger than 25 MB |
tooManyFiles |
Up to 10 files per message |
uploadRateLimited |
Too many uploads. Wait a minute, then try again. |
uploadFailed |
Couldn’t upload. Remove it and try again. |
download |
Download {name} |
downloadFailed |
The file couldn’t be downloaded. Try again in a moment. |
chatTab |
Chat |
helpTab |
Help articles |
online |
We’re online |
away |
We’re away — leave a message |
backAt |
Back {weekday} at {time} |
backAtZone |
Back {weekday} at {time} ({timezone} time) |
chatIntro |
Ask us anything, we’ll answer right here. |
chatIntroAway |
Leave a message and we’ll reply here or by email. |
chatIntroAwayHere |
Leave a message and we’ll reply here. |
chatMessage |
Write a message |
typing |
{name} is typing… |
emailPromptTitle |
Get replies by email |
emailPromptLive |
In case you leave before we answer. |
emailPromptAway |
Nobody’s online right now. Leave your email and we’ll reply by email. |
save |
Save |
notNow |
Not now |
emailSaved |
Thanks, we’ll also send replies to your email. |
newConversation |
New conversation |
yourConversations |
Your conversations |
conversationFailed |
This conversation couldn’t be loaded. Try again in a moment. |
openRequests |
Your open tickets |
viewClosed |
View closed tickets ({count}) |
closedRequests |
Closed tickets |
noClosedRequests |
No closed tickets. |
supportTitle |
Support |
activeTab |
Open and recent |
closedTab |
Closed |
closedTabCount |
Closed ({count}) |
noActiveRequests |
You have no open tickets. |
guestTickets |
Your tickets show here once you’re signed in. You can still send a new request. |
columnNumber |
No. |
columnSubject |
Subject |
columnStatus |
Status |
columnUpdated |
Last update |
loadMore |
Load more |
backToTickets |
Back to tickets |
requestReceived |
Request received |
requestReceivedNote |
We’ll reply by email. |
requestReceivedNoteHere |
We’ll reply here. Come back to this page to read it. |
anotherRequest |
Send another request |
suggestionsTitle |
These articles might help |
suggestionsAnswered |
This answered my question |
yourTickets |
Your tickets |
Inline panel
Section titled “Inline panel”Motenya('mount', '#help') (or Motenya.mount(element)) renders the panel inside that element instead of floating. Pass a CSS selector or the element itself. The panel fills the element’s width and height, with no launcher and no close button, and is at least 420 px tall, so give the element a height. The floating launcher is hidden while the panel is mounted. Calling mount again moves the panel. Motenya('unmount') removes it, and the launcher comes back.
<div id="help" style="height: 640px"></div><script>Motenya('mount', '#help')</script>Support portal
Section titled “Support portal”The support portal is a full-width page of the user’s tickets, for a “Support” or “Help” page inside your app. Use it instead of the panel, or as well as it.
<!-- Where the portal should appear --><div id="support"></div>
<!-- After the embed code --><script> Motenya('identify', { jwt: '<signed by your server>' }) Motenya('mount', '#support', { view: 'portal' })</script>The calls need the embed code to have run first, so put them after it. In a single-page app, call mount when the support page shows and Motenya('unmount') when it goes.
Signed-in users see a table of their tickets: number, subject, status and last update. It has two tabs:
- Open and recent: open tickets, and those closed in the last 7 days.
- Closed: every closed ticket, with the count on the tab.
Each tab loads 25 tickets at a time, with Load more. A row opens the ticket’s thread in place, where the user can reply, attach files and mark it solved. New request opens the form, and a sent request opens its thread. The table and an open thread refresh every 30 seconds.
Anyone not signed in sees the tickets view with no tickets, a note that their tickets show once they’re signed in, and New request. The form asks for their email and name, and then shows a confirmation. Sign your users in with identify to show them their tickets. While identify is on its way, the portal shows a spinner. If you call identify a moment after mounting, for example once your page has fetched the JWT, the tickets load in place.
The portal renders at the element’s width and grows with its content, so the page scrolls, not the portal. Below 560 px wide it hides the number and date columns. It follows setLanguage, the code’s data-color and logout.
The portal’s look is set in its mount code. In the admin, choose Support portal under Install it: step 1 is the embed code and step 2 the mount code, written with your choices. Your page needs both. There are three layouts:
- Table: tickets in columns (number, subject, status, last update). On a narrow screen each row stacks into two lines.
- List: tickets as rows, with the number and date under the subject.
- Help center: a help-article search on top, then the tickets as rows.
Every layout adapts to the portal’s width. It’s compact on phones and in sidebars, and roomier on wide screens, where article snippets get a second line. With article suggestions on (the default), up to three matching help articles appear under the subject while a user writes a new request. “This answered my question” takes them back to their tickets. The same suggestions appear in the floating panel’s form.
Whether users can mark a ticket solved is not an option: your team sets it in the admin (Tickets → Widget → Settings → What customers can do), and it applies to the floating widget, the portal and the mobile apps alike.
Options go in the third argument. An option you leave out, or a malformed one, takes its default.
| Option | Default | What it does |
|---|---|---|
layout |
'table' |
'table', 'list' or 'help-center'. |
closedWithinDays |
7 |
How many days a closed ticket stays in the first tab (1–90). |
closedTab |
true |
false hides the Closed tab. |
suggestArticles |
the embed code’s data-suggest-articles, else true |
false turns off article suggestions on the portal’s new-request form. |
route |
'none' |
'hash' keeps the portal’s place in the URL fragment: #support/12 for a ticket, #support/closed, #support/new, and nothing for the first tab. Links to these work, and so do the back and forward buttons. Other fragments of your page are left alone. Leave it off if your app uses hash routing itself. |
keepLauncher |
false |
true keeps the floating launcher on the page next to the portal, for example to keep live chat one click away. By default the launcher hides while the portal is mounted. |
Motenya('mount', '#support', { view: 'portal', layout: 'list', closedWithinDays: 14, route: 'hash', keepLauncher: true })Floating widget for guests, portal for signed-in users
Section titled “Floating widget for guests, portal for signed-in users”The floating widget and the portal can share one site. A common setup:
- Guests get the floating widget. The embed code is on every page, and they send requests or chat from the corner.
- Signed-in users are signed in with
identifyon every page. On your support page they get the portal with all their tickets.
<!-- Every page: the embed code (from the admin), then --><script> // Only when a user is signed in (the JWT comes from your server): Motenya('identify', { jwt: jwtFromYourServer })</script>
<!-- The support page, for signed-in users --><div id="support"></div><script>Motenya('mount', '#support', { view: 'portal' })</script>- The launcher for signed-in users. While the portal is mounted, the floating launcher hides. On other pages it stays and shows the user’s own tickets. To give signed-in users only the portal, have your server render the embed code with
data-launcher="none"when someone is signed in. You can still open the panel from your own button withdata-motenya-open. The attribute is read when the page loads, so in a single-page app it changes on the next full page load. - Requests made as a guest. A request sent with an email is kept under that email. When the same person later signs in with a JWT that includes that
email, the portal lists those requests too. A JWT with onlyuser_iddoesn’t link them. An anonymous chat where the guest never gave an email stays with that browser. - Signing out. Call
Motenya('logout')when the user signs out of your site. The widget keeps the signed-in session in the browser, so without it the next guest on that browser would see the previous user’s tickets. - Privacy. For guests, the embed code loads nothing until the widget is first opened. The portal page loads the widget right away.
Identity verification
Section titled “Identity verification”Without it, visitors are anonymous. They give an email with their first request, and they see only the requests made in this browser. If you sign your logged-in users in, they skip the email step and see all of their requests, whichever device they made them on.
The identity secret
Section titled “The identity secret”In Tickets → Widget → Install it, under Identity verification, choose Generate secret. The secret is shown once: store it on your server, like a password, and never put it in the page or in an app. Rotate secret replaces it. The old secret stops working at once, and signed-in visitors are signed out until your site signs them with the new one.
Sign a JWT on your server
Section titled “Sign a JWT on your server”For the signed-in user, sign a JWT with HS256 and the identity secret. Other algorithms are refused. Claims:
| Claim | |
|---|---|
user_id |
Your id for the user, as text, at most 128 characters. A number is read as its digits. |
email |
The user’s email. |
name |
Optional. Shown to your team. |
exp |
Optional, but recommended: the expiry, in Unix seconds. |
Give user_id, email, or both:
user_idonly: the user is recognised by your id. They get replies in the widget, not by email.emailonly: the user is recognised by email.- Both: they must stay paired, with the same
user_idalways with the same email. A token that pairs an id with a different email than the one on file is refused withIDENTITY_MISMATCH. A known id with no email yet takes the email, and a known email with no id yet takes the id.
exp, nbf and iat allow 60 seconds of clock skew.
Node, with jose:
import { SignJWT } from 'jose'
const secret = new TextEncoder().encode(process.env.MOTENYA_WIDGET_SECRET)const jwt = await new SignJWT({ user_id: String(user.id), email: user.email, name: user.name }) .setProtectedHeader({ alg: 'HS256', typ: 'JWT' }) .setExpirationTime('1h') .sign(secret)PHP, with firebase/php-jwt:
use Firebase\JWT\JWT;
$jwt = JWT::encode([ 'user_id' => (string) $user->id, 'email' => $user->email, 'name' => $user->name, 'exp' => time() + 3600,], getenv('MOTENYA_WIDGET_SECRET'), 'HS256');Python, with PyJWT:
import os, time, jwt
token = jwt.encode( {"user_id": str(user.id), "email": user.email, "name": user.name, "exp": int(time.time()) + 3600}, os.environ["MOTENYA_WIDGET_SECRET"], algorithm="HS256",)Sign in on the page
Section titled “Sign in on the page”Render the token into the page for the signed-in user, then call identify after the embed snippet:
Motenya('identify', { jwt })Sign out
Section titled “Sign out”When the user signs out of your site, call:
Motenya('logout')That way the next person on the same computer doesn’t see their requests.
The earlier email signature
Section titled “The earlier email signature”Sites that adopted the first version still work. It signs an email instead of a JWT:
// signature = hex(HMAC-SHA256(secret, "v1:" + timestamp + ":" + lowercase(email)))Motenya('identify', { email, name, timestamp, signature })timestamp is in Unix seconds and must be within 10 minutes of the current time. New integrations should use the JWT.