MCPcopy Index your code
hub / github.com/casdoor/go-sms-sender

github.com/casdoor/go-sms-sender @v0.25.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.25.0 ↗ · + Follow
83 symbols 187 edges 20 files 2 documented · 2% 1 cross-repo links updated 19mo agov0.25.0 · 2024-11-29★ 75
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-sms-sender

Go Report Card Go Go Reference GitHub release (latest SemVer)

This is a powerful open-source library for sending SMS message, which will help you to easily integrate with the popular SMS providers. And it has been applied to Casdoor, if you still don’t know how to use it after reading README.md, you can refer to it.

We support the following SMS providers, welcome to contribute.

Installation

Use go get to install:

go get github.com/casdoor/go-sms-sender

How to use

Create Client

Different SMS providers need to provide different configuration, but we support a unit API as below to init and get the SMS client.

func NewSmsClient(provider string, accessId string, accessKey string, sign string, template string, other ...string) (SmsClient, error)
  • provider the name of SMS provider, such as Aliyun SMS
  • accessId
  • accessKey
  • sign the sign name
  • template the template code
  • other other configuration

Send Message

After initializing the SMS client, we can use the following API to send message.

SendMessage(param map[string]string, targetPhoneNumber ...string) error
  • param the parameters in the SMS template, such as 6 random numbers
  • targetPhoneNumber the receivers, such as +8612345678910

Example

Twilio

Please get necessary information from Twilio console

package main

import "github.com/casdoor/go-sms-sender"

func main() {
    client, err := go_sms_sender.NewSmsClient(go_sms_sender.Twilio, "ACCOUNT_SID", "AUTH_TOKEN", "", "TEMPLATE_CODE")
    if err != nil {
        panic(err)
    }

    params := map[string]string{}
    params["code"] = "123456"
    phoneNumer := "+8612345678910"
    err = client.SendMessage(params, phoneNumer)
    if err != nil {
        panic(err)
    }
}

Aliyun

Before you begin, you need to sign up for an Aliyun account and retrieve your Credentials.

package main

import "github.com/casdoor/go-sms-sender"

func main() {
    client, err := go_sms_sender.NewSmsClient(go_sms_sender.Aliyun, "ACCESS_KEY_ID", "ACCESS_KEY_SECRET", "SIGN_NAME", "TEMPLATE_CODE")
    if err != nil {
        panic(err)
    }

    params := map[string]string{}
    params["code"] = "473956"
    phoneNumer := "+8612345678910"
    err = client.SendMessage(params, phoneNumer)
    if err != nil {
        panic(err)
    }
}

Tencent Cloud

package main

import "github.com/casdoor/go-sms-sender"

func main() {
    client, err := go_sms_sender.NewSmsClient(go_sms_sender.TencentCloud, "secretId", "secretKey", "SIGN_NAME", "TEMPLATE_CODE", "APP_ID")
    if err != nil {
        panic(err)
    }

    params := map[string]string{}
    params["0"] = "473956"
    phoneNumer := "+8612345678910"
    err = client.SendMessage(params, phoneNumer)
    if err != nil {
        panic(err)
    }
}

Netgsm

  • yourAccessId: is KullaniciAdi
  • yourAccessKey: is Sifre
  • yourSign: is Baslik
package main

import "github.com/casdoor/go-sms-sender"

func main() {
    client, err := go_sms_sender.NewSmsClient(go_sms_sender.Netgsm, "yourAccessId", "yourAccessKey", "yourSign", "yourTemplate")
    if err != nil {
        panic(err)
    }

    params := map[string]string{}
    params["param1"] = "value1"
    params["param2"] = "value2"
    phoneNumer := "+8612345678910"
    err = client.SendMessage(params, phoneNumer)
    if err != nil {
        panic(err)
    }
}

Oson Sms

  • senderId: is login
  • secretAccessKey: is hash
  • signName: is from
  • templateCode: is message
package main

func main() {
    client, err := go_sms_sender.NewSmsClient(go_sms_senderOsonSms, "senderId", "secretAccessKey", "signName", "templateCode")
    if err != nil {
        panic(err)
    }

    params := map[string]string{}
    params["code"] = "123456"
    phoneNumer := "+992123456789"
    err = client.SendMessage(params, phoneNumer)
    if err != nil {
        panic(err)
    }
}

Running Tests

To run tests for the go-sms-sender library, navigate to the root folder of the project in your terminal and execute the following command:

go test -v ./...

you can modify mock_test.go file to mock an other tests

License

This project is licensed under the Apache 2.0 license.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Struct 31
Function 30
Method 21
Interface 1

Languages

Go100%

Modules by API surface

infobip.go8 symbols
submail.go6 symbols
huawei.go6 symbols
gccpay.go6 symbols
netgsm.go5 symbols
msg91.go5 symbols
azure.go5 symbols
oson.go4 symbols
huyi.go4 symbols
aliyun.go4 symbols
volcengine.go3 symbols
unisms.go3 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add go-sms-sender \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page