Skip to content
The Golang Server SDK for Nexmo APIs. Still at an early stage but very much loved!
Go Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sling Added New function to nexmo.go, NewClient kept for backwards compat (#4 Aug 20, 2019
.codecov.yml Codecov (#1) May 3, 2017
.gitattributes Skeletal test for CreateApplication. (#18) Aug 23, 2019
.gitignore Update README with coverage badge. Apr 24, 2017
.travis.yml Update golang versions in travis. (#12) Aug 19, 2019
CONTRIBUTING.md Update README, add CONTRIBUTING (#15) Aug 21, 2019
LICENSE.txt Remove one item from TODO list. Apr 23, 2017
README.md Remove the word "unofficial" from the README Aug 22, 2019
TODO.md
application.go Added New function to nexmo.go, NewClient kept for backwards compat (#4 Aug 20, 2019
application_base.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
application_test.go Skeletal test for CreateApplication. (#18) Aug 23, 2019
auth.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
call_base.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
calls.go Added New function to nexmo.go, NewClient kept for backwards compat (#4 Aug 20, 2019
developer_account_balance.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
developer_account_pricing.go Added New function to nexmo.go, NewClient kept for backwards compat (#4 Aug 20, 2019
developer_base.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
go.mod
go.sum
insight.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
insight_base.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
insight_test.go Improved testing (#11) Aug 19, 2019
nexmo.go Added New function to nexmo.go, NewClient kept for backwards compat (#4 Aug 20, 2019
nexmo_test.go Added New function to nexmo.go, NewClient kept for backwards compat (#4 Aug 20, 2019
sms.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
sms_base.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
sms_test.go
structs.go Enums & Tests (#13) Aug 20, 2019
verify.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019
verify_base.go Adding a few basic comments to give GoDoc some content (#10) Aug 20, 2019

README.md

Nexmo Server SDK For Go

Go Report Card Build Status Coverage GoDoc

This is the community-supported Golang library for Nexmo. It has support for most of our APIs, but is still under active development. Issues, pull requests and other input is very welcome.

If you don't already know Nexmo: We make telephony APIs. If you need to make a call, check a phone number, or send an SMS then you are in the right place! If you don't have a Nexmo yet, you can sign up for a Nexmo account and get some free credit to get you started.

Installation

To install the package, use go get:

go get github.com/nexmo-community/nexmo-go

Or import the package into your project and then do go get ..

Usage

Here are some simple examples to get you started. If there's anything else you'd like to see here, please open an issue and let us know! Be aware that this library is still at an alpha stage so things may change between versions.

Number Insight

package main

import (
	"fmt"
	"net/http"

	"log"

	"github.com/nexmo-community/nexmo-go"
)

func main() {
	auth := nexmo.NewAuthSet()
	auth.SetAPISecret(API_KEY, API_SECRET)
	client := nexmo.New(http.DefaultClient, auth)
	insight, _, err := client.Insight.GetBasicInsight(nexmo.BasicInsightRequest{
		Number: PHONE_NUMBER,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Country Name:", insight.CountryName)
	fmt.Println("Local Formatting:", insight.NationalFormatNumber)
	fmt.Println("International Formatting:", insight.InternationalFormatNumber)
}

Sending SMS

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/nexmo-community/nexmo-go"
)

func main() {
	auth := nexmo.NewAuthSet()
	auth.SetAPISecret(API_KEY, API_SECRET)

	client := nexmo.NewClient(http.DefaultClient, auth)
	smsReq := nexmo.SendSMSRequest {
	    From: FROM_NUMBER,
	    To: TO_NUMBER,
	    Text: "This message comes to you from Nexmo via Golang",
    }

	callR, _, err := client.SMS.SendSMS(smsReq)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Status:", callR.Messages[0].Status)
}

Receiving SMS

package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {

	http.HandleFunc("/webhooks/inbound-sms", func(w http.ResponseWriter, r *http.Request) {
		params := r.URL.Query()
		fmt.Println("SMS from " + params["msisdn"][0] + ": " + string(params["text"][0]))
	})

	http.ListenAndServe(":8080", nil)
}

Starting a Verify Request

    package main

    import (
        "fmt"
        "github.com/nexmo-community/nexmo-go"
        "log"
        "net/http"
    )

    func verify_start() {
        auth := nexmo.NewAuthSet()
        auth.SetAPISecret(API_KEY, API_SECRET)
        client := nexmo.NewClient(http.DefaultClient, auth)
        verification, _, err := client.Verify.Start(nexmo.StartVerificationRequest{
            Number: PHONE_NUMBER,
            Brand:  "Golang Docs",
        })
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println("Request ID:", verification.RequestID)
    }

    func main() {
        verify_start()
    }

Confirming a Verify Code

    package main

    import (
        "fmt"
        "github.com/nexmo-community/nexmo-go"
        "log"
        "net/http"
    )

    func verify_check() {
        auth := nexmo.NewAuthSet()
        auth.SetAPISecret(API_KEY, API_SECRET)
        client := nexmo.NewClient(http.DefaultClient, auth)
        response, _, err := client.Verify.Check(nexmo.CheckVerificationRequest{
            RequestID: REQUEST_ID,
            Code:      CODE,
        })
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println("Status:", response.Status)
        fmt.Println("Cost:", response.Price)
    }

    func main() {
        verify_check()
    }

Getting Help

We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

Further Reading

You can’t perform that action at this time.