communication

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package communication handles interactions with external APIs for messaging, such as Africa's Talking SMS service.

Index

Constants

This section is empty.

Variables

View Source
var ATBaseURL = "https://api.africastalking.com/version1/messaging/bulk"

baseURL defines the Africa's Talking API endpoint for bulk SMS messaging. Points to the version 1 messaging endpoint.

View Source
var MessageStatusCodes = map[int]string{
	100: "Processed",
	101: "Sent",
	102: "Queued",
	401: "RiskHold",
	402: "InvalidSenderId",
	403: "InvalidPhoneNumber",
	404: "UnsupportedNumberType",
	405: "InsufficientBalance",
	406: "UserInBlacklist",
	407: "CouldNotRoute",
	409: "DoNotDisturbRejection",
	500: "InternalServerError",
	501: "GatewayError",
	502: "RejectedByGateway",
}

MessageStatusCodes maps Africa's Talking API status codes to human-readable messages. Provides descriptions for common success and error states.

Functions

func AddAttachment added in v1.3.7

func AddAttachment(details *models.EmailDetails, filePath string) error

AddAttachment adds a file attachment to email details.

func AddBCC added in v1.3.7

func AddBCC(details *models.EmailDetails, recipients ...string) error

AddBCC adds BCC recipients to email details.

func AddCC added in v1.3.7

func AddCC(details *models.EmailDetails, recipients ...string) error

AddCC adds CC recipients to email details.

func AddRecipients added in v1.3.7

func AddRecipients(details *models.EmailDetails, recipients ...string) error

AddRecipients adds multiple recipients to email details.

func CreateEmailDetails added in v1.3.7

func CreateEmailDetails(from string, to []string, subject, text, html string) models.EmailDetails

CreateEmailDetails creates a new EmailDetails struct with common fields.

func GetDeliveryStatus added in v1.1.6

GetDeliveryStatus retrieves the delivery status of an SMS from the Beem API. Sends a GET request with query parameters and parses the response. Returns the delivery status response or an error if the request fails.

func GetStatusMessage

func GetStatusMessage(code int) string

GetStatusMessage retrieves the human-readable message for a given status code. Returns the corresponding message from MessageStatusCodes or a default unknown message.

func SendAfricasTalkingSMS added in v1.1.6

func SendAfricasTalkingSMS(payload *models.ATSMSPayload) (*models.ATSMSResponse, error)

SendAfricasTalkingSMS sends a bulk SMS request to the Africa's Talking API. Marshals the SMS payload, sends a POST request, and parses the response. Returns the SMS response or an error if the request fails.

func SendBeemSMS added in v1.1.6

func SendBeemSMS(payload *models.BeemSMSPayload) (*models.BeemSMSResponse, error)

SendBeemSMS sends an SMS request to the Beem API. Constructs the request payload, sends a POST request, and parses the response. Returns the SMS response or an error if the request fails.

func SendEmail

func SendEmail(smtpHost string, smtpPort int, username, password string, InsecureSkipVerify bool, details models.EmailDetails) error

SendEmail sends an email using the provided SMTP server details and email content. Configures an email with sender, recipients, subject, body, and attachments. Connects to the SMTP server and sends the email, supporting TLS configuration. Returns an error if the email sending fails, otherwise nil.

func SendEmailWithConfig added in v1.3.7

func SendEmailWithConfig(config EmailConfig, details models.EmailDetails) error

SendEmailWithConfig sends an email using the provided configuration.

func SendEmailWithRetry added in v1.3.7

func SendEmailWithRetry(config EmailConfig, details models.EmailDetails) error

SendEmailWithRetry sends an email with retry logic for transient failures.

func SendHTMLEmail added in v1.3.7

func SendHTMLEmail(smtpHost string, smtpPort int, username, password string, from string, to []string, subject, html string) error

SendHTMLEmail is a convenience function for sending HTML emails.

func SendTextEmail added in v1.3.7

func SendTextEmail(smtpHost string, smtpPort int, username, password string, from string, to []string, subject, text string) error

SendTextEmail is a convenience function for sending plain text emails.

func ValidateEmailAddress added in v1.3.7

func ValidateEmailAddress(email string) bool

ValidateEmailAddress validates an email address format.

Types

type EmailConfig added in v1.3.7

type EmailConfig struct {
	SMTPHost           string        // SMTPHost is the SMTP server hostname
	SMTPPort           int           // SMTPPort is the SMTP server port
	Username           string        // Username for SMTP authentication
	Password           string        // Password for SMTP authentication
	InsecureSkipVerify bool          // InsecureSkipVerify controls TLS certificate verification
	Timeout            time.Duration // Timeout for email sending operations
	MaxRetries         int           // MaxRetries specifies maximum retry attempts
	RetryDelay         time.Duration // RetryDelay specifies delay between retries
}

EmailConfig holds configuration for email sending operations.

func LoadEmailConfig added in v1.3.7

func LoadEmailConfig() EmailConfig

LoadEmailConfig loads email configuration with defaults.

Jump to

Keyboard shortcuts

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