Documentation ¶
Index ¶
- Variables
- func FilterMessage(filters *twismsproto.MessageFilters, msg *twismsproto.Message) bool
- func NewReplyingMessage(msg *twismsproto.Message, body *twismsproto.MessageBody) *twismsproto.Message
- func NewTextBody(text string) *twismsproto.MessageBody
- func ReplyMessage(ctx context.Context, s MessageSender, msg *twismsproto.Message, ...) error
- func SendAutoTextMessage(ctx context.Context, s MessageSender, to string, body *twismsproto.MessageBody) error
- func SendTextMessage(ctx context.Context, s MessageSender, from, to string, ...) error
- func ValidatePhoneNumber(number string) error
- type MessageReplier
- type MessageSender
- type MessageService
- type MessageSubscriber
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.