Files
gochat/backend/internal/model/channel/tiktok.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

67 lines
2.6 KiB
Go

package channel
// ChannelTikTok represents a TikTok Business channel configuration.
// Reference: TikTok Business API — https://business-api.tiktok.com/portal/auth
//
// GoChat addition (Chatwoot does not have TikTok channel support).
// TikTok Business API provides:
// - OAuth2 authentication flow for connecting TikTok Business accounts
// - Direct messaging API for sending/receiving customer messages
// - Webhook events for incoming messages, read receipts, etc.
//
// Lifecycle:
// - OnCreate: OAuth2 token exchange → store access_token/refresh_token → setup webhook
// - OnReauthorization: refresh expired tokens via TikTok OAuth2 refresh endpoint
// - OnDestroy: delete webhook subscription
import (
"time"
"github.com/gochat/gochat/internal/model"
)
// ChannelTikTok stores TikTok Business channel configuration.
type ChannelTikTok struct {
model.Base // ID, CreatedAt, UpdatedAt, DeletedAt
// Account foreign key
AccountID uint `gorm:"index;not null" json:"account_id"`
// Inbox foreign key — links to the Inbox that wraps this channel
InboxID uint `gorm:"index" json:"inbox_id,omitempty"`
// TikTok Business account ID (obtained after OAuth authorization)
TikTokBusinessID string `gorm:"column:tiktok_business_id;type:varchar(255);not null" json:"tiktok_business_id"`
// OAuth2 tokens (obtained via BuildAuthURL → ExchangeToken flow)
AccessToken string `gorm:"type:varchar(512)" json:"access_token,omitempty"`
RefreshToken string `gorm:"type:varchar(512)" json:"refresh_token,omitempty"`
TokenExpiresAt time.Time `gorm:"" json:"token_expires_at,omitempty"`
// Webhook verification token (set during channel creation for webhook setup)
WebhookVerifyToken string `gorm:"type:varchar(255)" json:"webhook_verify_token,omitempty"`
// Flag indicating the channel needs re-authorization (token expired/revoked)
ReauthorizationRequired bool `gorm:"default:false" json:"reauthorization_required,omitempty"`
}
// GetChannelBase returns the common ChannelBase fields.
// For TikTok, we construct a ChannelBase from our fields since we don't embed it directly.
func (c ChannelTikTok) GetChannelBase() ChannelBase {
return ChannelBase{
ID: c.ID,
AccountID: c.AccountID,
InboxID: c.InboxID,
ChannelType: "tiktok",
CreatedAt: c.CreatedAt,
UpdatedAt: c.UpdatedAt,
DeletedAt: c.DeletedAt,
}
}
// GetChannelType returns the channel type identifier.
func (c ChannelTikTok) GetChannelType() string { return "tiktok" }
// TableName returns the GORM table name for ChannelTikTok.
func (ChannelTikTok) TableName() string { return "channel_tiktoks" }