# README
Courier

Install Courier in your workspace with:
go get github.com/nyaruka/courier
Build Courier with:
go install github.com/nyaruka/courier/cmd/...
This will create a new executable in $GOPATH/bin called courier
.
To run the tests you need to create the test database:
$ createdb courier_test
$ createuser -P -E courier
$ psql -d courier_test -f backends/rapidpro/schema.sql
$ psql -d courier_test -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO courier;"
$ psql -d courier_test -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO courier;"
To run all of the tests including benchmarks:
go test $(go list ./... | grep -v /vendor/) -cover -bench=.
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
EnsureSpoolDirPresent checks that the passed in spool directory is present and writable.
GetTextAndAttachments returns both the text of our message as well as any attachments, newline delimited.
LogChannelEventReceived logs that we received the passed in channel event.
LogMsgReceived logs that we received the passed in message.
LogMsgStatusReceived logs our that we received a new MsgStatus.
LogRequestIgnored logs that we ignored the passed in request.
NewBackend creates the type of backend passed in.
NewChannelID creates a new ChannelID for the passed in int64.
NewChannelLog creates a new channel log for the passed in channel, id, and request and response info.
NewChannelLogFromRR creates a new channel log for the passed in channel, id, and request/response log.
NewChannelUUID creates a new ChannelUUID for the passed in string.
NewForeman creates a new Foreman for the passed in server with the number of max senders.
NewMockBackend returns a new mock backend suitable for testing.
NewMockChannel creates a new mock channel for the passed in type, address, country and config.
NewMsgID creates a new MsgID for the passed in int64.
NewMsgUUID creates a new unique message UUID.
NewMsgUUIDFromString creates a new message UUID for the passed in string.
NewSender creates a new sender responsible for sending messages.
NewServer creates a new Server for the passed in configuration.
NewServerWithLogger creates a new Server for the passed in configuration.
NewTelegramURN returns a URN for the passed in telegram identifier.
NewTelURNForChannel returns a URN for the passed in telephone number and channel.
NewTelURNForCountry returns a URN for the passed in telephone number and country code ("US").
NewURNFromParts returns a new URN for the given scheme, path and display.
RegisterBackend adds a new backend, called by individual backends in their init() func.
RegisterFlusher creates a new walker which we will use to flush files from the passed in directory.
RegisterHandler adds a new handler for a channel type, this is called by individual handlers when they are initialized.
SplitAttachment takes an attachment string and returns the media type and URL for the attachment.
WriteChannelEventSuccess writes a JSON response for the passed in event indicating we handled it.
WriteError writes a JSON response for the passed in error.
WriteIgnored writes a JSON response for the passed in message.
WriteMsgSuccess writes a JSON response for the passed in msg indicating we handled it.
WriteStatusSuccess writes a JSON response for the passed in status update indicating we handled it.
WriteToSpool writes the passed in object to the passed in subdir.
# Constants
BulkPriority is the priority used for bulk messages.
ConfigAPIKey is a constant key for channel configs.
ConfigAuthToken is a constant key for channel configs.
ConfigContentType is a constant key for channel configs.
ConfigPassword is a constant key for channel configs.
ConfigSendBody is a constant key for channel configs.
ConfigSendMethod is a constant key for channel configs.
ConfigSendURL is a constant key for channel configs.
ConfigUsername is a constant key for channel configs.
DefaultPriority is used for normal responses and single messages.
FacebookScheme is the scheme used for Facebook identifiers.
HighPriority is used for messages that should come before any others.
Possible values for MsgStatus.
Possible values for MsgStatus.
Possible values for MsgStatus.
Possible values for MsgStatus.
Possible values for MsgStatus.
Possible values for MsgStatus.
Possible values for MsgStatus.
Possible values for ChannelEventTypes.
Possible values for MsgStatus.
NilStatusCode is used when we have an error before even sending anything.
Possible values for ChannelEventTypes.
TelegramScheme is the scheme used for telegram identifier.
TelScheme is the scheme used for telephone numbers.
TwitterScheme is the scheme used for Twitter identifiers.
# Variables
AnyChannelType is our empty channel type used when doing lookups without channel type assertions.
ErrChannelExpired is returned when our cached channel has outlived it's TTL.
ErrChannelNotFound is returned when we fail to find a channel in the db.
ErrChannelWrongType is returned when we find a channel with the set UUID but with a different type.
ErrMsgNotFound is returned when trying to queue the status for a Msg that doesn't exit.
NilChannelID is our nil value for ChannelIDs.
NilChannelUUID is our nil value for channel UUIDs.
NilMsgID is our nil value for MsgID.
NilMsgUUID is a "zero value" message UUID.
NilURN is our constant for nil URNs.
# Structs
ChannelID is our SQL type for a channel's id.
ChannelLog represents the log for a msg being received, sent or having its status updated.
ChannelUUID is our typing of a channel's UUID.
Foreman takes care of managing our set of sending workers and assigns msgs for each to send.
MockBackend is a mocked version of a backend which doesn't require a real database or cache.
MockChannel implements the Channel interface and is used in our tests.
MsgID is our typing of the db int type.
MsgUUID is the UUID of a message which has been received.
Sender is our type for a single goroutine that is sending messages.
# Interfaces
Backend represents the part of Courier that deals with looking up and writing channels and results.
Channel defines the general interface backend Channel implementations must adhere to.
ChannelEvent represents an event on a channel, such as a follow, new conversation or referral.
ChannelHandler is the interface all handlers must satisfy.
Msg is our interface to represent an incoming or outgoing message.
MsgStatus represents a status update on a message.
ReceiveEvent is our interface for the types of things a ChannelReceiveMsgFunc can return.
Server is the main interface ChannelHandlers use to interact with backends.
# Type aliases
BackendConstructorFunc defines a function to create a particular backend type.
ChannelActionHandlerFunc is the interface ChannelHandler functions must satisfy to handle other types of requests.
ChannelEventType is the type of channel event this is.
ChannelReceiveMsgFunc is the interface ChannelHandler functions must satisfy to handle incoming msgs The Server will take care of looking up the channel by UUID before passing it to this function.
ChannelType is our typing of the two char channel types.
ChannelUpdateStatusFunc is the interface ChannelHandler functions must satisfy to handle incoming status requests.
FlusherFunc defines our interface for flushers, they are handed a filename and byte blob and are expected to try to flush that to the db, returning an error if the db is still down.
MsgPriority is our type for the priority of a message.
MsgStatusValue is the status of a message.
URN represents a Universal Resource Name, we use this for contact identifiers like phone numbers etc..