Skip to content

AnoRebel/BriqGoSdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Briq Go SDK (Unofficial, Untested)

A Go client library for the Briq messaging platform API. This SDK provides programmatic access to Briq's SMS messaging services, including instant messaging, campaign management, and workspace organization.

Features

  • Instant Messaging: Send immediate SMS messages to recipients
  • Campaign Management: Create and manage messaging campaigns
  • Workspace Management: Organize campaigns within workspaces
  • Message Logging: Track message history and delivery status
  • Authentication: API key-based authentication with environment variable support

Installation

go get github.com/AnoRebel/BriqGoSdk

Quick Start

Basic Usage

package main

import (
    "fmt"
    "log"

    "github.com/AnoRebel/BriqGoSdk/client"
)

func main() {
    // Initialize client with API key
    apiKey := "your-api-key"
    client := client.NewClient(&apiKey, nil)

    // Use the client to make API calls
    resp, err := client.Get("workspaces", nil)
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Status: %d\n", resp.StatusCode)
}

Using Environment Variables

Create a .env file in your project root:

BRIQ_API_KEY=your-api-key
BRIQ_BASE_URL=http://karibu.briq.tz  # optional

Then initialize the client without parameters:

client := client.NewClient(nil, nil)  // Will load from environment

Working with Data Models

The SDK provides structured data models for all API operations:

import (
    "github.com/AnoRebel/BriqGoSdk/client"
    "github.com/AnoRebel/BriqGoSdk/models"
)

// Create a workspace
workspaceReq := models.WorkspaceCreateRequest{
    Name:        "My Workspace",
    Description: "A workspace for my campaigns",
}

// Validate the request
if err := workspaceReq.Validate(); err != nil {
    log.Fatal("Invalid request:", err)
}

// Send instant message
messageReq := models.InstantMessageRequest{
    Content:    "Hello from Briq Go SDK!",
    Recipients: []string{"+1234567890", "+0987654321"},
    SenderID:   "sender123",
}

if err := messageReq.Validate(); err != nil {
    log.Fatal("Invalid message request:", err)
}

API Reference

Client Methods

The main client provides several HTTP convenience methods:

// GET request with query parameters
resp, err := client.Get("endpoint", map[string]string{
    "param1": "value1",
    "param2": "value2",
})

// POST request with JSON body
data := map[string]interface{}{
    "name": "example",
    "value": 123,
}
resp, err := client.Post("endpoint", data)

// PATCH request with JSON body
resp, err := client.Patch("endpoint", data)

// Generic request method
resp, err := client.Request("PUT", "endpoint", data, params)

API Modules

The client provides access to different API modules:

  • client.Workspace: Workspace management operations
  • client.Campaign: Campaign management operations
  • client.Message: Message sending and history operations

Data Models

The SDK includes comprehensive data models for type-safe API interactions:

Workspace Models

  • WorkspaceCreateRequest: Create new workspace
  • WorkspaceUpdateRequest: Update existing workspace
  • WorkspaceResponse: Workspace API response

Campaign Models

  • CampaignCreateRequest: Create new campaign
  • CampaignUpdateRequest: Update existing campaign
  • CampaignResponse: Campaign API response

Message Models

  • InstantMessageRequest: Send instant messages
  • CampaignMessageRequest: Send campaign messages
  • MessageResponse: Message API response
  • MessageLogResponse: Message delivery logs

Generic Models

  • APIErrorResponse: API error responses
  • ListResponse: Paginated list responses

All request models include built-in validation methods:

req := models.WorkspaceCreateRequest{Name: "Test"}
if err := req.Validate(); err != nil {
    // Handle validation error
}

Configuration

The SDK supports configuration through environment variables or direct initialization:

Environment Variable Description Default
BRIQ_API_KEY Your Briq API key Required
BRIQ_BASE_URL Base URL for the API http://karibu.briq.tz

Error Handling

The SDK provides custom error types for different scenarios:

  • BriqAuthError: Authentication failures (401)
  • BriqAPIError: General API errors (4xx, 5xx)
  • BriqRequestError: Request construction or network errors
resp, err := client.Get("endpoint", nil)
if err != nil {
    switch e := err.(type) {
    case *exceptions.BriqAuthError:
        fmt.Println("Authentication failed:", e.Message)
    case *exceptions.BriqAPIError:
        fmt.Printf("API error %d: %s\n", e.Code, e.Message)
    default:
        fmt.Println("Request error:", err)
    }
}

Development

Building

go build ./...

Testing

go test ./...

Formatting

go fmt ./...
go vet ./...

License

This project is licensed under the same terms as the original Python SDK.

Contributing

Contributions are welcome! Please ensure all code is properly formatted and tested before submitting pull requests.

About

This is the Briq Go SDK - a Go client library for the Briq messaging platform API. It's a port of the Python [Briq](https://github.com/BRIQ-BLOCK/BriqPythonSdk) SDK to Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages