Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queue for sms and mms #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ WORKDIR /app
COPY --from=builder /app/main .

# Copy the .env and carriers.json files
COPY .env carriers.json ./
COPY .env clients.json ./

# Use the non-root user
USER appuser
Expand Down
62 changes: 41 additions & 21 deletions carrier.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,72 @@
package main

import (
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"io/ioutil"
"github.com/kataras/iris/v12"
"os"
"strings"
)

/*var CarrierType = struct {
Twilio string
Telynx string
}{
Twilio: "twilio",
Telynx: "telynx",
}*/

func (h *BaseCarrierHandler) Name() string {
return h.name
}

// BaseCarrierHandler provides common functionality for carriers
type BaseCarrierHandler struct {
name string
}

// CarrierHandler interface for different carrier handlers
type CarrierHandler interface {
HandleInbound(c *fiber.Ctx, gateway *SMSGateway) error
HandleOutbound(c *fiber.Ctx, gateway *SMSGateway) error
SendSMS(sms *SMS) error
Inbound(c iris.Context) error
SendSMS(sms *MsgQueueItem) error
SendMMS(sms *MsgQueueItem) error
Name() string
}

type CarrierConfig struct {
type Carrier struct {
Name string `json:"name"`
Type string `json:"type"`
// Add any carrier-specific configuration fields here
}

func loadCarriers(configPath string, logger *CustomLogger, gateway *SMSGateway) (map[string]CarrierHandler, error) {
data, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
func loadCarriers(gateway *Gateway) error {
var configs []Carrier

var configs []CarrierConfig
err = json.Unmarshal(data, &configs)
if err != nil {
return nil, err
// todo add more?
carrier := []string{"twilio", "telnyx"}

for _, cName := range carrier {
if strings.ToLower(os.Getenv(strings.ToUpper(cName)+"_ENABLE")) == "true" {
configs = append(configs, Carrier{
Name: cName,
})
}
}

carriers := make(map[string]CarrierHandler)
for _, config := range configs {
switch config.Type {
switch config.Name {
case "twilio":
carriers[config.Name] = NewTwilioHandler(logger, gateway)
carriers[config.Name] = NewTwilioHandler(gateway)
case "telnyx":
carriers[config.Name] = NewTelnyxHandler(gateway)
// Add cases for other carrier types here
default:
return nil, fmt.Errorf("unknown carrier type: %s", config.Type)
return fmt.Errorf("unknown carrier type: %s", config.Name)
}
}

return carriers, nil
// Capture 'name' and 'handler' to avoid closure issues

gateway.Carriers = carriers

return nil
}
Loading