npm package
orka-web-sdk, MIT, no dependency.
For React, Vue, Angular, Svelte and any bundled app. The package injects the same script as the HTML snippet, do not use both.
npm install orka-web-sdk
import Orka from "orka-web-sdk";
Orka.configure("YOUR_PROJECT_ID");
Orka is a default export, and a singleton: import it from any file, it is the same instance.
configure
Orka.configure("YOUR_PROJECT_ID", { autoload: false });
| Option | Type | Default | Description |
|---|---|---|---|
autoload |
boolean | true |
false does not inject the script. Call Orka.load() when you want the chat. |
locale |
string | browser | Forces the widget language, like ORKA_LOCALE. See Language. |
Call configure once, in the browser. With server-side rendering (Next.js, Nuxt, Remix), call it in an effect or a client-only component: the package needs window.
React
import Orka from "orka-web-sdk";
import { useEffect } from "react";
Orka.configure("YOUR_PROJECT_ID");
export function useOrkaIdentity(user) {
useEffect(() => {
if (user) {
Orka.update({ name: user.name, email: user.email, plan: user.plan });
}
}, [user?.email, user?.plan]);
}
// On logout
export function logout() {
Orka.reset();
// …your own logout
}
Vue
// main.js
import Orka from "orka-web-sdk";
Orka.configure("YOUR_PROJECT_ID");
app.config.globalProperties.$orka = Orka;
Methods and events
Every method of SDK methods is on the imported Orka: update(), reset(), show(message?), hide(), toggle(), showWidget(), hideWidget(), destroy(), load(), on(), off(), track(), and the getters isReady(), isOpen(), isOnline(), getUnreadCount().
- Every call is safe right after
configure(): the calls made before the script is loaded are queued and run in order once it is,update()included. - The getters return
false(and0forgetUnreadCount()) until the widget is ready. - TypeScript types ship with the package: the events and their arguments are typed.
Orka.configure("YOUR_PROJECT_ID");
Orka.on("unread:change", (count) => setBadge(count));
// conversation_id: null until the visitor writes, then given by "session:change"
Orka.on("session:change", ({ conversation_id }) => saveNextToUser(conversation_id));
Version 1 of the package (1.0.x) forwards update(), reset(), toggle(), show(), hide(), destroy() and load() only, and its calls other than update() need the script to be loaded. Upgrade to 2.x, nothing else changes.
Page changes of your router are tracked automatically, there is nothing to wire.