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.
81 lines
2.9 KiB
Go
81 lines
2.9 KiB
Go
package channel
|
|
|
|
import "github.com/gochat/gochat/internal/model"
|
|
|
|
// ChannelTwitter represents a Twitter/X channel.
|
|
// Reference: Chatwoot app/models/channel/twitter_profile.rb
|
|
//
|
|
// Chatwoot's ChannelTwitter (Channel::TwitterProfile) model attributes:
|
|
// - account_id: FK to Account
|
|
// - twitter_access_token: OAuth access token for Twitter API
|
|
// - twitter_access_token_secret: OAuth access token secret
|
|
// - profile_id: Twitter user ID (numeric)
|
|
// - name: Twitter display name
|
|
// - screen_name: Twitter @handle
|
|
// - profile_image_url: Twitter avatar URL
|
|
// - tweets_enabled: whether tweet webhooks should create conversations/messages
|
|
// - reauthorization_required: Flag when token needs refresh
|
|
//
|
|
// gochat enhancements beyond Chatwoot:
|
|
// - webhook_id: Twitter webhook ID for CRC/subscription management
|
|
// - webhook_env: Twitter Account Activity API environment name
|
|
// - uses OAuth 2.0 with PKCE for newer Twitter API v2 integration
|
|
type ChannelTwitter 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"`
|
|
|
|
// Twitter user ID (numeric string) — identifies the Twitter account
|
|
TwitterUserID string `gorm:"size:255;not null;uniqueIndex" json:"twitter_user_id"`
|
|
|
|
// Twitter display name
|
|
Name string `gorm:"size:255" json:"name,omitempty"`
|
|
|
|
// Twitter @handle (screen_name)
|
|
ScreenName string `gorm:"size:255" json:"screen_name,omitempty"`
|
|
|
|
// Twitter avatar URL
|
|
ProfileImageURL string `gorm:"size:512" json:"profile_image_url,omitempty"`
|
|
|
|
// OAuth 2.0 access token for Twitter API v2
|
|
AccessToken string `gorm:"size:1024;not null" json:"-"`
|
|
|
|
// OAuth 2.0 refresh token for token renewal
|
|
RefreshToken string `gorm:"size:1024" json:"-"`
|
|
|
|
// OAuth 1.0a access token (legacy Twitter API compatibility)
|
|
TwitterAccessToken string `gorm:"size:512;column:twitter_access_token" json:"-"`
|
|
|
|
// OAuth 1.0a access token secret (legacy)
|
|
TwitterAccessTokenSecret string `gorm:"size:512;column:twitter_access_token_secret" json:"-"`
|
|
|
|
// Twitter Account Activity API webhook ID
|
|
WebhookID string `gorm:"size:255" json:"webhook_id,omitempty"`
|
|
|
|
// Twitter Account Activity API environment name
|
|
WebhookEnv string `gorm:"size:255" json:"webhook_env,omitempty"`
|
|
|
|
// Whether incoming tweets should be processed into conversations/messages
|
|
TweetsEnabled bool `gorm:"default:true" json:"tweets_enabled"`
|
|
|
|
// Flag indicating reauthorization is required (token expired/revoked)
|
|
ReauthorizationRequired bool `gorm:"default:false" json:"reauthorization_required,omitempty"`
|
|
}
|
|
|
|
func (ChannelTwitter) TableName() string { return "channel_twitter_profiles" }
|
|
|
|
func (c ChannelTwitter) GetChannelBase() ChannelBase {
|
|
return ChannelBase{
|
|
ID: c.ID,
|
|
AccountID: c.AccountID,
|
|
InboxID: c.InboxID,
|
|
ChannelType: "twitter",
|
|
}
|
|
}
|
|
|
|
func (c ChannelTwitter) GetChannelType() string { return "twitter" }
|