• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    Go
  • License
    BSD 2-Clause "Sim...
  • Created over 10 years ago
  • Updated almost 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MessageBird's REST API for Go

MessageBird's REST API for Go

This repository contains the open source Go client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com.

Build Status PkgGoDev

Requirements

  • Sign up for a free MessageBird account
  • Create a new access key in the dashboard.
  • An application written in Go to make use of this API

Installation

The easiest way to use the MessageBird API in your Go project is to install it using go get:

$ go get github.com/messagebird/go-rest-api/v9

Examples

Here is a quick example on how to get started. Assuming the go get installation worked, you can import the messagebird package like this:

import "github.com/messagebird/go-rest-api/v9"

Then, create an instance of messagebird.Client. It can be used to access the MessageBird APIs.

// Access keys can be managed through our dashboard.
accessKey := "your-access-key"

// Create a client.
client := messagebird.New(accessKey)

// Request the balance information, returned as a balance.Balance object.
balance, err := balance.Read(client)
if err != nil {
	// Handle error.
	return
}

// Display the results.
fmt.Println("Payment: ", balance.Payment)
fmt.Println("Type:", balance.Type)
fmt.Println("Amount:", balance.Amount)

This will give you something like:

$ go run example.go
Payment: prepaid
Type: credits
Amount: 9

Please see the other examples for a complete overview of all the available API calls.

Errors

When something goes wrong, our APIs can return more than a single error. They are therefore returned by the client as "error responses" that contain a slice of errors.

It is important to notice that the Voice API returns errors with a format that slightly differs from other APIs. For this reason, errors returned by the voice package are of type voice.ErrorResponse. It contains voice.Error structs. All other packages return messagebird.ErrorResponse structs that contain a slice of messagebird.Error.

An example of "simple" error handling is shown in the example above. Let's look how we can gain more in-depth insight in what exactly went wrong:

import "github.com/messagebird/go-rest-api/v9"
import "github.com/messagebird/go-rest-api/v9/sms"

// ...

_, err := sms.Read(client, "some-id")
if err != nil {
	mbErr, ok := err.(messagebird.ErrorResponse)
	if !ok {
		// A non-MessageBird error occurred (no connection, perhaps?) 
		return err
	}
	
	fmt.Println("Code:", mbErr.Errors[0].Code)
	fmt.Println("Description:", mbErr.Errors[0].Description)
	fmt.Println("Parameter:", mbErr.Errors[0].Parameter)
}

voice.ErrorResponse is very similar, except that it holds voice.Error structs - those contain only Code and Message (not description!) fields:

import "github.com/messagebird/go-rest-api/v9/voice"

// ...

_, err := voice.CallFlowByID(client, "some-id")
if err != nil {
	vErr, ok := err.(voice.ErrorResponse)
	if !ok {
    		// A non-MessageBird (Voice) error occurred (no connection, perhaps?) 
    		return err
    }
	
	fmt.Println("Code:", vErr.Errors[0].Code)
	fmt.Println("Message:", vErr.Errors[0].Message)
}

Documentation

Complete documentation, instructions, and examples are available at: https://developers.messagebird.com.

Upgrading

If you're upgrading from older versions, please read the Messagebird go-rest-api upgrading guide.

License

The MessageBird REST Client for Go is licensed under The BSD 2-Clause License. Copyright (c) 2022 MessageBird

More Repositories

1

sachet

SMS alerts for Prometheus' Alertmanager
Go
216
star
2

php-rest-api

This repository contains the open source PHP client for MessageBird's REST API.
PHP
158
star
3

messagebird-nodejs

The open source Node.js client for MessageBird's REST API
JavaScript
105
star
4

pushprom

Pushprom is a proxy to the Prometheus Go client.
Go
80
star
5

python-rest-api

This repository contains the open source Python client for MessageBird's REST API.
Python
65
star
6

csharp-rest-api

This repository contains the open source C# client for MessageBird's REST API.
C#
54
star
7

java-rest-api

This repository contains the open source Java client for MessageBird's REST API.
Java
50
star
8

clickhouse-postgres-fdw

This project provides federated access to Clickhouse cluster from Postgres, with the ability to write FDW API functions in GO.
Go
45
star
9

ruby-rest-api

MessageBird's REST API for Ruby
Ruby
37
star
10

beanstalkd_exporter

A beanstalkd stats exporter for Prometheus
Go
34
star
11

slackincident

This node.js app is allowing you to start an incident management process via a Slack slash command.
JavaScript
27
star
12

gcppromd

Prometheus GCP discovery
Go
18
star
13

mysql-monitor

A tool to monitor mysql databases
Go
12
star
14

firestore-send-msg

Source code for MessageBird Firebase send message extension
TypeScript
11
star
15

python-grpc-argument-validator

Python
7
star
16

pushprom-php-client

PHP client for Pushprom
PHP
6
star
17

dart-rest-api

MessageBird's REST API for Dart
Dart
5
star
18

messagebird-magento-integration

Integrate magento (v2) with the MessageBird Flow Builder
PHP
3
star
19

messagebird-magento

PHP
3
star
20

pushprom-yii2-client

Yii 2 client for Pushprom
PHP
2
star
21

openapi-specs

Open API specifications of MessageBird public API's
1
star