agent

package
v6.0.0-...-97dcf11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package agent provides the client and structures for making Web API requests to Agent Chat API.

Detailed documentation of Agent Chat API is available here: https://developers.livechat.com/docs/messaging/agent-chat-api/.

All the methods of API have their analogue in Agent Chat API

Agent Chat API Version

This API Client uses Agent Chat API in version 3.6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewArchivesFilters

func NewArchivesFilters() *archivesFilters

NewArchivesFilters creates empty structure to aggregate filters for ListArchives method

func NewChatsFilters

func NewChatsFilters() *chatsFilters

NewChatsFilters creates empty structure to aggregate filters for Chats in ListChats method By default filters include also active chats

func NewIntegerFilter

func NewIntegerFilter(values []int64, inclusive bool) *integerFilter

NewIntegerFilter creates new filter for integer values `inclusive` parameter controls if the filtered values should match or exclude given values

func NewPropertyFilterType

func NewPropertyFilterType(includes bool, vals []interface{}, requireEveryValue bool) *propertyFilterType

NewPropertyFilterType creates new filter object for Chat properties If the first parameter is passed along with nil values then the last parameter will be ignored and the filter will check only existence of property Otherwise it will check if property values match/exclude given values based on the first parameter The last parameter modifies the filter behavior so that it matches only those Chats that have or don't have all values in the property the filter relates to

func NewThreadsFilters

func NewThreadsFilters() *threadsFilters

NewThreadsFilters creates empty structure to aggregate filters for Threads in ListThreads method

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 Agent 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 Agent API.

If provided client is nil, then default http client with 20s timeout is used.

func (*API) AddUserToChat

func (a *API) AddUserToChat(chatID, userID, userType, visibility string, ignoreRequesterPresence bool) error

AddUserToChat adds user to the chat. You can't add more than one customer type user to the chat.

func (*API) BanCustomer

func (a *API) BanCustomer(customerID string, days uint) error

BanCustomer bans customer for specific period of time (expressed in days).

func (*API) CreateCustomer

func (a *API) CreateCustomer(name, email, avatar string, sessionFields []map[string]string) (string, error)

CreateCustomer creates new Customer.

func (*API) DeactivateChat

func (a *API) DeactivateChat(chatID string, ignoreRequesterPresence bool) error

DeactivateChat deactivates active thread for given chat. If no thread is active, then this method is a no-op.

func (*API) DeleteChatProperties

func (a *API) DeleteChatProperties(chatID string, properties map[string][]string) error

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

func (a *API) DeleteThreadProperties(chatID, threadID string, properties map[string][]string) error

DeleteThreadProperties deletes given thread's properties.

func (*API) FollowChat

func (a *API) FollowChat(chatID string) error

FollowChat marks given chat as followed by requester.

func (*API) FollowCustomer

func (a *API) FollowCustomer(customerID string) error

FollowCustomer marks a customer as followed. As a result, the requester (an agent) will receive the info about all the changes related to that customer via pushes.

func (*API) GetChat

func (a *API) GetChat(chatID string, threadID string) (Chat, error)

GetChat returns given thread for given chat.

func (*API) GetCustomer

func (a *API) GetCustomer(customerID string) (customer Customer, err error)

GetCustomer returns Customer.

func (*API) ListAgentsForTransfer

func (a *API) ListAgentsForTransfer(chatID string) (AgentsForTransfer, error)

ListAgentsForTransfer returns the Agents you can transfer a given chat to.

func (*API) ListArchives

func (a *API) ListArchives(filters *archivesFilters, pageID string, limit uint) (chats []Chat, found uint, previousPage, nextPage string, err error)

ListArchives returns archived chats.

func (*API) ListChats

func (a *API) ListChats(filters *chatsFilters, sortOrder, pageID string, limit uint) (summary []ChatSummary, found uint, previousPage, nextPage string, err error)

ListChats returns chat summaries list.

func (*API) ListRoutingStatuses

func (a *API) ListRoutingStatuses(groupIDs []int) ([]AgentStatus, error)

func (*API) ListThreads

func (a *API) ListThreads(chatID, sortOrder, pageID string, limit, minEventsCount uint, filters *threadsFilters) (threads []Thread, found uint, previousPage, nextPage string, err error)

ListChats returns threads list.

func (*API) Logout

func (a *API) Logout(agentID string) error

Logout logs out the specified agent

func (*API) MarkEventsAsSeen

func (a *API) MarkEventsAsSeen(chatID string, seenUpTo time.Time) error

MarkEventsAsSeen marks all events up to given date in given chat as seen for current agent.

func (*API) Multicast

func (a *API) Multicast(recipients MulticastRecipients, content json.RawMessage, multicastType string) error

Multicast method serves for the chat-unrelated communication. Messages sent using multicast are not being saved.

func (*API) RemoveUserFromChat

func (a *API) RemoveUserFromChat(chatID, userID, userType string, ignoreRequesterPresence bool) error

RemoveUserFromChat Removes a user from chat. Removing customer user type is not allowed. It's always possible to remove the requester from the chat.

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

func (a *API) SendEvent(chatID string, event interface{}, attachToLastThread bool) (string, error)

SendEvent sends event of supported type to given chat. It returns event ID.

Supported event types are: event, message, system_message and file.

func (*API) SendRichMessagePostback

func (a *API) SendRichMessagePostback(chatID, eventID, threadID, postbackID string, toggled bool) error

SendRichMessagePostback sends postback for given rich message event.

func (*API) SendTypingIndicator

func (a *API) SendTypingIndicator(chatID, visibility string, isTyping bool) error

SendTypingIndicator sends a notification about typing to defined recipients.

func (*API) SetAuthorID

func (a *API) SetAuthorID(authorID string)

SetAuthorID provides a way to point the actual author of the action (e.g. send an event as a bot)

func (*API) SetRoutingStatus

func (a *API) SetRoutingStatus(agentID, status string) error

SetRoutingStatus changes status of an agent or a bot.

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) TagThread

func (a *API) TagThread(chatID, threadID, tag string) error

TagThread adds given tag to thread.

func (*API) TransferChat

func (a *API) TransferChat(chatID, targetType string, ids []interface{}, opts TransferChatOptions) error

TransferChat transfers chat to agent or group.

func (*API) UnfollowChat

func (a *API) UnfollowChat(chatID string) error

UnfollowChat removes requester from chat followers.

func (*API) UnfollowCustomer

func (a *API) UnfollowCustomer(customerID string) error

UnfollowCustomer removes the agent from the list of customer's followers.

func (*API) UntagThread

func (a *API) UntagThread(chatID, threadID, tag string) error

UntagThread removes given tag from thread.

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(customerID, name, email, avatar string, sessionFields []map[string]string) error

UpdateCustomer updates 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 Agent

type Agent struct {
	*User
	RoutingStatus string `json:"routing_status,omitempty"`
	Visibility    string `json:"visibility,omitempty"`
}

Agent represents LiveChat agent.

type AgentStatus

type AgentStatus struct {
	AgentID string `json:"agent_id,omitempty"`
	Status  string `json:"status,omitempty"`
}

type AgentsForTransfer

type AgentsForTransfer []struct {
	AgentID          string `json:"agent_id"`
	TotalActiveChats uint   `json:"total_active_chats"`
}

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"`
	IsFollowed bool       `json:"is_followed,omitempty"`
	Agents     map[string]*Agent
	Customers  map[string]*Customer
}

Chat represents LiveChat chat.

func (*Chat) UnmarshalJSON

func (c *Chat) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface for Chat.

func (*Chat) Users

func (c *Chat) Users() []*User

Users function returns combined list of Chat's Agents and Customers.

type ChatSummary

type ChatSummary struct {
	ID               string `json:"id"`
	LastEventPerType map[string]struct {
		ThreadID              string    `json:"thread_id"`
		ThreadCreatedAt       time.Time `json:"thread_created_at"`
		RestrictedEventAccess string    `json:"restricted_access,omitempty"`
		Event                 Event     `json:"event"`
	} `json:"last_event_per_type,omitempty"`
	Users             []*User        `json:"users"`
	LastThreadSummary *ThreadSummary `json:"last_thread_summary,omitempty"`
	Properties        Properties     `json:"properties,omitempty"`
	Access            *Access        `json:"access,omitempty"`
	IsFollowed        bool           `json:"is_followed"`
}

ChatSummary represents a short summary of a chat

type Customer

type Customer struct {
	*User
	EmailVerified bool  `json:"email_verified"`
	LastVisit     Visit `json:"last_visit"`
	Statistics    struct {
		VisitsCount            int `json:"visits_count"`
		ThreadsCount           int `json:"threads_count"`
		ChatsCount             int `json:"chats_count"`
		PageViewsCount         int `json:"page_views_count"`
		GreetingsShownCount    int `json:"greetings_shown_count"`
		GreetingsAcceptedCount int `json:"greetings_accepted_count"`
	} `json:"statistics"`
	AgentLastEventCreatedAt    time.Time           `json:"agent_last_event_created_at"`
	CustomerLastEventCreatedAt time.Time           `json:"customer_last_event_created_at"`
	CreatedAt                  time.Time           `json:"created_at"`
	SessionFields              []map[string]string `json:"session_fields"`
	Followed                   bool                `json:"followed"`
	Online                     bool                `json:"online"`
	State                      string              `json:"state"`
	GroupIDs                   []int               `json:"group_ids"`
}

