# iMessage Go SDK

> Send and receive iMessages from Go with Blooio’s official Go SDK, featuring context-aware requests, typed API models, retries, and webhook verification.

Source: https://blooio.com/integrations/api/imessage-go-sdk

## Overview

The Blooio Go SDK is an idiomatic Go client for the Blooio iMessage API. It provides typed request and response structs for API endpoints and webhook events, context-aware requests, built-in retry handling, and signature verification for inbound webhooks.

The SDK has no runtime dependencies beyond the Go standard library and supports Go 1.21 or later.

## Installation

Install the latest SDK within a Go module:

```bash
go get github.com/Blooio/blooio-go-sdk@latest
```

Import the API client package:

```go
import "github.com/Blooio/blooio-go-sdk/blooio"
```

## Send an iMessage

Create a client with a Blooio API key and send a message through `Chats.SendMessage`.

```go
package main

import (
    "context"
    "log"
    "os"

    "github.com/Blooio/blooio-go-sdk/blooio"
)

func main() {
    client := blooio.NewClient(os.Getenv("BLOOIO_API_KEY"))

    _, err := client.Chats.SendMessage(context.Background(), &blooio.SendMessageRequest{
        Phone: "+15551234567",
        Body:  "Hey Alex — thanks for booking a demo. Reply with any questions.",
    })
    if err != nil {
        log.Fatalf("send failed: %v", err)
    }
}
```

## Verify Webhooks

Use `webhook.Verify` to verify the raw request body against the `X-Blooio-Signature` header and your webhook secret. Verification returns a typed event or an error when the signature is invalid.

```go
package main

import (
    "encoding/json"
    "io"
    "log"
    "net/http"

    "github.com/Blooio/blooio-go-sdk/webhook"
)

func blooioHandler(w http.ResponseWriter, r *http.Request) {
    body, _ := io.ReadAll(r.Body)
    sig := r.Header.Get("X-Blooio-Signature")

    event, err := webhook.Verify(body, sig, "whsec_...")
    if err != nil {
        http.Error(w, "bad signature", http.StatusUnauthorized)
        return
    }

    if event.Type == "message.received" {
        var data struct {
            Body string `json:"body"`
        }
        _ = json.Unmarshal(event.Data, &data)
        log.Printf("inbound: %s", data.Body)
    }

    w.WriteHeader(http.StatusOK)
}
```

## SDK Features

- Context-aware requests using `context.Context` for cancellation and deadlines
- Typed request and response structs for every endpoint
- Typed webhook event handling
- Webhook signature verification helper
- Idiomatic error types compatible with `errors.Is` and `errors.As`
- Built-in retries with jitter for HTTP 429 and 5xx responses
- Zero runtime dependencies outside the Go standard library
- Support for Go 1.21 and later
- Compatible with Linux, macOS, Windows, and ARM
- MIT-licensed open-source repository

## Frequently Asked Questions

### How do I install the Blooio iMessage Go SDK?

Run:

```bash
go get github.com/Blooio/blooio-go-sdk@latest
```

Then import `github.com/Blooio/blooio-go-sdk/blooio`.

### Does the SDK support context cancellation?

Yes. Every SDK method accepts `context.Context` as its first argument. Requests respect cancellation and deadline settings on the context.

### How do I verify Blooio webhook signatures in Go?

Pass the raw request body, the `X-Blooio-Signature` header value, and your webhook secret to `webhook.Verify`.

### Does the SDK have runtime dependencies?

No. The SDK uses only the Go standard library at runtime.

### Is the Go SDK open source?

Yes. The Blooio Go SDK is MIT-licensed and publicly available on GitHub.

## Links

- HTML page: https://blooio.com/integrations/api/imessage-go-sdk
- Markdown page: https://blooio.com/integrations/api/imessage-go-sdk.md
- Go SDK repository: https://github.com/Blooio/blooio-go-sdk
- REST API overview: https://blooio.com/integrations/api.md
- Integrations overview: https://blooio.com/integrations.md
- Pricing: https://blooio.com/pricing.md
- LLM site index: https://blooio.com/llms.txt
