webhook

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package webhook provides HTTP webhook handling for Twilio and Telnyx callbacks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Port is the HTTP server port.
	Port int

	// TwilioAuthToken is used to validate Twilio webhook signatures.
	TwilioAuthToken string

	// TelnyxPublicKey is used to validate Telnyx webhook signatures (optional).
	TelnyxPublicKey string

	// Logger for server logging.
	Logger *slog.Logger
}

Config configures the webhook server.

type SMSHandler

type SMSHandler func(ctx context.Context, msg SMSMessage) error

SMSHandler is called when an SMS message is received.

type SMSMessage

type SMSMessage struct {
	ID         string
	From       string
	To         string
	Body       string
	Provider   string // "twilio" or "telnyx"
	Timestamp  time.Time
	RawPayload map[string]string
}

SMSMessage represents an incoming SMS message from a webhook.

type Server

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

Server handles incoming webhooks from Twilio and Telnyx.

func New

func New(cfg Config) *Server

New creates a new webhook server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler for use with external servers.

func (*Server) OnSMS

func (s *Server) OnSMS(handler SMSHandler)

OnSMS registers a handler for incoming SMS messages.

func (*Server) OnVoice

func (s *Server) OnVoice(handler VoiceHandler)

OnVoice registers a handler for voice events.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start() error

Start starts the webhook server.

type VoiceEvent

type VoiceEvent struct {
	CallID       string
	Status       string // "initiated", "ringing", "answered", "completed", "busy", "no-answer", "failed"
	From         string
	To           string
	Direction    string
	Duration     int // seconds, for completed calls
	RecordingURL string
	Provider     string
	Timestamp    time.Time
	RawPayload   map[string]string
}

VoiceEvent represents a voice call status event.

type VoiceHandler

type VoiceHandler func(ctx context.Context, event VoiceEvent) error

VoiceHandler is called when a voice event is received.

Jump to

Keyboard shortcuts

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