silcomms

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 11 Imported by: 8

README

Linting and Tests Coverage Status

silcomms Library

silcomms is a library that implements Bewell's SILcomms Bulk SMS functionality

Installing it

silcomms is compatible with modern Go releases in module mode, with Go installed:

go get -u github.com/savannahghi/silcomms

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

import "github.com/savannahghi/silcomms"

and run go get without parameters.

The package name is silcomms

Developing

The default branch library is main

We try to follow semantic versioning ( https://semver.org/ ). For that reason, every major, minor and point release should be tagged.

git tag -m "v0.0.1" "v0.0.1"
git push --tags

Continuous integration tests must pass on Travis CI. Our coverage threshold is 90% i.e you must keep coverage above 90%.

Environment variables

In order to run tests, you need to have an env.sh file similar to this one:

# Application settings
export SIL_COMMS_BASE_URL = ""
export SIL_COMMS_EMAIL = ""
export SIL_COMMS_PASSWORD = ""
export SIL_COMMS_SENDER_ID = ""
export GITGUARDIAN_API_KEY=""

This file must not be committed to version control.

It is important to export the environment variables. If they are not exported, they will not be visible to child processes e.g go test ./....

These environment variables should also be set up on github CI environment variable section.

Contributing

I would like to cover the entire GitHub API and contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward. See CONTRIBUTING.md for details.

Versioning

In general, enumutils follows semver as closely as we can for tagging releases of the package. For self-contained libraries, the application of semantic versioning is relatively straightforward and generally understood. We've adopted the following versioning policy:

  • We increment the major version with any incompatible change to non-preview functionality, including changes to the exported Go API surface or behavior of the API.
  • We increment the minor version with any backwards-compatible changes to functionality, as well as any changes to preview functionality in the GitHub API. GitHub makes no guarantee about the stability of preview functionality, so neither do we consider it a stable part of the go-github API.
  • We increment the patch version with any backwards-compatible bug fixes.

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BaseURL represents the SIL-Comms base URL
	BaseURL = serverutils.MustGetEnvVar("SIL_COMMS_BASE_URL")
)

Functions

This section is empty.

Types

type APIErrorResponse added in v0.0.6

type APIErrorResponse struct {
	Status  string                 `json:"status"`
	Message string                 `json:"message"`
	Data    map[string]interface{} `json:"data"`
}

APIErrorResponse is the representation of an error response

type APIResponse

