Merge branch 'release/1.2.1' into develop

This commit is contained in:
Pranav Raj Sreepuram
2020-03-08 22:15:58 +05:30
27 changed files with 235 additions and 111 deletions

View File

@@ -11,7 +11,9 @@ class Twitter::DirectMessageParserService < Twitter::WebhooksBaseService
content: message_create_data['message_data']['text'],
account_id: @inbox.account_id,
inbox_id: @inbox.id,
message_type: outgoing_message? ? :outgoing : :incoming
message_type: outgoing_message? ? :outgoing : :incoming,
contact_id: @contact.id,
source_id: direct_message_data['id']
)
end

View File

@@ -39,10 +39,16 @@ class Twitter::SendReplyService
end
def send_tweet_reply
twitter_client.send_tweet_reply(
response = twitter_client.send_tweet_reply(
reply_to_tweet_id: conversation.additional_attributes['tweet_id'],
tweet: screen_name + message.content
)
if response.status == '200'
tweet_data = response.body
message.update!(source_id: tweet_data['id_str'])
else
Rails.logger 'TWITTER_TWEET_REPLY_ERROR' + response.body
end
end
def send_reply

View File

@@ -3,16 +3,9 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
def perform
set_inbox
find_or_create_contact(user)
set_conversation
@conversation.messages.create(
account_id: @inbox.account_id,
contact_id: @contact.id,
content: tweet_text,
inbox_id: @inbox.id,
message_type: message_type,
source_id: tweet_data['id'].to_s
)
return if message_already_exist?
create_message
end
private
@@ -37,6 +30,10 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
tweet_data['user']
end
def tweet_id
tweet_data['id'].to_s
end
def parent_tweet_id
tweet_data['in_reply_to_status_id_str'].nil? ? tweet_data['id'].to_s : tweet_data['in_reply_to_status_id_str']
end
@@ -66,4 +63,21 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
@conversation = ::Conversation.create!(conversation_params)
end
def message_already_exist?
@inbox.messages.find_by(source_id: tweet_id)
end
def create_message
find_or_create_contact(user)
set_conversation
@conversation.messages.create(
account_id: @inbox.account_id,
contact_id: @contact.id,
content: tweet_text,
inbox_id: @inbox.id,
message_type: message_type,
source_id: tweet_id
)
end
end