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

70 lines
2.7 KiB
Go

package channel
import "github.com/gochat/gochat/internal/model"
// ChannelFacebook represents a Facebook Messenger channel.
// Reference: Chatwoot app/models/channel/facebook_page.rb
//
// Chatwoot's ChannelFacebook (Channel::FacebookPage) model attributes:
// - account_id: FK to Account
// - page_id: Facebook Page ID
// - page_access_token: Long-lived Page access token
// - page_name: Display name of the FB Page
// - reauthorization_required: Flag when token expires
//
// gochat enhancements beyond Chatwoot:
// - instagram_business_account_id: Optional link to IG account for cross-channel
// - app_id: FB App ID for webhook verification
// - webhook_verify_token: Token for FB webhook subscription verification
type ChannelFacebook struct {
model.Base
// 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:"not null;uniqueIndex" json:"inbox_id"`
// Facebook Page ID — identifies the FB Page for Messenger
PageID string `gorm:"size:255;not null" json:"page_id"`
// Long-lived Page access token for Graph API calls
// Requires pages_messaging permission for Messenger
PageAccessToken string `gorm:"size:512;not null" json:"page_access_token"`
// Long-lived user access token used to discover and reauthorize pages.
UserAccessToken string `gorm:"size:512" json:"user_access_token,omitempty"`
// Display name of the Facebook Page
PageName string `gorm:"size:255" json:"page_name,omitempty"`
// FB App ID — used for webhook verification and API calls
AppID string `gorm:"size:255" json:"app_id,omitempty"`
// Webhook verify token — used during FB webhook subscription
// Reference: Chatwoot doesn't store this; GoChat adds for verification
WebhookVerifyToken string `gorm:"size:255" json:"webhook_verify_token,omitempty"`
// Instagram Business Account ID — links to IG account for cross-channel
// When set, this FB Page also manages Instagram DMs
// Reference: FB Graph API /me?fields=instagram_business_account
InstagramBusinessAccountID string `gorm:"size:255" json:"instagram_business_account_id,omitempty"`
// Tracks when the Page token needs reauthorization
ReauthorizationRequired bool `gorm:"default:false" json:"reauthorization_required"`
}
func (ChannelFacebook) TableName() string { return "channel_facebook_pages" }
// GetChannelBase returns the base channel fields for polymorphic access.
func (c *ChannelFacebook) GetChannelBase() ChannelBase {
return ChannelBase{
AccountID: c.AccountID,
InboxID: c.InboxID,
ChannelType: "facebook",
}
}
// GetChannelType returns the channel type identifier.
func (c *ChannelFacebook) GetChannelType() string { return "facebook" }