# Getting started
# Install
npm install --save smartsupp-websocket
yarn add smartsupp-websocket
We use socket.io (opens new window) as websocket engine.
# Setup
Create visitor client with your SMARTSUPP_ACCOUNT_KEY. You can find this key in smartsupp guides "Insert chat code to website".
import { createVisitorClient } from 'smartsupp-websocket'
const client = createVisitorClient({
data: {
id: null, // or id returned from server
key: '__SMARTSUPP_ACCOUNT_KEY__',
// ...
},
})
When your client is connecting from non-browser environment you must setup extra headers:
const client = createVisitorClient({
connection: {
options: {
extraHeaders: {
'user-agent': '<user_agent_of_visitor>',
'x-forwarded-for': '<ip_of_visitor>',
},
},
},
})
When client is initialized you can connect to server
websocketClient.connect().then((data) => {
console.log(data)
}).catch((err) => {
console.log(err)
})
# Options
Required:
keySmartsupp account key to identify account.idVisitor id, defaultnulland should be set by last connect data.visitsNum of visits, default isnulland should by last connect data.
Optional user info:
nameName of visitor, maximum length of 255 chars.emailEmail of visitor, maximum length of 255 chars, must be matchable by client.EMAIL_REGEX.phonePhone of visitor, maximum length of 50 chars.langUser language, if omitted detected automatically.groupGroup of visitor, must be created in smartsupp settings, defaultnull.variablesAdditional data (context) related to chat (Key-value object). Values will be displayed in dashboard for agents.
Optional browsing info:
pageUrlPage url, defaultwindow.document.location.toString()pageTitlePage title, defaultwindow.document.titlerefererPage referer, defaultwindow.document.referrerdomainPage domain, defaultwindow.document.domain