Categorygithub.com/Remitly/nexmo-go
modulepackage
0.8.5
Repository: https://github.com/remitly/nexmo-go.git
Documentation: pkg.go.dev

# README

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.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Installation

Find current and past releases on the releases page.

Recommended process (Go 1.13+)

Import the package and use it:

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

Older versions of Go (<= 1.12)

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()
    }

Make a Phone Call

The Voice API uses applications and private keys for authentication. To use this snippet you will need a Nexmo number (for the "from" field), and an application with an ID and a private key. You can learn more about creating applications on the Developer Portal.

	// get the private key ready, assume file name private.key
	file, file_err := os.Open("private.key")
	if file_err != nil {
		log.Fatal(file_err)
	}
	defer file.Close()

	key, _ := ioutil.ReadAll(file)

	auth := nexmo.NewAuthSet()
	auth.SetApplicationAuth(APPLICATION_ID, key)
	client := nexmo.NewClient(http.DefaultClient, auth)

	to := make([]interface{}, 1)
	to[0] = nexmo.PhoneCallEndpoint{
		Type:   "phone",
		Number: TO_NUMBER,
	}

	response, _, err := client.Call.CreateCall(nexmo.CreateCallRequest{
		From:      nexmo.PhoneCallEndpoint{"phone", NEXMO_NUMBER, ""},
		To:        to,
		AnswerURL: []string{ANSWER_URL},
		EventURL:  []string{EVENT_URL},
	})

	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Status:", response.Status)

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

# Functions

No description provided by the author
No description provided by the author
Get a new Client object with the auth configured.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Use the Application API to create and manage your applications.
API credentials to access the Nexmo APIs.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
For working with the Voice API.
No description provided by the author
CheckVerificationRequest verifies the phone number.
CheckVerificationResponse is the response to the verify phone number request.
The main client object.
ControlVerificationRequest is the request struct to send a control verification.
ControlVerificationResponse is the response to a control verification request.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Developer API allows configuration of account and balance checking.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetPhoneOutboundPricingRequest is the request object for DeveloperService.GetPhoneOutboundPricing.
No description provided by the author
No description provided by the author
No description provided by the author
Number Insights provides information at varying levels of detail (basic/standard/advanced) about a phone number.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SearchVerificationRequest is sent to search the status of a verification request.
SearchVerificationResponse is the response to a search verification request.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Work with the SMS API to send SMS messges.
No description provided by the author
No description provided by the author
StartVerificationRequest is the struct for initiating verification process for a phone number.
StartVerificationResponse is the struct for the response for the initiation of verification to a phone number.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Use Verify API for 2FA, passwordless login, or confirming that a user has given a correct phone number.
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author