# iMessage Go SDK

Send and receive iMessages from Go with Blooio's official iMessage Go SDK. Idiomatic Go all the way down — context-aware requests, typed structs for every endpoint and webhook, zero third-party dependencies beyond the standard library, and a webhook verifier you can mount on any net/http handler.

## Install

One command to add the iMessage Go SDK to your project.

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

## Send your first iMessage

This is the smallest working example — authenticate with your Blooio API key, then call the send-message method on the client.

```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)
    }
}
```

## Handle inbound iMessages and webhooks

Every inbound iMessage, delivery, read, and reaction event is POSTed to your webhook URL. Use the SDK's signature verifier to reject forged requests and deserialize the payload into typed objects.

```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)
}
```

## What the SDK gives you on top of raw REST

- Context-aware — every request takes context.Context for cancellation and deadlines
- Typed request/response structs for every endpoint and webhook event
- Zero runtime dependencies beyond the Go standard library
- Idiomatic error types — check with errors.Is / errors.As
- Built-in retries with jitter for 429 and 5xx
- Go 1.21+ supported — builds cleanly on Linux, macOS, Windows, and ARM

## Go iMessage SDK FAQ

**How do I install the Blooio iMessage Go SDK?**  
Run `go get github.com/Blooio/blooio-go-sdk@latest` inside your module. Import with `github.com/Blooio/blooio-go-sdk/blooio`.

**Does the Go iMessage SDK support context cancellation?**  
Yes. Every method takes a `context.Context` as its first argument. Pass a context with a deadline or cancel function and the request will respect it.

**How do I verify Blooio webhook signatures in Go?**  
Use the `webhook.Verify` helper — pass the raw request body, the `X-Blooio-Signature` header, and your webhook secret. It returns a typed `Event` or an error if the signature is invalid.

**Does the Go SDK have any runtime dependencies?**  
No. The SDK uses only the Go standard library. It compiles on any platform supported by Go 1.21+, including ARM and Cloud Run.

**Is the Go SDK open source?**  
Yes, MIT-licensed and public on GitHub at github.com/Blooio/blooio-go-sdk.
