webhook

package
v0.0.0-...-debbb99 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EVENT_NEW_MESSAGE  string = "chat:new_message"
	EventNewChat     string = "chat:new"
	EventNewOperator string = "operator:new"
	// EVENT_NEW_OPERATOR_MESSAGE string = "operator:new_message"
	EventNewClient        string = "client:new"
	EventNewClientMessage string = "client:message"
)

Event Types

View Source
const (
	DEBUG   string = "DEBUG"
	INFO    string = "INFO"
	WARNING string = "WARN"
	ERROR   string = "ERROR"
	FATAL   string = "FATAL"
)

Log levels

Variables

This section is empty.

Functions

func Routes

func Routes(router *httprouter.Router, ds *store.InMemory)

Routes defines the Webhook API CRUD uris

Types

type Event

type Event struct {
	Id   string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
	// JSON string of data
	Data                 string               `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	SourceId             string               `protobuf:"bytes,4,opt,name=source_id,proto3" json:"source_id,omitempty"`
	CreationTime         *timestamp.Timestamp `protobuf:"bytes,5,opt,name=creation_time,proto3" json:"creation_time,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func CreateEvent

func CreateEvent(t string) *Event

CreateEvent a new Event object based on a given Type (t) string

func (*Event) Descriptor

func (*Event) Descriptor() ([]byte, []int)

func (*Event) GetCreationTime

func (m *Event) GetCreationTime() *timestamp.Timestamp

func (*Event) GetData

func (m *Event) GetData() string

func (*Event) GetId

func (m *Event) GetId() string

func (*Event) GetSourceId

func (m *Event) GetSourceId() string

func (*Event) GetType

func (m *Event) GetType() string

func (Event) Key

func (e Event) Key() string

Key implements the Keyer interface of the Store and returns a string used for storing the Webhook in memory.

func (Event) MarshalJSON

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON converts a Event object into a JSON string returned as a byte array.

func (*Event) ProtoMessage

func (*Event) ProtoMessage()

func (*Event) Reset

func (m *Event) Reset()

func (*Event) String

func (m *Event) String() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a JSON string (as a byte array) into a Event object.

func (*Event) XXX_DiscardUnknown

func (m *Event) XXX_DiscardUnknown()

func (*Event) XXX_Marshal

func (m *Event) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Event) XXX_Merge

func (dst *Event) XXX_Merge(src proto.Message)

func (*Event) XXX_Size

func (m *Event) XXX_Size() int

func (*Event) XXX_Unmarshal

func (m *Event) XXX_Unmarshal(b []byte) error

type Webhook

type Webhook struct {
	Id                   string               `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	EventTypes           []string             `protobuf:"bytes,2,rep,name=event_types,proto3" json:"event_types,omitempty"`
	Enabled              bool                 `protobuf:"varint,3,opt,name=enabled,proto3" json:"enabled,omitempty"`
	Secret               string               `protobuf:"bytes,4,opt,name=secret,proto3" json:"secret,omitempty"`
	Uri                  string               `protobuf:"bytes,5,opt,name=uri,proto3" json:"uri,omitempty"`
	CreationTime         *timestamp.Timestamp `protobuf:"bytes,6,opt,name=creation_time,proto3" json:"creation_time,omitempty"`
	UpdatedTime          *timestamp.Timestamp `protobuf:"bytes,7,opt,name=updated_time,json=update_time,proto3" json:"updated_time,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func CreateWebhook

func CreateWebhook(uri string, events []string) *Webhook

CreateWebhook a new Webhook object based on the given event strings.

func GetByEventType

func GetByEventType(ds *store.InMemory, event string) ([]*Webhook, error)

GetByEventType returns one or more Webhooks that are for a specified event

func (*Webhook) Descriptor

func (*Webhook) Descriptor() ([]byte, []int)

func (*Webhook) GetCreationTime

func (m *Webhook) GetCreationTime() *timestamp.Timestamp

func (*Webhook) GetEnabled

func (m *Webhook) GetEnabled() bool

func (*Webhook) GetEventTypes

func (m *Webhook) GetEventTypes() []string

func (*Webhook) GetId

func (m *Webhook) GetId() string

func (*Webhook) GetSecret

func (m *Webhook) GetSecret() string

func (*Webhook) GetUpdatedTime

func (m *Webhook) GetUpdatedTime() *timestamp.Timestamp

func (*Webhook) GetUri

func (m *Webhook) GetUri() string

func (Webhook) Key

func (w Webhook) Key() string

Key implements the Keyer interface of the Store and returns a string used for storing the Webhook in memory.

func (Webhook) MarshalJSON

func (w Webhook) MarshalJSON() ([]byte, error)

MarshalJSON converts a Webhook object into a JSON string returned as a byte array.

func (*Webhook) ProtoMessage

func (*Webhook) ProtoMessage()

func (*Webhook) Reset

func (m *Webhook) Reset()

func (*Webhook) Run

func (w *Webhook) Run(t string, d []byte, n string) error

Run executes the Webhook sending an HTTP request with an Event to the defined URI. We generate a Mnml-Signature header that looks something along the lines of:

Mnml-Signature: t=1492774577,

v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd

Where t is the unix timestamp in seconds, and v1 is an HMAC signature using SHA-256. This can be used to validate that the signature is coming from the daemon service and not anywhere else.

To manually verify the signature, take t and concat it with the JSON payload received, separated by a '.' dot. Use the Webhook's secret to sign the concatenated timestamp.payload and it should equal v1.

func (*Webhook) String

func (m *Webhook) String() string

func (*Webhook) UnmarshalJSON

func (w *Webhook) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a JSON string (as a byte array) into a Webhook object.

func (*Webhook) XXX_DiscardUnknown

func (m *Webhook) XXX_DiscardUnknown()

func (*Webhook) XXX_Marshal

func (m *Webhook) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Webhook) XXX_Merge

func (dst *Webhook) XXX_Merge(src proto.Message)

func (*Webhook) XXX_Size

func (m *Webhook) XXX_Size() int

func (*Webhook) XXX_Unmarshal

func (m *Webhook) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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