![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
github.com/messagebird/go-rest-api/v7
This repository contains the open source Go client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com.
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/v7
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/v7"
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.
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/v7"
import "github.com/messagebird/go-rest-api/v7/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/v7/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)
}
To use the whatsapp sandbox you need to enable the FeatureConversationsAPIWhatsAppSandbox
feature.
client.EnableFeatures(messagebird.FeatureConversationsAPIWhatsAppSandbox)
Complete documentation, instructions, and examples are available at: https://developers.messagebird.com.
If you're upgrading from older versions, please read the Messagebird go-rest-api
upgrading guide.
The MessageBird REST Client for Go is licensed under The BSD 2-Clause License. Copyright (c) 2014, 2015, MessageBird
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.