Customer represents LiveChat customer.

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"`
	Visibility string     `json:"visibility,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

func (e *Event) File() *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

func (e *Event) Message() *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 Geolocation

type Geolocation struct {
	Country     string `json:"country"`
	CountryCode string `json:"country_code"`
	Region      string `json:"region"`
	City        string `json:"city"`
	Timezone    string `json:"timezone"`
	Latitude    string `json:"latitude"`
	Longitude   string `json:"longitude"`
}

Geolocation contains geolocation information.

type GreetingsFilter

type GreetingsFilter struct {
	From          string         `json:"from,omitempty"`
	To            string         `json:"to,omitempty"`
	Values        []int64        `json:"values,omitempty"`
	ExcludeValues []int64        `json:"exclude_values,omitempty"`
	Exists        *bool          `json:"exists,omitempty"`
	Groups        *integerFilter `json:"groups,omitempty"`
}

GreetingsFilter represents structure to match greetings when getting Archives

type InitialChat

type InitialChat struct {
	ID         string         `json:"id"`
	Access     *Access        `json:"access,omitempty"`
	Properties Properties     `json:"properties,omitempty"`
	Thread     *InitialThread `json:"thread,omitempty"`
	Users      []*User        `json:"users,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"`
	Tags       []string      `json:"tags,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 MulticastRecipients

type MulticastRecipients struct {
	Agents    *MulticastRecipientsAgents    `json:"agents,omitempty"`
	Customers *MulticastRecipientsCustomers `json:"customers,omitempty"`
}

MulticastRecipients aggregates Agent and Customer recipients that multicast should be sent to

type MulticastRecipientsAgents

type MulticastRecipientsAgents struct {
	Groups []uint   `json:"groups,omitempty"`
	IDs    []string `json:"ids,omitempty"`
	All    *bool    `json:"all,omitempty"`
}

MulticastRecipientsAgents represents recipients for multicast to agents

type MulticastRecipientsCustomers

type MulticastRecipientsCustomers struct {
	IDs []string `json:"ids,omitempty"`
}

MulticastRecipientsCustomers represents recipients for multicast to customers

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 Properties

type Properties map[string]map[string]interface{}

Properties represents LiveChat properties in form of property_namespace -> property -> value.

type PropertiesFilters

type PropertiesFilters map[string]map[string]*propertyFilterType

PropertiesFilters represents set of filters for Chat properties

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 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 SurveyFilter

type SurveyFilter struct {
	Type     string `json:"type"`
	AnswerID string `json:"answer_id"`
}

SurveyFilter represents structure to match surveys when getting Archives

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"`
	RestrictedAccess          string     `json:"restricted_access"`
	Properties                Properties `json:"properties"`
	Access                    *Access    `json:"access"`
	Tags                      []string   `json:"tags,omitempty"`
	Events                    []*Event   `json:"events"`
	PreviousThreadID          string     `json:"previous_thread_id"`
	NextThreadID              string     `json:"next_thread_id"`
	CreatedAt                 time.Time  `json:"created_at"`
	PreviousAccesibleThreadID string     `json:"previous_accessible_thread_id,omitempty"`
	NextAccessibleThreadID    string     `json:"next_accessible_thread_id,omitempty"`
	Queue                     *Queue     `json:"queue,omitempty"`
	QueuesDuration            *int       `json:"queues_duration,omitempty"`
	CustomerVisit             *struct {
		IP          string      `json:"ip"`
		UserAgent   string      `json:"user_agent"`
		Geolocation Geolocation `json:"geolocation"`
	} `json:"customer_visit,omitempty"`
}

Thread represents LiveChat chat thread

type ThreadSummary

type ThreadSummary struct {
	ID         string     `json:"id"`
	UserIDs    []string   `json:"user_ids"`
	Properties Properties `json:"properties,omitempty"`
	Active     bool       `json:"active"`
	Access     *Access    `json:"access,omitempty"`
	Tags       []string   `json:"tags,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	Queue      *Queue     `json:"queue,omitempty"`
}

ThreadSummary represents a short summary of a thread

type TransferChatOptions

type TransferChatOptions struct {
	IgnoreRequesterPresence  bool
	IgnoreAgentsAvailability bool
}

TransferChatOptions defines options for TransferChat method.

type User

type User struct {
	ID             string    `json:"id"`
	Type           string    `json:"type"`
	Name           string    `json:"name"`
	Avatar         string    `json:"avatar"`
	Email          string    `json:"email"`
	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).

func (*User) Agent

func (u *User) Agent() *Agent

Agent function converts User object to Agent object if User's Type is "agent". If Type is different or User is malformed, then it returns nil.

func (*User) Customer

func (u *User) Customer() *Customer

Customer function converts User object to Customer object if User's Type is "customer". If Type is different or User is malformed, then it returns nil.

type Visit

type Visit struct {
	IP          string      `json:"ip"`
	UserAgent   string      `json:"user_agent"`
	Geolocation Geolocation `json:"geolocation"`
	StartedAt   time.Time   `json:"started_at"`
	EndedAt     time.Time   `json:"ended_at"`
	Referrer    string      `json:"referrer"`
	LastPages   []struct {
		OpenedAt time.Time `json:"opened_at"`
		URL      string    `json:"url"`
		Title    string    `json:"title"`
	} `json:"last_pages"`
}

Visit contains information about particular customer's visit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL