Skip to main content

Types

TypeScript type definitions for the Traise Widget API.

Configuration

WidgetConfig

Configuration options passed to init().

interface WidgetConfig {
// Required
apiKey: string;

// UI Settings
mode?: 'light' | 'dark';
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';

// User Information
userId?: string;
firstName?: string;
lastName?: string;

// Features
debug?: boolean;
demoMode?: boolean;
}
PropertyTypeRequiredDefaultDescription
apiKeystringYes-Your Traise widget API key
modestringNo'light'Color mode: 'light' or 'dark'
positionstringNo'bottom-right'Widget position on screen
userIdstringNo''User identifier
firstNamestringNo''User's first name
lastNamestringNo''User's last name
debugbooleanNofalseEnable debug mode and logging
demoModebooleanNofalseRun with simulated data (no API calls)

Client Data

ClientData

Client information passed to loadClient() or makeCall().

interface ClientData {
name?: string;
phoneNumber?: string;
mobilePhone?: string;
email?: string;
firstName?: string;
lastName?: string;
}
PropertyTypeDescription
namestringClient's display name
phoneNumberstringPrimary phone number
mobilePhonestringMobile phone number (alternative to phoneNumber)
emailstringEmail address
firstNamestringFirst name
lastNamestringLast name

Status

WidgetStatus

Status object returned by getStatus().

interface WidgetStatus {
initialized: boolean;
visible: boolean;
websocket: boolean;
voice: boolean;
activeCall: boolean;
unreadMessages: number;
}
PropertyTypeDescription
initializedbooleanWhether the widget initialized successfully
visiblebooleanWhether the widget panel is visible
websocketbooleanWhether WebSocket is connected
voicebooleanWhether voice device is ready
activeCallbooleanWhether a call is in progress
unreadMessagesnumberCount of unread messages

Errors

WidgetError

Error object emitted with the error event.

interface WidgetError {
category: 'auth' | 'voice' | 'sms' | 'network' | 'api';
message: string;
code?: string;
details?: any;
timestamp: string;
}
PropertyTypeDescription
categorystringError category for handling
messagestringHuman-readable error message
codestringOptional error code
detailsanyOptional additional error details
timestampstringISO timestamp when error occurred

Error Categories

CategoryDescription
authAuthentication or authorization error
voiceVoice call error (connection, device, etc.)
smsSMS/messaging error
networkNetwork connectivity error
apiAPI request error

Call Information

CallInfo

Information about a voice call.

interface CallInfo {
phoneNumber: string;
direction: 'inbound' | 'outbound';
status: 'connecting' | 'ringing' | 'connected' | 'ended';
duration?: number;
clientName?: string;
}
PropertyTypeDescription
phoneNumberstringPhone number of the other party
directionstringWhether call is inbound or outbound
statusstringCurrent call status
durationnumberCall duration in seconds (when ended)
clientNamestringName of the client if known

Call Status Values

StatusDescription
connectingCall is being initiated
ringingCall is ringing
connectedCall is active
endedCall has ended

Messages

Message

Information about an SMS message.

interface Message {
id: string;
text: string;
phoneNumber: string;
direction: 'inbound' | 'outbound';
status: 'pending' | 'sent' | 'delivered' | 'failed';
timestamp: string;
clientName?: string;
}
PropertyTypeDescription
idstringUnique message identifier
textstringMessage content
phoneNumberstringPhone number of the other party
directionstringWhether message is inbound or outbound
statusstringDelivery status
timestampstringISO timestamp
clientNamestringName of the client if known

Message Status Values

StatusDescription
pendingMessage is being sent
sentMessage was sent
deliveredMessage was delivered
failedMessage failed to send

Using Types in TypeScript

If you're using TypeScript, you can create a type declaration file:

// types/traise-widget.d.ts
declare module 'traise-widget' {
interface WidgetConfig {
apiKey: string;
mode?: 'light' | 'dark';
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
userId?: string;
firstName?: string;
lastName?: string;
debug?: boolean;
demoMode?: boolean;
}

interface ClientData {
name?: string;
phoneNumber?: string;
mobilePhone?: string;
email?: string;
firstName?: string;
lastName?: string;
}

interface WidgetStatus {
initialized: boolean;
visible: boolean;
websocket: boolean;
voice: boolean;
activeCall: boolean;
unreadMessages: number;
}

interface TraiseWidgetAPI {
init(config: WidgetConfig): Promise<TraiseWidgetAPI>;
show(): TraiseWidgetAPI;
hide(): TraiseWidgetAPI;
destroy(): void;
retry(): Promise<TraiseWidgetAPI>;
makeCall(target: string | ClientData): Promise<void>;
endCall(): void;
sendMessage(phoneNumber: string, message: string): Promise<void>;
loadClient(client: ClientData): TraiseWidgetAPI;
setClient(client: ClientData): TraiseWidgetAPI;
getClient(): ClientData | null;
unloadClient(): TraiseWidgetAPI;
getConfig(): WidgetConfig;
updateConfig(updates: Partial<WidgetConfig>): TraiseWidgetAPI;
getStatus(): WidgetStatus;
on(event: string, handler: Function): TraiseWidgetAPI;
off(event: string, handler: Function): TraiseWidgetAPI;
}

export function init(config: WidgetConfig): Promise<TraiseWidgetAPI>;
export function show(): TraiseWidgetAPI;
export function hide(): TraiseWidgetAPI;
export function destroy(): void;
export function retry(): Promise<TraiseWidgetAPI>;
export function makeCall(target: string | ClientData): Promise<void>;
export function endCall(): void;
export function sendMessage(phoneNumber: string, message: string): Promise<void>;
export function loadClient(client: ClientData): TraiseWidgetAPI;
export function setClient(client: ClientData): TraiseWidgetAPI;
export function getClient(): ClientData | null;
export function unloadClient(): TraiseWidgetAPI;
export function getConfig(): WidgetConfig;
export function updateConfig(updates: Partial<WidgetConfig>): TraiseWidgetAPI;
export function getStatus(): WidgetStatus;
export function on(event: string, handler: Function): TraiseWidgetAPI;
export function off(event: string, handler: Function): TraiseWidgetAPI;

const widget: TraiseWidgetAPI;
export default widget;
}

Next Steps