sms

package module
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 7 Imported by: 0

README

A package for sending SMS message via AWS SNS

GitHub tag (latest SemVer pre-release) GitHub go.mod Go version GitHub Workflow Status Go Report Card PkgGoDev

Introduction

  • Send emails via AWS SNS

Example

package main

import (
	"context"

	sms "github.com/gofor-little/aws-sms"
)

func main() {
	// Initialize the SMS package.
	if err := sms.Initialize("AWS_PROFILE", "AWS_REGION"); err != nil {
		panic(err)
	}

	// Build the SMS data.
	data := sms.Data{
		SenderID: "ExampleApp",
		PhoneNumber: "+61412345678",
		Message: "Example Message",
	}

	// Send the SMS message.
	if _, err := sms.Send(context.Background(), data); err != nil {
		panic(err)
	}
}

Testing

Ensure the following environment variables are set, usually with a .env file.

  • AWS_PROFILE (an AWS CLI profile name)
  • AWS_REGION (a valid AWS region)
  • TEST_SMS_RECIPIENTS (a comma separated list of valid phone numbers including country code)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SNSClient is used to interact with AWS SNS.
	SNSClient *sns.Client
)

Functions

func Initialize

func Initialize(ctx context.Context, profile string, region string) error

Initialize will initialize the sms package. Both the profile and region parameters are optional if authentication can be achieved via another method. For example, environment variables or IAM roles.

func Send

func Send(ctx context.Context, data Data) (string, error)

Send builds an SMS message and sends it.

Types

type Data

type Data struct {
	SenderID    string `json:"senderId"`
	PhoneNumber string `json:"phoneNumber"`
	Message     string `json:"message"`
}

Data is the data required to build and send an SMS message.

Jump to

Keyboard shortcuts

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