Feature: Twitter DM Integration (#451)

An initial version of twitter integration

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2020-02-03 00:39:00 +05:30
committed by GitHub
parent a287c86bc4
commit a9c304f1ef
20 changed files with 406 additions and 49 deletions

View File

@@ -0,0 +1,49 @@
# == Schema Information
#
# Table name: channel_twitter_profiles
#
# id :bigint not null, primary key
# name :string
# 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
#
class Channel::TwitterProfile < ApplicationRecord
self.table_name = 'channel_twitter_profiles'
validates :account_id, presence: true
validates :profile_id, uniqueness: { scope: :account_id }
has_one_attached :avatar
belongs_to :account
has_one :inbox, as: :channel, dependent: :destroy
before_destroy :unsubscribe
def name
'Twitter'
end
def create_contact_inbox(profile_id, name)
ActiveRecord::Base.transaction do
contact = inbox.account.contacts.create!(name: name)
::ContactInbox.create!(
contact_id: contact.id,
inbox_id: inbox.id,
source_id: profile_id
)
rescue StandardError => e
Rails.logger e
end
end
private
def unsubscribe
# to implement
end
end

View File

@@ -82,7 +82,12 @@ class Message < ApplicationRecord
end
def send_reply
::Facebook::SendReplyService.new(message: self).perform
channel_name = conversation.inbox.channel.class.to_s
if channel_name == 'Channel::FacebookPage'
::Facebook::SendReplyService.new(message: self).perform
elsif channel_name == 'Channel::TwitterProfile'
::Twitter::SendReplyService.new(message: self).perform
end
end
def reopen_conversation