Go library for interacting with the Sendchamp API
go get github.com/fuadop/sendchamp
import "github.com/fuadop/sendchamp"
package main
import (
"log"
"fmt"
"github.com/fuadop/sendchamp"
)
var publicKey = &sendchamp.Keys{
PublicKey: "your-public-key",
} //pass as nil to use the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
var mode string = sendchamp.ModeLive // can be set to test mode (sendchamp.ModeTest) too
func main() {
//if the first parameter is nil, the package would look for the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
client := sendchamp.NewClient(publicKey, mode)
sender := "sendchamp"
to := []string{"2348023456087"}
message := "my sms message"
route := sendchamp.RouteInternational
res, err := client.NewSms().Send(sender, to, message, route)
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
// res field contains various values from res
// like res.Status, res.Message, res.Code, etc.
}
Checkout more examples in the test files and this example http server repo https://github.com/fuadop/my_server.
publicKey := &sendchamp.Keys{
PublicKey: "your-public-key",
} //pass as nil to use the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
mode := sendchamp.ModeLive
//if the first parameter is nil, the package would look for the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
client := sendchamp.NewClient(publicKey, mode)
sms := client.NewSms()
// routes
sendchamp.RouteNonDND = "non_dnd"
sendchamp.RouteDND = "dnd"
sendchamp.RouteInternational = "international"
// use cases (for creation of sender ID)
sendchamp.UseCaseTransactional = "transactional"
sendchamp.UseCaseMarketing = "marketing"
sendchamp.UseCaseTransactionalAndMarketing = "transaction_marketing"
Send
Send a message to one of more phone number
sender := "sendchamp" // slice of phone numbers to := []string{"2348143775374"} message := "Holla amigo!" route := sendchamp.RouteInternational res, err := sms.Send(sender, to, message, route) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
CreateSenderID
Create a sender ID
name := "mySenderId" sample := "Your otp is 200" useCase := sendchamp.UseCaseTransactional res, err := sms.CreateSenderID(name, sample, useCase) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
GetDeliveryReport
Get an SMS delivery report with its ID, refer to line 40 in sms_test.go
// res.Data.ID is the ID gotten from the send sms (sms.Send) method. res, err := sms.GetDeliveryReport(res.Data.ID.(string)) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.DeliveredAt, etc.
publicKey := &sendchamp.Keys{
PublicKey: "your-public-key",
} //pass as nil to use the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
mode := sendchamp.ModeLive
//if the first parameter is nil, the package would look for the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
client := sendchamp.NewClient(publicKey, mode)
voice := client.NewVoice()
sendchamp.VoiceTypeOutgoing = "outgoing"
Send
Send a voice message to a phone number. Refer to voice_test.go.
customerMobileNumbers := []string{"2348153207998"} message := "Test from golang test suite." voiceType := sendchamp.VoiceTypeOutgoing // only supported type currently var repeat uint = 3 // repeat the voice 3 times res, err := voice.Send(customerMobileNumbers, message, voiceType, repeat) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
publicKey := &sendchamp.Keys{
PublicKey: "your-public-key",
} //pass as nil to use the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
mode := sendchamp.ModeLive
//if the first parameter is nil, the package would look for the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
client := sendchamp.NewClient(publicKey, mode)
WalletBalance
Get your sendchamp wallet balance. Refer to wallet_test.go.
res, err := client.WalletBalance() // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc. fmt.Println(res.Data.AvailableBalance) // Balance in usd (type string) fmt.Println(res.Data.Details.BusinessAmount) // Balance in ngn (type float64) // use vscode intellisense/auto-complete to see more fields.
publicKey := &sendchamp.Keys{
PublicKey: "your-public-key",
} //pass as nil to use the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
mode := sendchamp.ModeLive
//if the first parameter is nil, the package would look for the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
client := sendchamp.NewClient(publicKey, mode)
verification := client.NewVerification()
// otp channels
sendchamp.OTPChannelSMS = "sms"
sendchamp.OTPChannelEmail = "email"
// otp token types
sendchamp.OTPTokenTypeNumeric = "numeric"
sendchamp.OTPTypeAlphaNumeric = "alphanumeric"
-
SendOTP
Send OTP to customer with sms or email channel. Refer to verification_test.go.
// create this outside the main function // to contain any fields of your type type metadata struct { FirstName string // important - export fields and add json annotations LastName string } payload := sendchamp.SendOTPPayload{ // specify channel , "sms" or "email" Channel: sendchamp.OTPChannelSMS, Sender: "Sendchamp", // specify "numeric" or "alphanumeric" TokenType: sendchamp.OTPTokenTypeNumeric, TokenLength: "4", // expiration time in minutes ExpirationTime: 6, // mobile number in the 13 digit format CustomerMobileNumber: "2348143222998", CustomerEmailAddress: "abc@gmail.com", // your metadata struct MetaData: metadata{"Shina", "Ebuka"}, } res, err := verification.SendOTP(payload) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc. // use vscode autocomplete to see more values
-
ConfirmOTP
Confirm OTP sent to user. Refer to verification_test.go.
code, reference := "01799", "de858be1-6240-48fb-916c-4d07d8c9f79d" res, err := verification.ConfirmOTP(code, reference) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc. // use vscode autocomplete/intellisense to see more properties
publicKey := &sendchamp.Keys{
PublicKey: "your-public-key",
} //pass as nil to use the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
mode := sendchamp.ModeLive
//if the first parameter is nil, the package would look for the enviroment variable 'SENDCHAMP_PUBLIC_KEY'
client := sendchamp.NewClient(publicKey, mode)
whatsapp := client.NewWhatsapp()
-
SendTemplate
Send a whatsapp message using template created on dashboard. Refer to whatsapp_test.go.
sender := "2348120678278" recipient := "2348153207998" templateCode := "912671fe-5f20-4b59-92ee-a33a62ea6a19" data := map[string]string{ "1": "Test", "2": "1234", "3": "10", } res, err := whatsapp.SendTemplate(sender, recipient, templateCode, data) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
-
SendText
Send a whatsapp text. Refer to whatsapp_test.go.
sender := "2348120678278" recipient := "2348153207998" message := "Hello World" res, err := whatsapp.SendText(sender, recipient, message) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
-
SendAudio
Send a whatsapp audio message. Refer to whatsapp_test.go.
sender := "2348120678278" recipient := "2348153207998" message := "I am the best" link := "https://sample-videos.com/audio/mp3/crowd-cheering.mp3" res, err := whatsapp.SendAudio(sender, recipient, message, link) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
-
SendVideo
Send a whatsapp video message. Refer to whatsapp_test.go.
sender := "2348120678278" recipient := "2348153207998" link := "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4" res, err := whatsapp.SendVideo(sender, recipient, link) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
-
SendSticker
Send a whatsapp sticker message. Refer to whatsapp_test.go.
sender := "2348120678278" recipient := "2348153207998" link := "https://studio.posit.us/api/samples/sticker.webp" res, err := whatsapp.SendSticker(sender, recipient, link) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
-
SendLocation
Send a location via whatsapp. Refer to whatsapp_test.go.
sender := "2348120678278" recipient := "2348153207998" longitude := -46.662787 latitude := -23.553610 name := "Robbu Brazil" address := "Av. AngΓ©lica, 2530 - Bela Vista, SΓ£o Paulo - SP, 01228-200" res, err := whatsapp.SendLocation(sender, recipient, longitude, latitude, name, address) // use err variables to check for errors like network errors, etc. if err != nil { // handle } // use res for api response // res.Status, res.Code, res.Message, res.Data.ID, res.Data.CreatedAt, etc.
PRs are greatly appreciated, help us build this hugely needed tool so anyone else can easily integrate sendchamp into their Go based projects and applications.
- Create a fork
- Create your feature branch: git checkout -b my-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request π
- Customer Service
- Customer Group Service
Thanks goes to these wonderful people (emoji key):
Aliyu Abubakar πΌ π π΅ π€ π§βπ« π¦ π¬ β π’ |
Fuad Olatunji π π» π π§ π¨ π‘ π‘οΈ π§ π |
Sayo Paul π» π π |
Sam π» π |
This project follows the all-contributors specification. Contributions of any kind welcome!