Files
gochat/backend/internal/model/channel/twilio.go
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00

62 lines
2.8 KiB
Go

package channel
// ChannelTwilioSMS represents a Twilio SMS channel configuration.
// Reference: Twilio SMS API — https://www.twilio.com/docs/sms
// + Chatwoot app/models/channel/twilio_sms.rb (partial — Chatwoot uses Twilio for SMS + WhatsApp)
//
// GoChat addition — full Twilio SMS integration.
// The Twilio SMS channel connects Twilio phone numbers to gochat conversations.
//
// Key Twilio API concepts:
// - Account SID: Twilio account identifier
// - Auth Token: Twilio authentication token (used for API + webhook verification)
// - Phone Number: the Twilio phone number sending/receiving SMS
// - Messaging Service SID: optional, for grouped phone numbers
// - Webhook: Twilio sends inbound messages to a configured URL
//
// Design notes:
// - Uses GORM soft-delete pattern consistent with other channel models
// - JSON field tags follow snake_case convention per P2D §7
// - Twilio supports both SMS and WhatsApp via the same API — this model
// handles SMS only; WhatsApp has its own ChannelWhatsApp model
// - Sensitive fields (auth_token) are stored in Inbox.ChannelConfig
import "gorm.io/gorm"
// ChannelTwilioSMS is the GORM model for Twilio SMS channels.
// Reference: Chatwoot app/models/channel/twilio_sms.rb
// Design: Follows the same pattern as ChannelTelegram — minimal GORM model with
// config stored in Inbox.ChannelConfig (JSONB).
type ChannelTwilioSMS struct {
gorm.Model
// Twilio Account SID
// Unique identifier for the Twilio subaccount
AccountSID string `json:"account_sid" gorm:"type:varchar(255);not null"`
// Phone number assigned to this channel (Twilio purchased number)
PhoneNumber string `json:"phone_number" gorm:"type:varchar(50);uniqueIndex;not null"`
// Messaging Service SID (optional)
// Used when multiple phone numbers are grouped under a messaging service
MessagingServiceSID string `json:"messaging_service_sid" gorm:"type:varchar(255)"`
// AccountID references the owning gochat account (multi-tenant)
AccountID uint `json:"account_id" gorm:"index;not null"`
// InboxID references the associated inbox (1:1 with channel)
InboxID uint `json:"inbox_id" gorm:"uniqueIndex;not null"`
}
// TableName overrides GORM table name convention.
func (ChannelTwilioSMS) TableName() string { return "channel_twilio_sms" }
// Channelable interface implementation for ChannelTwilioSMS.
func (c *ChannelTwilioSMS) GetChannelType() string { return "twilio_sms" }
func (c *ChannelTwilioSMS) GetChannelID() string { return c.AccountSID }
func (c *ChannelTwilioSMS) GetName() string { return c.PhoneNumber }
func (c *ChannelTwilioSMS) GetAccountID() uint { return c.AccountID }
func (c *ChannelTwilioSMS) GetInboxID() uint { return c.InboxID }
func (c *ChannelTwilioSMS) SetInboxID(id uint) { c.InboxID = id }