Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
69 lines
2.3 KiB
Ruby
69 lines
2.3 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: channel_twitter_profiles
|
|
#
|
|
# id :bigint not null, primary key
|
|
# tweets_enabled :boolean default(TRUE)
|
|
# twitter_access_token :string not null
|
|
# twitter_access_token_secret :string not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# account_id :integer not null
|
|
# profile_id :string not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_channel_twitter_profiles_on_account_id_and_profile_id (account_id,profile_id) UNIQUE
|
|
#
|
|
|
|
class Channel::TwitterProfile < ApplicationRecord
|
|
include Channelable
|
|
|
|
# TODO: Remove guard once encryption keys become mandatory (target 3-4 releases out).
|
|
if Chatwoot.encryption_configured?
|
|
encrypts :twitter_access_token
|
|
encrypts :twitter_access_token_secret
|
|
end
|
|
|
|
self.table_name = 'channel_twitter_profiles'
|
|
|
|
validates :profile_id, uniqueness: { scope: :account_id }
|
|
|
|
before_destroy :unsubscribe
|
|
|
|
EDITABLE_ATTRS = [:tweets_enabled].freeze
|
|
|
|
def name
|
|
'Twitter'
|
|
end
|
|
|
|
def create_contact_inbox(profile_id, name, additional_attributes)
|
|
::ContactInboxWithContactBuilder.new({
|
|
source_id: profile_id,
|
|
inbox: inbox,
|
|
contact_attributes: { name: name, additional_attributes: additional_attributes }
|
|
}).perform
|
|
end
|
|
|
|
def twitter_client
|
|
Twitty::Facade.new do |config|
|
|
config.consumer_key = ENV.fetch('TWITTER_CONSUMER_KEY', nil)
|
|
config.consumer_secret = ENV.fetch('TWITTER_CONSUMER_SECRET', nil)
|
|
config.access_token = twitter_access_token
|
|
config.access_token_secret = twitter_access_token_secret
|
|
config.base_url = 'https://api.twitter.com'
|
|
config.environment = ENV.fetch('TWITTER_ENVIRONMENT', '')
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def unsubscribe
|
|
### Fix unsubscription with new endpoint
|
|
unsubscribe_response = twitter_client.remove_subscription(user_id: profile_id)
|
|
Rails.logger.info "TWITTER_UNSUBSCRIBE: #{unsubscribe_response.body}"
|
|
rescue StandardError => e
|
|
Rails.logger.error e
|
|
end
|
|
end
|