Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tizz98/magicbell-go
Unofficial Go API Library for MagicBell
https://github.com/tizz98/magicbell-go
golang golang-api magicbell
Last synced: 9 days ago
JSON representation
Unofficial Go API Library for MagicBell
- Host: GitHub
- URL: https://github.com/tizz98/magicbell-go
- Owner: tizz98
- License: mit
- Created: 2021-02-07T18:25:34.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-09T22:39:18.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T02:16:53.778Z (5 months ago)
- Topics: golang, golang-api, magicbell
- Language: Go
- Homepage: https://www.magicbell.com/docs
- Size: 64.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# magicbell-go: Unofficial Go API Library for MagicBell
[![Go Reference](https://pkg.go.dev/badge/github.com/tizz98/magicbell-go.svg)](https://pkg.go.dev/github.com/tizz98/magicbell-go)
[`mbctl`](#mbctl-cli-installation)**This is still a work in progress, expect breaking changes until v1.0.0**
## What is MagicBell?
See https://magicbell.io/.
## Library Installation
```bash
go get -u github.com/tizz98/magicbell-go
```## Library Usage
### Send Notification
```go
package mainimport (
"fmt""github.com/tizz98/magicbell-go"
)func main() {
magicbell.Init(magicbell.Config{
APIKey: "my-key",
APISecret: "my-secret",
})notification, _ := magicbell.CreateNotification(magicbell.CreateNotificationRequest{
Title: "Welcome to MagicBell",
Recipients: []magicbell.NotificationRecipient{
{Email: "[email protected]"},
{ExternalID: "some-id"},
},
Content: "The notification inbox for your product. Get started in minutes.",
CustomAttributes: map[string]interface{}{
"order": map[string]string{
"id": "1234567",
"title": "A title you can use in your templates",
},
},
ActionURL: "https://developer.magicbell.io",
Category: "new_message",
})
fmt.Printf("Created notification %s\n", notification.ID)
}
```### Create user
```go
package mainimport (
"fmt"
"github.com/tizz98/magicbell-go"
)func main() {
magicbell.Init(magicbell.Config{
APIKey: "my-key",
APISecret: "my-secret",
})user, _ := magicbell.CreateUser(magicbell.CreateUserRequest{
ExternalID: "56780",
Email: "[email protected]",
FirstName: "Hana",
LastName: "Mohan",
CustomAttributes: map[string]interface{}{
"plan": "enterprise",
"pricing_version": "v10",
"preferred_pronoun": "She",
},
})fmt.Printf("%#v\n", user)
}
```## `mbctl` CLI Installation
Download the latest release for your OS from https://github.com/tizz98/magicbell-go/releases
and add the binary to your `PATH`.## `mbctl` CLI Usage
```bash
mbctl --version
mbctl --help
```### Initialize Config
This will save your API key and API secret in a `config.yaml` file.
```bash
mbctl config init
```### Notification Commands
Commands related to Notifications.
#### Create Notification
Send a notification to a set of users. Separate multiple recipients with a comma.
Any string with an `@` will be considered an email address and sent to the API in that field.```bash
mbctl notifications create \
--title="CLI test" \
--recipients [email protected],[email protected],my-external-id \
--content="Notification content" \
--action-url https://google.com \
--category new_message
```### User Commands
Commands related to Users.
#### Generate HMAC
Generate and return a base64-encoded HMAC signature of the provided email.
The HMAC key is the API secret.```bash
mbctl users generate-hmac [email protected]
```