77 lines
2.7 KiB
Go
77 lines
2.7 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
|
|
// - 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"`
|
|
|
|
// 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" }
|