Documentation ¶
Overview ¶
Package customer provides the client and structures for making Web API requests to Customer Chat API.
Detailed documentation of Customer Chat API is available here: https://developers.livechat.com/docs/messaging/customer-chat-api/.
All the methods of API have their analogue in Customer Chat API except for SendMessage and SendSystemMessage, which are specializations of SendEvent.
Customer Chat API Version ¶
This API Client uses Customer Chat API in version 3.5.
Index ¶
- func CustomerEndpointGenerator(r i.HTTPEndpointGenerator) i.HTTPEndpointGenerator
- func ValidateEvent(e interface{}) error
- type API
- func (a *API) AcceptGreeting(greetingID int, uniqueID string) error
- func (a *API) CancelGreeting(uniqueID string) error
- func (a *API) CheckGoals(pageURL string, groupID int, customerFields map[string]string) error
- func (a *API) DeactivateChat(chatID string) error
- func (a *API) DeleteChatProperties(chatID string, properties map[string][]string) error
- func (a *API) DeleteEventProperties(chatID, threadID, eventID string, properties map[string][]string) error
- func (a *API) DeleteThreadProperties(chatID, threadID string, properties map[string][]string) error
- func (a *API) GetChat(chatID string, threadID string) (Chat, error)
- func (a *API) GetConfiguration(groupID int, version string) (*Configuration, error)
- func (a *API) GetCustomer() (*Customer, error)
- func (a *API) GetDynamicConfiguration(groupID int, url, channelType string, isTest bool) (*DynamicConfiguration, error)
- func (a *API) GetForm(groupID int, formType FormType) (form *Form, enabled bool, err error)
- func (a *API) GetLocalization(groupID int, language, version string) (map[string]string, error)
- func (a *API) GetPredictedAgent() (*PredictedAgent, error)
- func (a *API) GetURLInfo(url string) (*URLInfo, error)
- func (a *API) ListChats(sortOrder, pageID string, limit uint) (summary []ChatSummary, total uint, previousPage, nextPage string, err error)
- func (a *API) ListGroupProperties(groupID uint, namespace, name string) (Properties, error)
- func (a *API) ListGroupStatuses(groupIDs []int) (map[int]GroupStatus, error)
- func (a *API) ListLicenseProperties(namespace, name string) (Properties, error)
- func (a *API) ListThreads(chatID, sortOrder, pageID string, limit, minEventsCount uint) (threads []Thread, found uint, previousPage, nextPage string, err error)
- func (a *API) MarkEventsAsSeen(chatID string, seenUpTo time.Time) error
- func (a *API) RequestEmailVerification(callbackURI string) error
- func (a *API) ResumeChat(initialChat *InitialChat, continuous, active bool) (threadID string, eventIDs []string, err error)
- func (a *API) SendEvent(chatID string, e interface{}, attachToLastThread bool) (string, error)
- func (a *API) SendMessage(chatID, text string, recipients Recipients) (string, error)
- func (a *API) SendRichMessagePostback(chatID, threadID, eventID, postbackID string, toggled bool) error
- func (a *API) SendSneakPeek(chatID, text string) error
- func (a *API) SendSystemMessage(chatID, text, messageType string, textVars map[string]string, ...) (string, error)
- func (a *API) SetCustomerSessionFields(sessionFields []map[string]string) error
- func (a *API) StartChat(initialChat *InitialChat, continuous, active bool) (chatID, threadID string, eventIDs []string, err error)
- func (a *API) UpdateChatProperties(chatID string, properties Properties) error
- func (a *API) UpdateCustomer(name, email, avatarURL string, sessionFields []map[string]string) error
- func (a *API) UpdateEventProperties(chatID, threadID, eventID string, properties Properties) error
- func (a *API) UpdateThreadProperties(chatID, threadID string, properties Properties) error
- type Access
- type Agent
- type AgentStatus
- type Chat
- type ChatSummary
- type ConfigButton
- type Configuration
- type Customer
- type DynamicConfiguration
- type Event
- type File
- type FilledForm
- type Form
- type FormType
- type GroupStatus
- type InitialChat
- type InitialThread
- type Message
- type Postback
- type PredictedAgent
- type Properties
- type Queue
- type Recipients
- type RichMessage
- type RichMessageButton
- type RichMessageElement
- type RichMessageImage
- type SystemMessage
- type Thread
- type URLInfo
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CustomerEndpointGenerator ¶
func CustomerEndpointGenerator(r i.HTTPEndpointGenerator) i.HTTPEndpointGenerator
func ValidateEvent ¶
func ValidateEvent(e interface{}) error
ValidateEvent checks if given interface resolves into supported event type
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API provides the API operation methods for making requests to Customer Chat API via Web API. See this package's package overview docs for details on the service.
func NewAPI ¶
func NewAPI(t authorization.TokenGetter, client *http.Client, clientID string) (*API, error)
NewAPI returns ready to use Customer API.
If provided client is nil, then default http client with 20s timeout is used.
func (*API) AcceptGreeting ¶
AcceptGreeting marks an incoming greeting as seen.
func (*API) CancelGreeting ¶
CancelGreeting cancels a greeting (an invitation to the chat).
func (*API) CheckGoals ¶
CheckGoals triggers checking if goals were achieved. Then, Agents receive the information. You should call this method to provide goals parameters for the server when the customers limit is reached. Works only for offline Customers.
func (*API) DeactivateChat ¶
DeactivateChat deactivates active thread for given chat. If no thread is active, then this method is a no-op.
func (*API) DeleteChatProperties ¶
DeleteChatProperties deletes given chat's properties.
func (*API) DeleteEventProperties ¶
func (a *API) DeleteEventProperties(chatID, threadID, eventID string, properties map[string][]string) error
DeleteEventProperties deletes given event's properties.
func (*API) DeleteThreadProperties ¶
DeleteThreadProperties deletes given chat thread's properties.
func (*API) GetConfiguration ¶
func (a *API) GetConfiguration(groupID int, version string) (*Configuration, error)
GetConfiguration returns the configuration of a given group in a given version.
func (*API) GetCustomer ¶
GetCustomer returns current Customer.
func (*API) GetDynamicConfiguration ¶
func (a *API) GetDynamicConfiguration(groupID int, url, channelType string, isTest bool) (*DynamicConfiguration, error)
GetDynamicConfiguration returns the dynamic configuration of a given group. It provides data to call Get Configuration and Get Localization.
func (*API) GetForm ¶
GetForm returns an empty prechat, postchat or ticket form and indication whether the form is enabled on the license.
func (*API) GetLocalization ¶
GetLocalization returns the localization of a given language and group in a given version.
func (*API) GetPredictedAgent ¶
func (a *API) GetPredictedAgent() (*PredictedAgent, error)
GetPredictedAgent returns the predicted Agent - the one the Customer will chat with when the chat starts. To use this method, the Customer needs to be logged in, which can be done via Customer Chat RTM Api's login method.
func (*API) GetURLInfo ¶
GetURLInfo returns info on a given URL.
func (*API) ListChats ¶
func (a *API) ListChats(sortOrder, pageID string, limit uint) (summary []ChatSummary, total uint, previousPage, nextPage string, err error)
ListChats returns chat summaries list.
func (*API) ListGroupProperties ¶
func (a *API) ListGroupProperties(groupID uint, namespace, name string) (Properties, error)
ListGroupProperties returns the properties of a given group.
func (*API) ListGroupStatuses ¶
func (a *API) ListGroupStatuses(groupIDs []int) (map[int]GroupStatus, error)
ListGroupStatuses returns status of provided groups.
Possible values are: GroupStatusOnline, GroupStatusOffline and GroupStatusOnlineForQueue. GroupStatusUnknown should never be returned.
func (*API) ListLicenseProperties ¶
func (a *API) ListLicenseProperties(namespace, name string) (Properties, error)
ListLicenseProperties returns the properties of a given license.
func (*API) ListThreads ¶
func (a *API) ListThreads(chatID, sortOrder, pageID string, limit, minEventsCount uint) (threads []Thread, found uint, previousPage, nextPage string, err error)
ListThreads returns threads list.
func (*API) MarkEventsAsSeen ¶
MarkEventsAsSeen marks all events up to given date in given chat as seen for current customer.
func (*API) RequestEmailVerification ¶
RequestEmailVerification sends a request to confirm customer identity with webhook sent to `callbackURI` after validation.
func (*API) ResumeChat ¶
func (a *API) ResumeChat(initialChat *InitialChat, continuous, active bool) (threadID string, eventIDs []string, err error)
ResumeChat resumes chat initialChat.ID with access, properties and initial thread as defined in initialChat. It returns respectively thread ID and initial event IDs (except for server-generated events).
func (*API) SendEvent ¶
SendEvent sends event of supported type to given chat. It returns event ID.
Supported event types are: event, file, message, rich_message and system_message.
func (*API) SendMessage ¶
func (a *API) SendMessage(chatID, text string, recipients Recipients) (string, error)
SendMessage sends event of type message to given chat. It returns event ID.
func (*API) SendRichMessagePostback ¶
func (a *API) SendRichMessagePostback(chatID, threadID, eventID, postbackID string, toggled bool) error
SendRichMessagePostback sends postback for given rich message event.
func (*API) SendSneakPeek ¶
SendSneakPeek sends sneak peek of message for given chat.
func (*API) SendSystemMessage ¶
func (a *API) SendSystemMessage(chatID, text, messageType string, textVars map[string]string, recipients Recipients, attachToLastThread bool) (string, error)
SendSystemMessage sends event of type system_message to given chat. It returns event ID.
func (*API) SetCustomerSessionFields ¶
SetCustomerSessionFields sets current customer's fields.
func (*API) StartChat ¶
func (a *API) StartChat(initialChat *InitialChat, continuous, active bool) (chatID, threadID string, eventIDs []string, err error)
StartChat starts new chat with access, properties and initial thread as defined in initialChat. It returns respectively chat ID, thread ID and initial event IDs (except for server-generated events).
func (*API) UpdateChatProperties ¶
func (a *API) UpdateChatProperties(chatID string, properties Properties) error
UpdateChatProperties updates given chat's properties.
func (*API) UpdateCustomer ¶
func (a *API) UpdateCustomer(name, email, avatarURL string, sessionFields []map[string]string) error
UpdateCustomer updates current customer's info.
func (*API) UpdateEventProperties ¶
func (a *API) UpdateEventProperties(chatID, threadID, eventID string, properties Properties) error
UpdateEventProperties updates given event's properties.
func (*API) UpdateThreadProperties ¶
func (a *API) UpdateThreadProperties(chatID, threadID string, properties Properties) error
UpdateThreadProperties updates given thread's properties.
type Access ¶
type Access struct {
GroupIDs []int `json:"group_ids"`
}
Access represents LiveChat chat and thread access
type AgentStatus ¶
type Chat ¶
type Chat struct { ID string `json:"id,omitempty"` Properties Properties `json:"properties,omitempty"` Access *Access `json:"access,omitempty"` Thread *Thread `json:"thread,omitempty"` Threads []Thread `json:"threads,omitempty"` Agents map[string]*Agent Customers map[string]*Customer }
Chat represents LiveChat chat.
func (*Chat) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface for Chat.
type ChatSummary ¶
type ChatSummary struct { ID string `json:"id"` LastThreadCreatedAt time.Time `json:"last_thread_created_at"` LastThreadID string `json:"last_thread_id,omitempty"` LastEventPerType map[string]struct { ThreadID string `json:"thread_id"` ThreadCreatedAt time.Time `json:"thread_created_at"` Event Event `json:"event"` } `json:"last_event_per_type,omitempty"` Users []*User `json:"users"` Access *Access `json:"access,omitempty"` Properties Properties `json:"properties,omitempty"` Active bool `json:"active"` }
ChatSummary represents a short summary of a chat
type ConfigButton ¶
type Configuration ¶
type Configuration struct { Buttons []ConfigButton `json:"buttons"` TicketForm *Form `json:"ticket_form,omitempty"` PrechatForm *Form `json:"prechat_form,omitempty"` AllowedDomains []string `json:"allowed_domains,omitempty"` Integrations map[string]map[string]string `json:"integrations"` Properties struct { Group Properties `json:"group"` License Properties `json:"license"` } `json:"properties"` }
type Customer ¶
type Customer struct { *User Email string `json:"email"` EmailVerified bool `json:"email_verified"` SessionFields []map[string]string `json:"session_fields"` }
Customer represents LiveChat customer.
type DynamicConfiguration ¶
type DynamicConfiguration struct { GroupID int `json:"group_id"` OrganizationID string `json:"organization_id"` ClientLimitExceeded bool `json:"client_limit_exceeded"` DomainAllowed bool `json:"domain_allowed"` ConfigVersion string `json:"config_version"` LocalizationVersion string `json:"localization_version"` Language string `json:"language"` }
type Event ¶
type Event struct { ID string `json:"id,omitempty"` CustomID string `json:"custom_id,omitempty"` CreatedAt time.Time `json:"created_at"` AuthorID string `json:"author_id"` Properties Properties `json:"properties,omitempty"` Recipients string `json:"recipients,omitempty"` Type string `json:"type,omitempty"` // contains filtered or unexported fields }
Event represents base of all LiveChat chat events.
To get specific event type's structure, call appropriate function based on Event's Type.
func (*Event) File ¶
File function converts Event object to File object if Event's Type is "file". If Type is different or Event is malformed, then it returns nil.
func (*Event) FilledForm ¶
func (e *Event) FilledForm() *FilledForm
FilledForm function converts Event object to FilledForm object if Event's Type is "filled_form". If Type is different or Event is malformed, then it returns nil.
func (*Event) Message ¶
Message function converts Event object to Message object if Event's Type is "message". If Type is different or Event is malformed, then it returns nil.
func (*Event) RichMessage ¶
func (e *Event) RichMessage() *RichMessage
RichMessage function converts Event object to RichMessage object if Event's Type is "rich_message". If Type is different or Event is malformed, then it returns nil.
func (*Event) SystemMessage ¶
func (e *Event) SystemMessage() *SystemMessage
SystemMessage function converts Event object to SystemMessage object if Event's Type is "system_message". If Type is different or Event is malformed, then it returns nil.
type File ¶
type File struct { Event ContentType string `json:"content_type"` Name string `json:"name"` URL string `json:"url"` ThumbnailURL string `json:"thumbnail_url,omitempty"` Thumbnail2xURL string `json:"thumbnail2x_url,omitempty"` Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` Size int `json:"size,omitempty"` AlternativeText string `json:"alternative_text,omitempty"` }
File represents LiveChat file event
type FilledForm ¶
type FilledForm struct { Fields []struct { ID string `json:"id"` Label string `json:"label"` Type string `json:"type"` Value string `json:"value"` } `json:"fields"` FormType string `json:"form_type"` Event }
FilledForm represents LiveChat filled form event.
type Form ¶
type Form struct { ID string `json:"id"` Fields []struct { ID string `json:"id"` Type string `json:"type"` Label string `json:"label"` Required bool `json:"required"` Options []struct { ID string `json:"id"` Type int `json:"group_id"` Label string `json:"label"` } `json:"options"` } `json:"fields"` }
Form struct describes schema of custom form (e-mail, prechat or postchat survey).
type GroupStatus ¶
type GroupStatus int
GroupStatus represents status of groups.
const ( // GroupStatusUnknown should never be returned by API Client. GroupStatusUnknown GroupStatus = iota GroupStatusOnline GroupStatusOffline GroupStatusOnlineForQueue )
Possible values of GroupStatus.
type InitialChat ¶
type InitialChat struct { ID string `json:"id"` Access *Access `json:"access,omitempty"` Properties Properties `json:"properties,omitempty"` Thread *InitialThread `json:"thread,omitempty"` }
InitialChat represents initial chat used in StartChat or ResumeChat.
func (*InitialChat) Validate ¶
func (chat *InitialChat) Validate() error
Validate checks if there are no unsupported event types in InitialChat Thread
type InitialThread ¶
type InitialThread struct { Events []interface{} `json:"events,omitempty"` Properties Properties `json:"properties,omitempty"` }
InitialThread represents initial chat thread used in StartChat or ResumeChat.
type Message ¶
type Message struct { Event Text string `json:"text"` Postback *Postback `json:"postback,omitempty"` }
Message represents LiveChat message event.
type Postback ¶
type Postback struct { ID string `json:"id"` ThreadID string `json:"thread_id"` EventID string `json:"event_id"` Type string `json:"type,omitempty"` Value string `json:"value,omitempty"` }
Postback represents postback data in LiveChat message event.
type PredictedAgent ¶
type PredictedAgent struct { Agent struct { ID string `json:"id"` Name string `json:"name"` AvatarURL string `json:"avatar"` IsBot bool `json:"is_bot"` JobTitle string `json:"job_title"` Type string `json:"type"` } `json:"agent"` Queue bool `json:"queue"` }
PredictedAgent is an agent returned by GetPredictedAgent method.
type Properties ¶
Properties represents LiveChat properties in form of property_namespace -> property -> value.
type Queue ¶
type Queue struct { Position int `json:"position"` WaitTime int `json:"wait_time"` QueuedAt time.Time `json:"queued_at"` }
Queue represents position of a thread in a queue
type Recipients ¶
type Recipients string
Recipients represents possible event recipients.
const ( All Recipients = "all" Agents Recipients = "agents" )
Possible values of Recipients.
type RichMessage ¶
type RichMessage struct { Event TemplateID string `json:"template_id"` Elements []RichMessageElement `json:"elements"` }
RichMessage represents LiveChat rich message event
type RichMessageButton ¶
type RichMessageButton struct { Text string `json:"text"` Type string `json:"type"` Value string `json:"value"` UserIds []string `json:"user_ids"` PostbackID string `json:"postback_id"` // Allowed values: compact, full, tall WebviewHeight string `json:"webview_height"` // Allowed values: new, current Target string `json:"target,omitempty"` }
RichMessageButton represents button in LiveChat rich message
type RichMessageElement ¶
type RichMessageElement struct { Buttons []RichMessageButton `json:"buttons"` Title string `json:"title"` Subtitle string `json:"subtitle"` Image *RichMessageImage `json:"image,omitempty"` }
RichMessageElement represents element of LiveChat rich message
type RichMessageImage ¶
type RichMessageImage struct { URL string `json:"url"` Name string `json:"name,omitempty"` ContentType string `json:"content_type,omitempty"` Size int `json:"size,omitempty"` Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` AlternativeText string `json:"alternative_text,omitempty"` }
RichMessageImage represents image in LiveChat rich message
type SystemMessage ¶
type SystemMessage struct { Event SystemMessageType string `json:"system_message_type"` Text string `json:"text,omitempty"` TextVars map[string]string `json:"text_vars,omitempty"` }
SystemMessage represents LiveChat system message event.
type Thread ¶
type Thread struct { ID string `json:"id"` Active bool `json:"active"` UserIDs []string `json:"user_ids"` Properties Properties `json:"properties"` Access *Access `json:"access"` Events []*Event `json:"events"` PreviousThreadID string `json:"previous_thread_id"` NextThreadID string `json:"next_thread_id"` CreatedAt time.Time `json:"created_at"` Queue *Queue `json:"queue,omitempty"` }
Thread represents LiveChat chat thread
type URLInfo ¶
type URLInfo struct { Title string `json:"title"` Description string `json:"description"` URL string `json:"url"` ImageURL string `json:"image_url"` ImageOriginalURL string `json:"image_original_url"` ImageWidth int `json:"image_width"` ImageHeight int `json:"image_height"` }
URLInfo contains some OpenGraph info of the URL.
type User ¶
type User struct { ID string `json:"id"` Type string `json:"type"` Name string `json:"name"` Avatar string `json:"avatar"` Present bool `json:"present"` EventsSeenUpTo time.Time `json:"events_seen_up_to"` // contains filtered or unexported fields }
User represents base of both Customer and Agent
To get specific user type's structure, call Agent() or Customer() (based on Type value).