Reference

Types & events

The types, socket events and storage keys that the React, Vue and Flutter SDKs share. Only the syntax differs between them.

KiliConfig

The config object passed to KiliChat, or to configureKili(). Shown in each language's syntax:

types.ts
export type KiliConfig = {
  apiBaseUrl: string;
  socketBaseUrl?: string;
  apiKey: string;
  apiSecret: string;
};
OptionTypeRequiredDescription
apiBaseUrlstringrequiredBase URL of the Kili REST API.
socketBaseUrlstringoptionalBase URL of the realtime server. Defaults to apiBaseUrl.
apiKeystringrequiredYour organisation's API key.
apiSecretstringrequiredYour organisation's API secret.

Example value: apiBaseUrl is https://api.kili.africa.

Chat, Message and Customer

These are the data types the widget uses. The tables come from the React SDK's types.ts. The Flutter types have the same field names, with some nullability differences listed below.

Chat

OptionTypeRequiredDescription
idnumberrequiredChat ID.
createdAtDaterequiredWhen the chat was created.
updatedAtstringrequiredWhen the chat was last updated.
assignedStaffEmailstringoptionalEmail of the assigned staff member.
assignedStaffFullNamestringoptionalFull name of the assigned staff member.
assignedStaffIdnumberoptionalID of the assigned staff member.
assignmentStatusstringrequiredAssignment state of the chat.
closedAtDateoptionalWhen the chat was closed.
customerEmailstringoptionalThe customer's email.
customerFullNamestringoptionalThe customer's full name.
customerIdnumberoptionalThe customer's ID.
initiationChannelstringoptionalChannel the chat started on, such as web_widget.
lastMessageSentAtstringoptionalWhen the last message was sent.
lastMessagePreviewstringoptionalPreview text of the last message.
lastMessageSenderAccountType'customer' | 'staff'optionalWho sent the last message.
prioritystringrequiredPriority of the chat.
snoozedAtstringoptionalWhen the chat was snoozed.
snoozedByStaffEmailstringoptionalEmail of the staff member who snoozed the chat.
snoozedUntilstringoptionalWhen a snoozed chat wakes up.
staffMemberEmailsMentionedstringoptionalStaff emails mentioned in the chat.
statusstringrequiredStatus of the chat.
summarystringoptionalSummary of the chat.
tagsstringrequiredTags on the chat.
titlestringoptionalTitle of the chat.

Message

OptionTypeRequiredDescription
idnumberrequiredMessage ID.
createdAtDaterequiredWhen the message was created.
updatedAtDaterequiredWhen the message was last updated.
attachmentPathstringoptionalStorage path of an attachment.
attachmentTypestringoptionalMIME type of an attachment.
attachmentUrlstringoptionalURL of an attachment.
deliveredAtDateoptionalWhen the message was delivered.
chatIdnumberoptionalID of the chat the message belongs to.
contentstringoptionalText of the message.
extraDatastringoptionalExtra data attached to the message.
openedByReceiverAtDateoptionalWhen the receiver opened the message.
orgIdnumberoptionalID of the organisation.
senderEmailstringoptionalEmail of the sender.
senderIdnumberoptionalID of the sender.
sentAtstringoptionalWhen the message was sent.
senderAccountTypestringoptionalAccount type of the sender, such as CUSTOMER.
senderFirstNamestringoptionalFirst name of the sender.
senderLastNamestringoptionalLast name of the sender.
mentionedStaffEmailsstringoptionalStaff emails mentioned in the message.
typestringrequiredMessage type, such as TEXT.

Customer

OptionTypeRequiredDescription
idnumberrequiredCustomer ID.
createdAtDaterequiredWhen the customer was created.
updatedAtDaterequiredWhen the customer was last updated.
citystringoptionalCity.
countrystringoptionalCountry.
devicestringoptionalDevice name.
emailstringoptionalEmail address.
firstNamestringoptionalFirst name.
identifierstringoptionalExternal identifier.
lastNamestringoptionalLast name.
middleNamestringoptionalMiddle name.
orgIdnumberoptionalID of the organisation.
phoneCountryCodestringoptionalCountry code of the phone number.
phoneNumberSuffixstringoptionalPhone number without the country code.
statestringoptionalState or region.
usernamestringoptionalUsername.

