modulepackage
0.0.7
Repository: https://github.com/ndolestudio/httpsms-go.git
Documentation: pkg.go.dev
# README
httpsms-go
This package provides a generic go
client template for the Http SMS Api
Installation
httpsms-go
is compatible with modern Go releases in module mode, with Go installed:
go get github.com/NdoleStudio/httpsms-go
Alternatively the same can be achieved if you use import
in a package:
import "github.com/NdoleStudio/httpsms-go"
Implemented
- Messages
-
POST /v1/messages/send
: Send a new SMS -
GET /v1/messages
: Get list of messages which are exchanged between 2 phone numbers.
-
- Heartbeats
-
GET /v1/heartbeats
: Get the heartbeats of an Android Phone
-
- Message Threads
-
GET /v1/message-threads
: Get the message threads of a phone number -
DELETE v1/message-threads/:messageThreadID
: Delete a message thread
-
- Cipher
-
Encrypt
: Encrypt the content of a message to cipher text -
Decrypt
: Decrypt an encrypted message content to plain text
-
Usage
Initializing the Client
An instance of the client can be created using httpsms.New()
.
package main
import (
"github.com/NdoleStudio/httpsms-go"
)
func main() {
client := htpsms.New(htpsms.WithDelay(200))
}
Error handling
All API calls return an error
as the last return object. All successful calls will return a nil
error.
_, response, err := client.Messages.Send(context.Background())
if err != nil {
//handle error
}
Messages
POST /v1/messages/send
: Send a new SMS Message
message, response, err := client.Messages.Send(context.Background(), &MessageSendParams{
Content: "This is a sample text message",
From: "+18005550199",
To: "+18005550100",
})
if err != nil {
log.Fatal(err)
}
log.Println(message.Code) // 202
Testing
You can run the unit tests for this client from the root directory using the command below:
go test -v
License
This project is licensed under the MIT License - see the LICENSE file for details
# Functions
New creates and returns a new campay.Client from a slice of campay.ClientOption.
WithAPIKey sets the api key for the httpsms API.
WithBaseURL sets the base url for the httpsms API.
WithHTTPClient sets the underlying HTTP client used for API requests.
# Constants
EventTypeMessageCallMissed is emitted when a new message is sent.
EventTypeMessagePhoneDelivered is emitted when the phone delivers a message.
EventTypeMessagePhoneReceived is emitted when a new message is received by a mobile phone.
EventTypeMessagePhoneSent is emitted when the phone sends a message.
EventTypeMessageSendExpired is emitted when the phone a message expires.
EventTypeMessageSendFailed is emitted when the phone could not send.
EventTypePhoneHeartbeatOffline is emitted when the phone is missing a heartbeat.
EventTypePhoneHeartbeatOnline is emitted when the phone is missing a heartbeat.
# Structs
No description provided by the author
Client is the campay API client.
Heartbeat represents is a pulse from an active phone.
HeartbeatIndexParams is the payload for fetching entities.Heartbeat of a phone number.
Message represents and incoming or outgoing SMS message.
MessageIndexParams is the payload fetching entities.Message sent between 2 numbers.
MessageSendParams is the request payload for sending a message.
MessageThread represents a message thread between 2 phone numbers.
MessageThreadIndexParams is the payload fetching entities.MessageThread sent between 2 numbers.
Response captures the http response.
# Interfaces
Option is options for constructing a client.
# Type aliases
CipherService is used to encrypt and decrypt SMS messages using the AES-256 algorithm.
HeartbeatService is the API client for the `/heartbeats` endpoint.
MessageService is the API client for the `/` endpoint.
MessageThreadService is the API client for the `/message-threads` endpoint.