webhooks

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: 5 Imported by: 0

Documentation

Overview

Package webhooks implements handlers and definitions of LiveChat webhooks.

General LiveChat webhooks documentation is available here: https://developers.livechatinc.com/docs/management/configuration-api/#webhooks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWebhookHandler

func NewWebhookHandler(cfg *Configuration) http.HandlerFunc

NewWebhookHandler creates WebhookHandler that can be used with golang HTTP server.

WebhookHandler decodes raw webhook JSON into dedicated webhook structures and, if provided, passes those structures into webhook Handlers attached to given webhook type.

Types

type AccessGranted

type AccessGranted struct {
	Resource string         `json:"resource"`
	ID       string         `json:"id"`
	Access   objects.Access `json:"access"`
}

AccessGranted represents payload of access_granted webhook.

type AccessRevoked

type AccessRevoked struct {
	Resource string         `json:"resource"`
	ID       string         `json:"id"`
	Access   objects.Access `json:"access"`
}

AccessRevoked represents payload of access_revoked webhook.

type AccessSet

type AccessSet struct {
	Resource string         `json:"resource"`
	ID       string         `json:"id"`
	Access   objects.Access `json:"access"`
}

AccessSet represents payload of access_set webhook.

type AgentDeleted

type AgentDeleted struct {
	AgentID string `json:"agent_id"`
}

AgentDeleted represents payload of agent_deleted webhook.

type AgentStatusChanged

type AgentStatusChanged struct {
	AgentID string `json:"agent_id"`
	Status  string `json:"status"`
}

AgentStatusChanged represents payload of agent_status_changed webhook.

type ChatPropertiesDeleted

type ChatPropertiesDeleted struct {
	ChatID     string              `json:"chat_id"`
	Properties map[string][]string `json:"properties"`
}

ChatPropertiesDeleted represents payload of chat_properties_deleted webhook.

type ChatPropertiesUpdated

type ChatPropertiesUpdated struct {
	ChatID     string             `json:"chat_id"`
	Properties objects.Properties `json:"properties"`
}

ChatPropertiesUpdated represents payload of chat_properties_updated webhook.

type ChatThreadPropertiesDeleted

type ChatThreadPropertiesDeleted struct {
	ChatID     string              `json:"chat_id"`
	ThreadID   string              `json:"thread_id"`
	Properties map[string][]string `json:"properties"`
}

ChatThreadPropertiesDeleted represents payload of chat_thread_properties_deleted webhook.

type ChatThreadPropertiesUpdated

type ChatThreadPropertiesUpdated struct {
	ChatID     string             `json:"chat_id"`
	ThreadID   string             `json:"thread_id"`
	Properties objects.Properties `json:"properties"`
}

ChatThreadPropertiesUpdated represents payload of chat_thread_properties_updated webhook.

type ChatThreadTagged

type ChatThreadTagged struct {
	ChatID   string `json:"chat_id"`
	ThreadID string `json:"thread_id"`
	Tag      string `json:"tag"`
}

ChatThreadTagged represents payload of chat_thread_tagged webhook.

type ChatThreadUntagged

type ChatThreadUntagged struct {
	ChatID   string `json:"chat_id"`
	ThreadID string `json:"thread_id"`
	Tag      string `json:"tag"`
}

ChatThreadUntagged represents payload of chat_thread_untagged webhook.

type ChatUserAdded

type ChatUserAdded struct {
	ChatID   string       `json:"chat_id"`
	ThreadID string       `json:"thread_id"`
	User     objects.User `json:"user"`
	UserType string       `json:"user_type"`
}

ChatUserAdded represents payload of chat_user_added webhook.

type ChatUserRemoved

type ChatUserRemoved struct {
	ChatID   string `json:"chat_id"`
	ThreadID string `json:"thread_id"`
	UserID   string `json:"user_id"`
	UserType string `json:"user_type"`
}

ChatUserRemoved represents payload of chat_user_removed webhook.

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

A Configuration structure is used to configure WebhookHandler

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration creates basic WebhookHandler configuration that processes no webhooks and uses http.Error to handle webhook processing errors.

func (*Configuration) WithAction

func (cfg *Configuration) WithAction(action string, handler Handler, secretKey string) *Configuration

WithAction allows to attach custom webhook Handler for given webhook action.

If secretKey is an empty string, then no validation of webhook's secret is performed. Otherwise, webhook's secret is strictly validated. In case of any mismatch between expected and actual secret key, webhook processing is stopped and error is returned.

func (*Configuration) WithErrorHandler

func (cfg *Configuration) WithErrorHandler(h ErrorHandler) *Configuration

WithErrorHandler allows to attach custom ErrorHandler, which acts as sink for all WebhookHandler errors.

Custom ErrorHandler might be used to eg. always return 200OK for incoming webhooks.

type CustomerCreated

type CustomerCreated objects.Customer

CustomerCreated represents payload of customer_created webhook.

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, err string, statusCode int)

The ErrorHandler type is used to define custom error handlers for WebhookHandler.

It allows to customize behaviour of WebhookHandler when webhook processing errors, eg. to always respond with 200OK.

type EventPropertiesDeleted

type EventPropertiesDeleted struct {
	ChatID     string              `json:"chat_id"`
	ThreadID   string              `json:"thread_id"`
	EventID    string              `json:"event_id"`
	Properties map[string][]string `json:"properties"`
}

EventPropertiesDeleted represents payload of event_properties_deleted webhook.

type EventPropertiesUpdated

type EventPropertiesUpdated struct {
	ChatID     string             `json:"chat_id"`
	ThreadID   string             `json:"thread_id"`
	EventID    string             `json:"event_id"`
	Properties objects.Properties `json:"properties"`
}

EventPropertiesUpdated represents payload of event_properties_updated webhook.

type EventUpdated

type EventUpdated struct {
	ChatID   string        `json:"chat_id"`
	ThreadID string        `json:"thread_id"`
	Event    objects.Event `json:"event"`
}

EventUpdated represents payload of event_updated webhook.

type EventsMarkedAsSeen

type EventsMarkedAsSeen struct {
	UserID   string `json:"user_id"`
	ChatID   string `json:"chat_id"`
	SeenUpTo string `json:"seen_up_to"`
}

EventsMarkedAsSeen represents payload of events_marked_as_seen webhook.

type Handler

type Handler func(webhookPayload interface{}) error

The Handler type is used to define webhook processors.

It can be used with WebhookHandler, in which case WebhookHandler will pass decoded webhook payload (ie. one of webhooks structures).

type IncomingChatThread

type IncomingChatThread struct {
	Chat objects.Chat `json:"chat"`
}

IncomingChatThread represents payload of incoming_chat_thread webhook.

func (*IncomingChatThread) UnmarshalJSON

func (p *IncomingChatThread) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface for IncomingChatThread.

type IncomingEvent

type IncomingEvent struct {
	ChatID   string        `json:"chat_id"`
	ThreadID string        `json:"thread_id"`
	Event    objects.Event `json:"event"`
}

IncomingEvent represents payload of incoming_event webhook.

type IncomingRichMessagePostback

type IncomingRichMessagePostback struct {
	UserID   string `json:"user_id"`
	ChatID   string `json:"chat_id"`
	ThreadID string `json:"thread_id"`
	EventID  string `json:"event_id"`
	Postback struct {
		ID      string `json:"id"`
		Toggled bool   `json:"toggled"`
	} `json:"postback"`
}

IncomingRichMessagePostback represents payload of incoming_rich_message_postback webhook.

type ThreadClosed

type ThreadClosed struct {
	ChatID   string `json:"chat_id"`
	ThreadID string `json:"thread_id"`
	UserID   string `json:"user_id"`
}

ThreadClosed represents payload of thread_closed webhook.

type WebhookBase

type WebhookBase struct {
	WebhookID      string          `json:"webhook_id"`
	SecretKey      string          `json:"secret_key"`
	Action         string          `json:"action"`
	Payload        json.RawMessage `json:"payload"`
	AdditionalData json.RawMessage `json:"additional_data"`
}

WebhookBase represents general webhook format.

Jump to

Keyboard shortcuts

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