Skip to content

Repository files navigation

direct-go-sdk

CI direct-go porting coverage License: MIT

Important

これは非公式のSDKです。L is B社およびdirect公式チームとは関係ありません。

This is an unofficial SDK for the direct (direct4b.com) chat service. It provides a low-level SDK (direct-go) and a high-level bot framework (daab-go).

Modules

  • direct-go: Go SDK for Direct4B WebSocket/MessagePack RPC API
  • daab-go: Bot framework and CLI tools built on direct-go
  • direct-teams-bridge: Multi-account direct4b ⇄ Microsoft Teams bridge
  • direct-mcp-server: OAuth-protected MCP server for Direct4B read and send tools
  • direct-slack-compat: Minimal Slack-compatible Web API and Events API adapter for Direct4B

Reference Repositories

This SDK is developed based on the following official repositories:

Installation

# For the SDK
go get github.com/f4ah6o/direct-go-sdk/direct-go

# For the bot framework
go get github.com/f4ah6o/direct-go-sdk/daab-go

Quick Start

Using the SDK directly

package main

import (
    "context"
    "log"

    direct "github.com/f4ah6o/direct-go-sdk/direct-go"
    "github.com/f4ah6o/direct-go-sdk/direct-go/auth"
)

func main() {
    // Load token from .env file or environment
    a := auth.NewAuth()
    token, err := a.GetToken()
    if err != nil {
        log.Fatal(err)
    }

    // Create client
    client := direct.NewClient(direct.Options{
        Token:    token,
        Endpoint: direct.DefaultEndpoint,
    })

    // Connect
    ctx := context.Background()
    if err := client.Connect(); err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    // Send a message
    err = client.SendText(roomID, "Hello, World!")
    if err != nil {
        log.Fatal(err)
    }
}

Using the Bot Framework

package main

import (
    "context"
    "log"
    "os"

    "github.com/f4ah6o/direct-go-sdk/daab-go/bot"
)

func main() {
    // Create a new bot
    r := bot.New(
        bot.WithName("mybot"),
    )

    // Add a simple handler
    r.Hear("hello", func(ctx context.Context, res bot.Response) {
        res.Send("Hello there!")
    })

    // Add a response handler (only when directly addressed)
    r.Respond("ping", func(ctx context.Context, res bot.Response) {
        res.Reply("pong")
    })

    // Run the bot
    ctx := context.Background()
    if err := r.Run(ctx); err != nil {
        log.Fatal(err)
    }
}

Using Middleware

import (
    "log"
    "os"

    "github.com/f4ah6o/direct-go-sdk/daab-go/bot"
)

func main() {
    r := bot.New()

    // Add middleware for logging and recovery
    logger := log.New(os.Stdout, "[BOT] ", log.LstdFlags)
    r.Use(bot.LoggingMiddleware(logger))
    r.Use(bot.RecoveryMiddleware(logger))

    // Add rate limiting (1 request per 10 seconds per user)
    r.Use(bot.RateLimitMiddleware(10 * time.Second))

    // Add filter to only process messages from specific users
    r.Use(bot.FilterMiddleware(func(ctx context.Context, res bot.Response) bool {
        return res.UserID() == "allowed_user_id"
    }))

    // Your handlers...
    r.Hear("test", func(ctx context.Context, res bot.Response) {
        res.Send("Filtered and rate-limited response!")
    })

    r.Run(context.Background())
}

Using the CLI

# Login to obtain access token
daabgo login

# Initialize a new bot project
daabgo init my-bot

# Run the bot
cd my-bot
daabgo run

# Show available commands
daabgo --help

Running the MCP Server

direct-mcp-server exposes Direct4B read/send tools over MCP Streamable HTTP. OAuth login and token issuance are expected to be handled by an upstream OAuth gateway or identity provider. The Go server validates incoming Bearer JWTs with the configured JWKS URL and enforces direct:read / direct:write scopes.

cp mcp.config.example.yaml mcp.config.yaml
# Edit mcp.config.yaml for your gateway, JWKS URL, public resource URL, and Direct accounts.
go run ./cmd/direct-mcp-server --config mcp.config.yaml

Protected resource metadata is served at:

/.well-known/oauth-protected-resource

Running the Slack-Compatible Adapter

direct-slack-compat exposes a small Slack-compatible subset for simple bots: auth.test, chat.postMessage, conversations.list, conversations.history, and users.list.

cp slackcompat.config.example.yaml slackcompat.config.yaml
# Edit slackcompat.config.yaml for Direct accounts and token refs.
go run ./cmd/direct-slack-compat --config slackcompat.config.yaml

The adapter intentionally does not implement Slack OAuth, Socket Mode, Block Kit, modals, full threads, or interactive components.

Environment Variables

Variable Description Default
DIRECT_TOKEN Access token for authentication -
HUBOT_DIRECT_ENDPOINT WebSocket endpoint URL wss://api.direct4b.com/albero-app-server/api
HUBOT_DIRECT_PROXY_URL Proxy URL for connections -
HTTPS_PROXY HTTPS proxy URL (fallback) -
HTTP_PROXY HTTP proxy URL (fallback) -

Documentation

Examples

See daab-go-examples for complete example projects:

  • ping - Simple echo bot
  • webhook - Webhook server example

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests: go test ./...
  4. Run linter: golangci-lint run
  5. Commit your changes
  6. Push to the branch
  7. Create a Pull Request

Development

# Run tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run tests with race detector
go test -race ./...

# Build the CLI
cd daab-go && go build -o daabgo cmd/daabgo/main.go

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages