objects

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package objects defines common LiveChat structures.

General common LiveChat structures documentation is available here: https://developers.livechatinc.com/docs/messaging/customer-chat-api/#other-common-structures

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateEvent

func ValidateEvent(e interface{}) error

ValidateEvent checks if given interface resolves into supported event type

Types

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"`
}

Agent represents LiveChat agent.

type Chat

type Chat struct {
	ID         string     `json:"id,omitempty"`
	Properties Properties `json:"properties,omitempty"`
	Access     Access     `json:"access,omitempty"`
	Threads    []Thread   `json:"threads,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  interface{}    `json:"last_event_per_type,omitempty"`
	Users             []interface{}  `json:"users"`
	LastThreadSummary *ThreadSummary `json:"last_thread_summary,omitempty"`
	Properties        Properties     `json:"properties,omitempty"`
	Access            interface{}    `json:"access,omitempty"`
	Order             uint64         `json:"order,omitempty"`
	IsFollowed        bool           `json:"is_followed"`
}

ChatSummary represents a short summary of a chat

type Customer

type Customer struct {
	*User
	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"`
	Fields                     map[string]string `json:"fields"`
}

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,omitempty"`
	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 speficic 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.

type File

type File struct {
	Event
	ContentType string `json:"content_type"`
	URL         string `json:"url"`
	Width       int    `json:"width,omitempty"`
	Height      int    `json:"height,omitempty"`
	Name        string `json:"name"`
}

File represents LiveChat file event

type FilledForm

type FilledForm struct {
	Fields []struct {
		Label string `json:"label"`
		Type  string `json:"type"`
		Value string `json:"value"`
	} `json:"fields"`
	Event
}

FilledForm represents LiveChat filled form event.

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 ActivateChat.

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 ActivateChat.

type Message

type Message struct {
	Event
	Text string `json:"text,omitempty"`
}

Message represents LiveChat message event.

type Properties

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

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

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"`
	UserIds    []string `json:"user_ids"`
	Value      string   `json:"value"`
	PostbackID string   `json:"postback_id"`
	// Allowed values: compact, full, tall
	WebviewHeight string `json:"webview_height"`
}

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"`
}

RichMessageElement represents element of LiveChat rich message

type RichMessageImage

type RichMessageImage struct {
	Name        string `json:"name"`
	URL         string `json:"url"`
	ContentType string `json:"content_type"`
	Size        int    `json:"size"`
	Width       int    `json:"width,omitempty"`
	Height      int    `json:"height,omitempty"`
}

RichMessageImage represents image in LiveChat rich message

type SystemMessage

type SystemMessage struct {
	Event
	Type string `json:"system_message_type,omitempty"`
	Text string `json:"text,omitempty"`
}

SystemMessage represents LiveChat system message event.

type Thread

type Thread struct {
	ID               string     `json:"id"`
	Timestamp        Time       `json:"timestamp"`
	Active           bool       `json:"active"`
	UserIDs          []string   `json:"user_ids"`
	RestrictedAccess bool       `json:"restricted_access"`
	Order            int        `json:"order"`
	Properties       Properties `json:"properties"`
	Access           Access     `json:"access"`
	Events           []*Event   `json:"events"`
}

Thread represents LiveChat chat thread

type ThreadSummary

type ThreadSummary struct {
	ID          string `json:"id"`
	Order       int32  `json:"order"`
	TotalEvents uint   `json:"total_events"`
}

ThreadSummary represents a short summary of a thread.

type Time

type Time struct {
	time.Time
}

The Time type is a helper type to convert string time into golang time representation.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface for Time.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(s []byte) (err error)

UnmarshalJSON implements json.Unmarshaler interface for Time.

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"`
	LastSeen Time   `json:"last_seen_timestamp"`
	// contains filtered or unexported fields
}

User represents base of both Customer and Agent

To get speficic 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 struct {
		Country     string `json:"country"`
		CountryCode string `json:"country_code"`
		Region      string `json:"region"`
		City        string `json:"city"`
		Timezone    string `json:"timezone"`
	} `json:"geolocation"`
	StartedAt time.Time `json:"started_at"`
	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