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" }