https://github.com/levpay/infobip
Infobip API client library in Go
https://github.com/levpay/infobip
golang golang-package infobip infobip-api sms
Last synced: 5 months ago
JSON representation
Infobip API client library in Go
- Host: GitHub
- URL: https://github.com/levpay/infobip
- Owner: levpay
- License: mit
- Created: 2018-03-20T20:44:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-06T19:37:06.000Z (about 6 years ago)
- Last Synced: 2024-06-20T01:57:37.588Z (almost 2 years ago)
- Topics: golang, golang-package, infobip, infobip-api, sms
- Language: Go
- Homepage: https://dev.infobip.com/getting-started
- Size: 12.7 KB
- Stars: 7
- Watchers: 9
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# infobip
Infobip API client library in Go
[](https://travis-ci.org/levpay/infobip)
[](https://godoc.org/github.com/levpay/infobip)
[](https://goreportcard.com/report/github.com/levpay/infobip)
## Usage
To initiate a client, you should use the `infobip.ClientWithBasicAuth` func. This will returns a pointer to `infobip.Client` and allows to you use features from service.
### Sending a single message
The func needs a `infobip.Message` struct. That struct consists of the following attributes:
| Attribute | Type | Description |
|-----------|------|-------------|
| From | string | Represents a sender ID which can be alphanumeric or numeric |
| To | string | Message destination address |
| Text | string | Text of the message that will be sent |
It has a func to validate the `From` and `To` attributes, according to Infobip docs, and it is used into all funcs that make a request to the service. The following code is a basic example of the validate func:
```go
package main
import (
"log"
"github.com/levpay/infobip"
)
func main() {
m := infobip.Message{
From: "Company", // or company number
To: "41793026727",
Text: "This is an example of the body of the SMS message",
}
err := m.Validate()
if err != nil {
log.Fatalf("Infobip message error: %v", err)
}
}
```
Finally, the following code is a full example to send a single message to Infobip service:
```go
package main
import (
"fmt"
"log"
"github.com/levpay/infobip"
)
func main() {
client := infobip.ClientWithBasicAuth("foo", "bar")
r, err := client.SingleMessage(m) // "m" refers to the variable from the previous example
if err != nil {
log.Fatalf("Infobip error: %v", err)
}
fmt.Printf("Infobip response: %v", r)
}
```
### Sending a advanced message
The func needs a `infobip.BulkMessage` struct. That struct consists of the following attributes:
| Attribute | Type | Description |
|-----------|------|-------------|
| ID | string | The ID which uniquely identifies the request |
| Messages | slice of Message | Message values |
And the `infobip.Message` struct consists in the following attributes:
| Attribute | Type | Description |
|-----------|------|-------------|
| From | string | Represents a sender ID which can be alphanumeric or numeric |
| Destinations | slice of Destination | Destination values |
| Text | string | Text of the message that will be sent |
| Transliteration | string | Conversion of a message text from one script to another |
| LanguageCode | string | Code for language character set of a message text |
And finally the `infobip.Destination` struct consists in the following attributes:
| Attribute | Type | Description |
|-----------|------|-------------|
| ID | string | The ID that uniquely identifies the message sent |
| To | string | Message destination address |
The following code is a basic example of the validate func:
```go
package main
import (
"log"
"github.com/levpay/infobip"
)
func main() {
m := infobip.BulkMessage{
Messages: []infobip.Message{
infobip.Message{
From: "Company", // or company number
Destinations: []infobip.Destination{
infobip.Destination{
To: "41793026727",
},
},
Text: "This is an example of the body of the SMS message",
Transliteration: "PORTUGUESE",
LanguageCode: "PT",
},
},
}
err := m.Validate()
if err != nil {
log.Fatalf("Infobip message error: %v", err)
}
}
```
Finally, the following code is a full example to send an advanced message to Infobip service:
```go
package main
import (
"fmt"
"log"
"github.com/levpay/infobip"
)
func main() {
client := infobip.ClientWithBasicAuth("foo", "bar")
r, err := client.AdvancedMessage(m) // "m" refers to the variable from the previous example
if err != nil {
log.Fatalf("Infobip error: %v", err)
}
fmt.Printf("Infobip response: %v", r)
}
```