wpd-message-gateway

module
v1.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: MIT

README ΒΆ

WPD Message Gateway

Go Reference Go Report Card

A unified Go library and HTTP API for sending Email, SMS, Push, and Chat messages.

One interface, multiple providers. Write your messaging code once β€” switch between Mailgun, Twilio, Firebase, WhatsApp, and more without changing a single line of application code.

Why Use This?

  • πŸ”Œ One API, Many Providers β€” Send emails via Mailgun today, switch to SendGrid tomorrow. No code changes.
  • πŸ“¦ DevBox Included β€” Built-in web UI to preview emails, SMS, push notifications, and chat messages during development.
  • πŸ§ͺ E2E Testing Ready β€” Memory provider stores messages in RAM. Query them via REST API for automated testing.
  • πŸš€ Go Library + HTTP Server β€” Use as a Go package (import) or deploy as a standalone microservice.

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Your App      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ POST /v1/email
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Gateway Serviceβ”‚
β”‚ (Routes by      β”‚
β”‚  provider name) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ providers.defaults.email = ?
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                                 β”‚
    β–Ό                                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ "memory"        β”‚       β”‚ "mailgun"       β”‚
β”‚                 β”‚       β”‚ "sendgrid"      β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚       β”‚ etc.            β”‚
β”‚ β”‚ DevBox UI   β”‚ β”‚       β”‚                 β”‚
β”‚ β”‚ (RAM store) β”‚ β”‚       β”‚  Real Provider  β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚       β”‚  (API calls)    β”‚
β”‚        +        β”‚       β”‚                 β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ Mailpit     β”‚ β”‚
β”‚ β”‚ (optional)  β”‚ β”‚ ← Only if mailpit.enabled: true
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Message Types

Type What it does Example providers
πŸ“§ Email Send emails with HTML, attachments Mailgun, SendGrid, AWS SES
πŸ“± SMS Send text messages to phones Twilio, Vonage
πŸ”” Push Send notifications to apps Firebase, OneSignal
πŸ’¬ Chat Send messages on chat platforms WhatsApp, Telegram, Slack

Quick Start

Option 1: Use as a Go Package
go get github.com/weprodev/wpd-message-gateway
package main

import (
    "context"
    "log"

    "github.com/weprodev/wpd-message-gateway/pkg/contracts"
    "github.com/weprodev/wpd-message-gateway/pkg/gateway"
)

func main() {
    gw, _ := gateway.New(gateway.Config{
        DefaultEmailProvider: "memory",
    })

    result, err := gw.SendEmail(context.Background(), &contracts.Email{
        To:      []string{"user@example.com"},
        Subject: "Welcome!",
        HTML:    "<h1>Hello!</h1>",
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Sent! ID: %s", result.ID)
}
Option 2: Run as HTTP Server
# 1. Clone and configure
git clone https://github.com/weprodev/wpd-message-gateway.git
cd wpd-message-gateway
cp configs/local.example.yml configs/local.yml

# 2. Start everything (Gateway + DevBox UI)
make start

Open http://localhost:10104 to see all intercepted messages in the DevBox UI.

β†’ See Usage Guide for more examples.

Configuration

Configure providers in configs/local.yml:

providers:
  defaults:
    email: mailgun   # or: memory, sendgrid, ses
    sms: memory      # or: twilio, vonage
    push: memory     # or: firebase, onesignal
    chat: memory     # or: slack, telegram, whatsapp
  
  email:
    mailgun:
      api_key: "your-api-key"
      domain: "mg.yourdomain.com"

Or use environment variables for secrets:

MESSAGE_MAILGUN_API_KEY=key-xxxxx
MESSAGE_MAILGUN_DOMAIN=mg.example.com

Development Mode (DevBox)

During development, use the memory provider to capture all messages locally:

# configs/local.yml
providers:
  defaults:
    email: memory
    sms: memory
    push: memory
    chat: memory

β†’ See DevBox Documentation for details.

Mailpit Integration (Optional)

For realistic email preview with HTML rendering:

# 1. Start Mailpit
make mailpit

# 2. Enable in configs/local.yml:
mailpit:
  enabled: true

# 3. Start server
make start

# View emails:
#   - DevBox UI: http://localhost:10104 (all message types)
#   - Mailpit:   http://localhost:10103 (email preview)

E2E Testing in CI

Use the gateway to capture and verify all messages your app sends during tests. No mocks needed.

Benefits:

  • βœ… Test real HTTP calls, not mocks
  • βœ… Verify exact message content (subject, body, recipients)
  • βœ… Test all channels: Email + SMS + Push + Chat
  • βœ… Zero external dependencies (no Mailgun/Twilio accounts needed)
services:
  gateway:
    image: ghcr.io/weprodev/wpd-message-gateway:latest
    ports:
      - 10101:10101

steps:
  - run: npm test  # Your app sends to http://localhost:10101
  
  - name: Verify welcome email
    run: |
      curl -s http://localhost:10101/api/v1/emails | \
        jq -e '.emails[0].email.subject == "Welcome!"'

β†’ See E2E Testing Guide for complete examples.

Provider Status

Type Provider Status
πŸ“§ Email Mailgun βœ… Ready
πŸ“§ Email Memory (DevBox) βœ… Ready
πŸ“§ Email SendGrid πŸ“‹ Planned
πŸ“± SMS Memory (DevBox) βœ… Ready
πŸ“± SMS Twilio πŸ“‹ Planned
πŸ”” Push Memory (DevBox) βœ… Ready
πŸ”” Push Firebase πŸ“‹ Planned
πŸ’¬ Chat Memory (DevBox) βœ… Ready
πŸ’¬ Chat WhatsApp πŸ“‹ Planned

Commands

make install    # Install all dependencies
make start      # Start development (Gateway + DevBox UI)
make test       # Run tests
make audit      # Full check: format + lint + test + security
make build      # Build all packages

# Docker
make dev        # Start Gateway via Docker
make dev-down   # Stop Docker

# Optional (email preview)
make mailpit    # Start Mailpit for HTML email preview

Project Structure

wpd-message-gateway/
β”œβ”€β”€ cmd/server/          # HTTP server entry point
β”œβ”€β”€ configs/             # YAML configuration files
β”œβ”€β”€ internal/            # Private application code
β”‚   β”œβ”€β”€ app/             # Configuration, wiring, validation
β”‚   β”œβ”€β”€ core/            # Business logic
β”‚   β”‚   β”œβ”€β”€ port/        # Interface definitions (contracts)
β”‚   β”‚   └── service/     # Gateway service, registry
β”‚   β”œβ”€β”€ infrastructure/  # External integrations
β”‚   β”‚   └── provider/    # Provider implementations
β”‚   β”‚       β”œβ”€β”€ mailgun/ # Mailgun email provider
β”‚   β”‚       └── memory/  # In-memory provider (DevBox)
β”‚   └── presentation/    # HTTP layer
β”‚       β”œβ”€β”€ handler/     # Request handlers
β”‚       └── router.go    # Route definitions
β”œβ”€β”€ pkg/                 # Public packages for external use
β”‚   β”œβ”€β”€ contracts/       # Message types (Email, SMS, Push, Chat)
β”‚   β”œβ”€β”€ errors/          # Error types
β”‚   └── gateway/         # Embedded SDK
β”œβ”€β”€ web/                 # DevBox React UI
└── tests/bruno/         # API test collection

Documentation

Document Description
Usage Guide Install, configure, and send messages
E2E Testing Test your app's messages in CI
Architecture System design and principles
DevBox Development inbox UI
Contributing Add new providers
Workflow CI/CD and releases
Code Conventions Coding standards

License

MIT

Directories ΒΆ

Path Synopsis
cmd
server command
examples
chat command
Chat example demonstrates sending a chat message using the message gateway.
Chat example demonstrates sending a chat message using the message gateway.
email command
Email example demonstrates sending an email using the message gateway.
Email example demonstrates sending an email using the message gateway.
push command
Push example demonstrates sending a push notification using the message gateway.
Push example demonstrates sending a push notification using the message gateway.
sms command
SMS example demonstrates sending an SMS using the message gateway.
SMS example demonstrates sending an SMS using the message gateway.
internal
app
Package app imports all providers to trigger their init() registration.
Package app imports all providers to trigger their init() registration.
app/registry
Package registry provides provider registration functionality.
Package registry provides provider registration functionality.
pkg
gateway
Package gateway provides an embedded SDK for the message gateway.
Package gateway provides an embedded SDK for the message gateway.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL