Headless web SDK API reference

This page lists the API methods available for the headless web SDK.

getTrigger

This method detects the current page's proactive triggers. It will return either the current matched trigger or null.

const trigger = await client.getTrigger()

getCompany

This method retrieves the company information.

const company = await client.getCompany()
interface CompanyResponse {
  name: string;
  subdomain: string;
  support_email: string;
  languages: LanguageOption[];
  action_tracking: boolean;
  email_transcripts: boolean;
  message_preview: boolean;
  email_enhancement: boolean;
}

getAfterHourMessage

This method fetches the message for after hour deflection.

Request parameter:

(lang?: string)

Example:

const message: string = await client.getAfterHourMessage()

getMenus

This method lists all menu items available for the tenant.

Request parameter:

(key?: string, lang?: string)

Example:

const data = await client.getMenus("direct_menu_key")
console.log(data.menus)
console.log(data.direct

Response data:

interface MenuItem {
  id: number;
  name?: string;
  enabled: boolean;
  redirection?: {
    option: string;
    data: string;
  };
  children?: MenuItem[];
  channels: MenuChannel[];
  deflection?: {
    enabled: boolean;
    type: string;
  };
}
interface MenuResponse {
  menus: MenuItem[];
  direct: {
    key: boolean;
    user: boolean;
  };

getTimeSlots

This method fetches available time slots for scheduled calls.

Request parameter:

(menuId: number | string, lang: string = 'en')

Example:

const slots = await client.getTimeSlots(123)

Response data example:

[
  "2023-05-31 11:45 +0000",
  "2023-05-31 12:00 +0000",
  "2023-05-31 12:15 +0000",
  "2023-05-31 12:30 +0000",
  "2023-05-31 12:45 +0000",
  "2023-05-31 13:00 +0000",
  "2023-05-31 13:15 +0000",
  "2023-05-31 13:30 +0000",
  "2023-05-31 13:45 +0000",
  "2023-05-31 14:00 +0000"
]

createCall

This method creates an instant/scheduled call.

Request parameter:

interface CallRequest {
  menu_id: number;
  lang: string;
  phone_number: string;
  scheduled_at?: string;
  ticket_id?: string;
  email?: string;
  recording_permission?: boolean;
}

When scheduled_at is set, it will create a scheduled call.

Create an instant call:

const call = await client.createCall({
 menu_id: 123,
 lang: 'en',
 phone_number: '+12345678',
})

Create a scheduled call:

const call = await client.createCall({
 menu_id: 123,
 lang: 'en',
 phone_number: '+12345678',
 scheduled_at: '2023-05-31T11:45+0000',
})

loadCall

This method retrieves the call information for a specified call ID.

Request parameter:

(callId: number | string)

Example:

const call = await client.loadCall(1234)

cancelCall

This method cancels a call. It is typically used for canceling a scheduled call.

Request parameter:

(callId: number | string)

Example:

client.cancelCall(1234)

createChat

This method creates a new chat.

Request parameter:

interface ChatRequest {
  menu_id: number;
  lang: string;
  trigger_id?: string;
  ticket_id?: string;
  email?: string;
  greeting?: string;
  cobrowsable?: boolean;
}

(data: ChatRequest, customData?)

Example:

client.createChat({
  menu_id: 123,
  lang: 'en',
})

loadChat

This method retrieves the chat information for a given chat ID.

Request parameter:

(chatId: number | string)

// client.loadChat(1234)

resumeChat

This method resumes a dismissed chat.

Request parameter:

(chatId: number | string)

// client.resumeChat(1234)

loadOngoingChat

This method retrieves information for an ongoing chat. The client will save the current ongoing chat ID in the browser's localStorage; this method will try to load the ongoing chat information.

const chat = await client.loadOngoingChat()

getChatDeflection

This method fetches the chat deflection configuration.

// this method can only be used when there is a chat
const deflection = await client.getChatDeflection()

The response is either null or:

interface ChatDeflectionResponse {
  enabled: boolean;
  threshold: number;
  keep_waiting: boolean;
}

escalateChat

This method transfers a chat from virtual agent to human agent.

client.escalateChat()

finishChat

This method changes the chat status to finished.

client.finishChat()

Some methods are called after finishChat,for example sendChatSurvey, sendChatRate.

destroyChat

This method destroys the current ongoing chat.

client.destroyChat()

fetchMessages

This method is used to fetch all the previous messages. It is typically used together with loadOngoingChat. You can call this method after the chat is connected.

client.on("chat.connected", async () => {
  const messages = await client.fetchMessages()
})

sendTextMessage

This method sends a text message.

client.sendTextMessage("hello world")

sendFileMessage

This method sends a file message.

const input = document.querySelector('input[type="file"]')
const file = input.files[0]
client.sendFileMessage(file)

startCobrowse

This method starts a Co-browse session.

client.startCobrowse()

createCobrowseCode

This method createas a Co-browse code.

client.createCobrowseCode()

sendChatTranscripts

Send the chat transcripts to a specified email address.

client.sendChatTranscripts([
  "name1@example.com",
  "name2@example.com",
])

chatOngoing

Emit when there is an ongoing chat.

client.on("chat.ongoing", (chat) => {
  console.log(chat)
})

sendChatRate

This method sends the end-user feedback for the current chat when the chat is finished.

Request parameter:

client.sendChatRate({
  rating: 5,
  feedback: "Very good service",
})

sendChatSurvey

This method sends a survey to the consumer.

Request parameter:

interface {
  [question_id: string]: number | string;
}

You will need to fetch the survey questions:

const questions = await client.getChatSurvey()

Response: { sign_off_display_text: "some text", questions: [ { id: number, type: string, display_text: string, valid_answers? } ] } */

Answer each question, then call sendChatSurvey:

client.sendChatSurvey({
 123: "a",
 231: "b",
})

createEmail

This method sends an email.

Request parameter:

interface EmailRequest {
  name?: string;
  email: string;
  content: string;
  menu_id: number | string;
  lang: string;
  files?: File[];
  recaptcha?: string;
}
client.createEmail({
  menu_id: 123,
  lang: "en",
  name: "User name",
  email: "name@example.com",
  content: "description of the question",
  files: input.files,
})