Dart differences

  • Field names match in both SDKs. In Dart, Chat.createdAt, the createdAt and updatedAt fields of Message and Customer, and Customer.id are nullable (DateTime?, int?). Some fields that are required in TypeScript are nullable in Dart.
  • Message.id is Object? in Dart. It keeps the raw value from the API and compares ids as strings, so either a number or a string works.

ChatAction

The typing and upload states sent with a chat_action event. The widget uses the typing values.

types.ts
type ChatAction =
  | 'typing.started'
  | 'typing.stopped'
  | 'uploading_file.started'
  | 'uploading_file.stopped';

SocketEvent

Every constant is the same in the React, Vue and Flutter SDKs. The last column shows how the widget uses each one. Events marked as used by the Kili agent app are sent or handled on the agent side, and the widget doesn't use them.

ConstantWire valueRole
SocketEvent.ConnectionconnectionNot used. The widget listens for the literal 'connect'.
SocketEvent.DisconnectdisconnectWidget logs it.
SocketEvent.ErrorerrorWidget logs it.
SocketEvent.AssignChatassign_chatKili agent app
SocketEvent.ChatActionchat_actionWidget listens and emits (typing indicators)
SocketEvent.ChatAssignedchat_assignedKili agent app
SocketEvent.ChatDeassignedchat_deassignedKili agent app
SocketEvent.ChatStartedchat_startedWidget listens (a new chat was started)
SocketEvent.ChatUpdatedchat_updatedWidget listens (updates the open chat)
SocketEvent.ChatWindowClosedchat_window_closedKili agent app
SocketEvent.ChatWindowOpenedchat_window_openedKili agent app
SocketEvent.CloseChatclose_chatKili agent app
SocketEvent.InternalNoteinternal_noteKili agent app
SocketEvent.JoinAllUnclosedChatRoomsjoin_all_unclosed_chat_roomsWidget emits on connect
SocketEvent.JoinChatRoomjoin_chat_roomWidget emits after a chat starts
SocketEvent.JoinedChatRoomjoined_chat_roomLogged by SocketProvider (advanced)
SocketEvent.LeaveRoomleave_roomKili agent app
SocketEvent.MarkMsgAsReadmark_msg_as_readKili agent app
SocketEvent.MessagemessageWidget emits to send a message
SocketEvent.MessageDeliveredmessage_deliveredWidget listens (adds a message to the thread)
SocketEvent.NewMentionnew_mentionKili agent app
SocketEvent.PrioritizeChatprioritize_chatKili agent app
SocketEvent.RefetchChatsrefetch_chatsKili agent app
SocketEvent.ReopenChatreopen_chatKili agent app
SocketEvent.RefetchChatCountsrefetch_chat_countsKili agent app
SocketEvent.SnoozeChatsnooze_chatKili agent app
SocketEvent.StartChatstart_chatWidget emits when the visitor starts a conversation

Connection events

The widget listens for the literal connect event, not SocketEvent.Connection. It also emits message to send a visitor's message.

Storage keys

The SDK keeps the visitor's session in browser storage. In Flutter, localStorage is backed by shared_preferences, and each key gets a kili. prefix so it can't clash with your app's own keys. sessionStorage is kept in memory for the app's lifetime.

ConstantWeb keyFlutter keyHolds
LocalStorageKeys.UserlocalStorage: ukili.uThe customer object (JSON).
LocalStorageKeys.JwtAccessTokenlocalStorage: atkili.atThe access token sent as a Bearer token.
LocalStorageKeys.AccessTokenExplocalStorage: atexpkili.atexpWhen the access token expires, from the registration response.
LocalStorageKeys.JwtRefreshTokenlocalStorage: rtkili.rtA refresh token. The state API can store it, but KiliChat doesn't set it.
SessionStorageKeys.ActiveChatsessionStorage: acac (in memory)The chat the visitor has open.

Clearing storage

Clearing the stored customer (u) starts a fresh customer on the next load. Clearing only the access token (at) doesn't create a new customer. The next load registers the stored customer again and gets a new token.