type APIResponse struct {
	Status  Status      `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

APIResponse is the base response from sil communications API

type AuthServerImpl added in v0.0.7

type AuthServerImpl interface {
	LoginUser(ctx context.Context, input *authutils.LoginUserPayload) (*authutils.OAUTHResponse, error)
	RefreshToken(ctx context.Context, refreshToken string) (*authutils.OAUTHResponse, error)
}

AuthServerImpl defines the methods provided by the auth server library

type BulkSMSResponse

type BulkSMSResponse struct {
	GUID       string   `json:"guid"`
	Sender     string   `json:"sender"`
	Message    string   `json:"message"`
	Recipients []string `json:"recipients"`
	State      string   `json:"state"`
	SMS        []string `json:"sms"`
	Created    string   `json:"created"`
	Updated    string   `json:"updated"`
}

BulkSMSResponse is the data in the API response that is returned after making a request to send bulk sms

type CommsLib

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

CommsLib is the SDK implementation for interacting with the sil communications API

func MustNewSILCommsLib added in v0.0.3

func MustNewSILCommsLib(authServer AuthServerImpl) *CommsLib

MustNewSILCommsLib initializes a new implementation of the SIL Comms SDK

func NewSILCommsLib

func NewSILCommsLib(authServer AuthServerImpl) (*CommsLib, error)

NewSILCommsLib initializes a new implementation of the SIL Comms SDK

func (CommsLib) ActivateSubscription added in v0.0.5

func (l CommsLib) ActivateSubscription(ctx context.Context, offer string, msisdn string, activate bool) (bool, error)

ActivateSubscription is used activate a subscription to an offer on SILCOMMS. msisdn - phone number to be to activate a subscription to an offer. offer - offercode used to create a subscription. activate - boolean value to determine whether activation should happen on SDP

func (CommsLib) GetSubscriptions added in v0.0.5

func (l CommsLib) GetSubscriptions(ctx context.Context, queryParams map[string]string) ([]*Subscription, error)

GetSubscriptions fetches subscriptions from SILCOMMs based on provided query params params - query params used to get a subscription to an offer.

func (CommsLib) SendBulkSMS

func (l CommsLib) SendBulkSMS(ctx context.Context, message string, recipients []string, senderID string) (*BulkSMSResponse, error)

SendBulkSMS returns a 202 Accepted synchronous response while the API attempts to send the SMS in the background. An asynchronous call is made to the app's sms_callback URL with a notification that shows the Bulk SMS status. An asynchronous call is made to the app's sms_callback individually for each of the recipients with the SMS status. message - message to be sent via the Bulk SMS recipients - phone number(s) to receive the Bulk SMS

func (CommsLib) SendPremiumSMS added in v0.0.4

func (l CommsLib) SendPremiumSMS(ctx context.Context, message, msisdn, subscription string) (*PremiumSMSResponse, error)

SendPremiumSMS is used to send a premium SMS using SILCOMMS gateway. message - message to be sent via the premium SMS. msisdn - phone number to receive the premium SMS. subscription - subscription/offer associated with the premium SMS.

type ErrorMessage

type ErrorMessage struct {
	Message string `json:"message,omitempty"`
}

ErrorMessage is the message in the ErrorResponse

type ErrorResponse

type ErrorResponse struct {
	Detail  string         `json:"detail,omitempty"`
	Code    string         `json:"code,omitempty"`
	Message []ErrorMessage `json:"message,omitempty"`
}

ErrorResponse is the data in the API response when an error is encountered

type PremiumSMSResponse added in v0.0.4

type PremiumSMSResponse struct {
	GUID         string `json:"guid"`
	Body         string `json:"body"`
	Msisdn       string `json:"msisdn"`
	SMSType      string `json:"sms_type"`
	Gateway      string `json:"gateway"`
	Carrier      string `json:"carrier"`
	Subscription string `json:"subscription"`
	Direction    string `json:"direction"`
	State        string `json:"state"`
}

PremiumSMSResponse is the response returned after making a request to SILCOMMS to send a premium SMS

type ResultsResponse added in v0.0.3

type ResultsResponse struct {
	Count    int           `json:"count"`
	Next     *string       `json:"next"`
	Previous *string       `json:"previous"`
	Results  []interface{} `json:"results"`
}

ResultsResponse is the base response from a paginated list of results

type Status

type Status string

Status is the API response status

const (
	// StatusSuccess returns a `success` response
	StatusSuccess Status = "success"
	// StatusFailure returns a `failure` response
	StatusFailure Status = "failure"
	// StatusError returns an `error` response
	StatusError Status = "error"
)

func (Status) IsValid

func (s Status) IsValid() bool

IsValid returns true if a status is valid

func (Status) String

func (s Status) String() string

String representation of status

type Subscription added in v0.0.5

type Subscription struct {
	GUID             string `json:"guid"`
	Gateway          string `json:"gateway"`
	Offer            string `json:"offer"`
	Msisdn           string `json:"msisdn"`
	LinkID           string `json:"link_id"`
	ActivationDate   string `json:"activation_date"`
	DeactivationDate any    `json:"deactivation_date"`
	DeactivationType string `json:"deactivation_type"`
	Sms              []any  `json:"sms"`
	Created          string `json:"created"`
	Updated          string `json:"updated"`
}

Subscription represents the response that is returned when activating a subscription to an offer

type TokenResponse

type TokenResponse struct {
	Refresh string `json:"refresh"`
	Access  string `json:"access"`
}

TokenResponse is the data in the API response when logging in The access token is used as the X-bearer token when making API requests The refresh token is used to obtain a new access token when it expires

Jump to

Keyboard shortcuts

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