twisms

package
v0.0.0-...-15ca262 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MPL-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPhoneNumber = errors.New("invalid phone number, must be E.164 format")

ErrInvalidPhoneNumber is returned when the phone number is not in E.164 format.

Functions

func FilterMessage

func FilterMessage(filters *twismsproto.MessageFilters, msg *twismsproto.Message) bool

FilterMessage filters the given message based on the given filters. It implements the given set of filters in Go code.

func NewReplyingMessage

func NewReplyingMessage(msg *twismsproto.Message, body *twismsproto.MessageBody) *twismsproto.Message

NewReplyingMessage creates a new message that is a reply to the given message with the given body.

func NewTextBody

func NewTextBody(text string) *twismsproto.MessageBody

NewTextBody creates a new message body with the given text.

func ReplyMessage

func ReplyMessage(ctx context.Context, s MessageSender, msg *twismsproto.Message, body *twismsproto.MessageBody) error

ReplyMessage is a helper function that replies to the given message using the provided MessageSender. If it implements MessageReplier, it will use the fast path for synchronous replies.

func SendAutoTextMessage

func SendAutoTextMessage(ctx context.Context, s MessageSender, to string, body *twismsproto.MessageBody) error

SendAutoTextMessage sends an SMS message with the given text from the service's sending number to the given recipient.

func SendTextMessage

func SendTextMessage(ctx context.Context, s MessageSender, from, to string, body *twismsproto.MessageBody) error

SendTextMessage sends an SMS message with the given text from the given sender to the given recipient.

func ValidatePhoneNumber

func ValidatePhoneNumber(number string) error

ValidatePhoneNumber validates the given phone number.

Types

type MessageReplier

type MessageReplier interface {
	MessageSender

	// ReplyMessage replies to the given message.
	ReplyMessage(ctx context.Context, msg *twismsproto.Message, body *twismsproto.MessageBody) error
}

MessageReplier describes a service that can reply to messages. It is meant to extend the MessageSender interface and provide services with a fast path for synchronous replies. It is optional and services can choose to not implement it.

type MessageSender

type MessageSender interface {
	// SendMessage sends an SMS message to the given recipient.
	SendMessage(ctx context.Context, msg *twismsproto.Message) error
	// SendingNumber returns the number to send messages from and the cost of
	// sending a message. The cost should be within [0.0, 1.0]. Lower values
	// are chosen first.
	//
	// TODO: figure out a better way to load-balance a pool of phone numbers.
	// Perhaps that is worthy of its own service.
	SendingNumber() (string, float64)
}

MessageSender describes a service that can send messages.

type MessageService

type MessageService interface {
	MessageSubscriber
	MessageSender
}

MessageService describes a service that can both send and receive message events. It is a combination of the two interfaces MessageSubscriber and MessageSender.

type MessageSubscriber

type MessageSubscriber interface {
	// SubscribeMessages subscribes to incoming messages for the given
	// recipient.
	SubscribeMessages(ch chan<- *twismsproto.Message, filters *twismsproto.MessageFilters)
	// UnsubscribeMessages unsubscribes the given channel from incoming
	// messages.
	UnsubscribeMessages(ch chan<- *twismsproto.Message)
}

MessageSubscriber describes a service that can subscribe to incoming messages.

Directories

Path Synopsis
Package wsbridge implements Twisms via a Websocket Protobuf RPC bridge.
Package wsbridge implements Twisms via a Websocket Protobuf RPC bridge.

Jump to

Keyboard shortcuts

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