Feat: Manage conversation for tweets based on the tweet flag (#3353)
Add tweet conversation only if tweets are enabled. Fixes #1961
This commit is contained in:
parent
e2e459a1ac
commit
9984edd3ef
12 changed files with 73 additions and 17 deletions
|
@ -124,19 +124,6 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
|||
end
|
||||
|
||||
def get_channel_attributes(channel_type)
|
||||
case channel_type
|
||||
when 'Channel::WebWidget'
|
||||
Channel::WebWidget::EDITABLE_ATTRS
|
||||
when 'Channel::Api'
|
||||
Channel::Api::EDITABLE_ATTRS
|
||||
when 'Channel::Email'
|
||||
Channel::Email::EDITABLE_ATTRS
|
||||
when 'Channel::Telegram'
|
||||
Channel::Telegram::EDITABLE_ATTRS
|
||||
when 'Channel::Line'
|
||||
Channel::Line::EDITABLE_ATTRS
|
||||
else
|
||||
[]
|
||||
end
|
||||
channel_type.constantize::EDITABLE_ATTRS.presence || []
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,7 +47,10 @@
|
|||
},
|
||||
"TWITTER": {
|
||||
"HELP": "To add your Twitter profile as a channel, you need to authenticate your Twitter Profile by clicking on 'Sign in with Twitter' ",
|
||||
"ERROR_MESSAGE": "There was an error connecting to Twitter, please try again"
|
||||
"ERROR_MESSAGE": "There was an error connecting to Twitter, please try again",
|
||||
"TWEETS": {
|
||||
"ENABLE": "Create conversations from mentioned Tweets"
|
||||
}
|
||||
},
|
||||
"WEBSITE_CHANNEL": {
|
||||
"TITLE": "Website channel",
|
||||
|
|
|
@ -32,6 +32,14 @@
|
|||
:label="inboxNameLabel"
|
||||
:placeholder="inboxNamePlaceHolder"
|
||||
/>
|
||||
<label for="toggle-business-hours" class="toggle-input-wrap" v-if="isATwitterInbox">
|
||||
<input
|
||||
v-model="tweetsEnabled"
|
||||
type="checkbox"
|
||||
name="toggle-business-hours"
|
||||
/>
|
||||
{{ $t('INBOX_MGMT.ADD.TWITTER.TWEETS.ENABLE') }}
|
||||
</label>
|
||||
<woot-input
|
||||
v-if="isAPIInbox"
|
||||
v-model.trim="webhookUrl"
|
||||
|
@ -401,6 +409,7 @@ export default {
|
|||
avatarUrl: '',
|
||||
selectedAgents: [],
|
||||
greetingEnabled: true,
|
||||
tweetsEnabled: true,
|
||||
hmacMandatory: null,
|
||||
greetingMessage: '',
|
||||
autoAssignment: false,
|
||||
|
@ -564,6 +573,7 @@ export default {
|
|||
this.selectedInboxName = this.inbox.name;
|
||||
this.webhookUrl = this.inbox.webhook_url;
|
||||
this.greetingEnabled = this.inbox.greeting_enabled || false;
|
||||
this.tweetsEnabled = this.inbox.tweets_enabled || false;
|
||||
this.hmacMandatory = this.inbox.hmac_mandatory || false;
|
||||
this.greetingMessage = this.inbox.greeting_message || '';
|
||||
this.autoAssignment = this.inbox.enable_auto_assignment;
|
||||
|
@ -622,6 +632,7 @@ export default {
|
|||
selectedFeatureFlags: this.selectedFeatureFlags,
|
||||
reply_time: this.replyTime || 'in_a_few_minutes',
|
||||
hmac_mandatory: this.hmacMandatory,
|
||||
tweets_enabled: this.tweetsEnabled,
|
||||
},
|
||||
};
|
||||
if (this.avatarFile) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# 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
|
||||
|
@ -24,6 +25,8 @@ class Channel::TwitterProfile < ApplicationRecord
|
|||
|
||||
before_destroy :unsubscribe
|
||||
|
||||
EDITABLE_ATTRS = [:tweets_enabled].freeze
|
||||
|
||||
def name
|
||||
'Twitter'
|
||||
end
|
||||
|
|
|
@ -87,6 +87,10 @@ class Inbox < ApplicationRecord
|
|||
channel_type == 'Channel::TwilioSms'
|
||||
end
|
||||
|
||||
def twitter?
|
||||
channel_type == 'Channel::TwitterProfile'
|
||||
end
|
||||
|
||||
def inbox_type
|
||||
channel.name
|
||||
end
|
||||
|
|
|
@ -3,7 +3,8 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
|
|||
|
||||
def perform
|
||||
set_inbox
|
||||
return if message_already_exist? || user_has_blocked?
|
||||
|
||||
return if !tweets_enabled? || message_already_exist? || user_has_blocked?
|
||||
|
||||
create_message
|
||||
end
|
||||
|
@ -38,6 +39,10 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
|
|||
payload['user_has_blocked'] == true
|
||||
end
|
||||
|
||||
def tweets_enabled?
|
||||
@inbox.channel.tweets_enabled?
|
||||
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
|
||||
|
|
|
@ -14,6 +14,8 @@ json.working_hours resource.weekly_schedule
|
|||
json.timezone resource.timezone
|
||||
json.callback_webhook_url resource.callback_webhook_url
|
||||
|
||||
json.tweets_enabled resource.channel.try(:tweets_enabled) if resource.twitter?
|
||||
|
||||
## Channel specific settings
|
||||
## TODO : Clean up and move the attributes into channel sub section
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddTweetEnabledFlagToTwitterChannel < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :channel_twitter_profiles, :tweets_enabled, :boolean, default: true
|
||||
end
|
||||
end
|
|
@ -242,6 +242,7 @@ ActiveRecord::Schema.define(version: 2021_12_08_085931) do
|
|||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.boolean "tweets_enabled", default: true
|
||||
t.index ["account_id", "profile_id"], name: "index_channel_twitter_profiles_on_account_id_and_profile_id", unique: true
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Webhooks::Twitter
|
||||
SUPPORTED_EVENTS = [:direct_message_events, :tweet_create_events].freeze
|
||||
EDITABLE_ATTRS = [:tweets_enabled].freeze
|
||||
|
||||
attr_accessor :params, :account
|
||||
|
||||
|
|
|
@ -362,6 +362,19 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||
expect(api_channel.reload.webhook_url).to eq('webhook.test')
|
||||
end
|
||||
|
||||
it 'updates twitter inbox when administrator' do
|
||||
api_channel = create(:channel_twitter_profile, account: account, tweets_enabled: true)
|
||||
api_inbox = create(:inbox, channel: api_channel, account: account)
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{api_inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { channel: { tweets_enabled: false } },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(api_channel.reload.tweets_enabled).to eq(false)
|
||||
end
|
||||
|
||||
it 'updates email inbox when administrator' do
|
||||
email_channel = create(:channel_email, account: account)
|
||||
email_inbox = create(:inbox, channel: email_channel, account: account)
|
||||
|
|
|
@ -6,7 +6,7 @@ describe Webhooks::Twitter do
|
|||
|
||||
let!(:account) { create(:account) }
|
||||
# FIX ME: recipient id is set to 1 inside event factories
|
||||
let!(:twitter_channel) { create(:channel_twitter_profile, account: account, profile_id: '1') }
|
||||
let!(:twitter_channel) { create(:channel_twitter_profile, account: account, profile_id: '1', tweets_enabled: true) }
|
||||
let!(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account, greeting_enabled: false) }
|
||||
let!(:dm_params) { build(:twitter_message_create_event).with_indifferent_access }
|
||||
let!(:tweet_params) { build(:tweet_create_event).with_indifferent_access }
|
||||
|
@ -32,6 +32,27 @@ describe Webhooks::Twitter do
|
|||
|
||||
it 'creates incoming message in the twitter inbox' do
|
||||
twitter_webhook.new(tweet_params).consume
|
||||
twitter_inbox.reload
|
||||
expect(twitter_inbox.contacts.count).to be 1
|
||||
expect(twitter_inbox.conversations.count).to be 1
|
||||
expect(twitter_inbox.messages.count).to be 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'with tweet_enabled flag disabled' do
|
||||
before do
|
||||
twitter_channel.update(tweets_enabled: false)
|
||||
end
|
||||
|
||||
it 'does not create incoming message in the twitter inbox for tweet' do
|
||||
twitter_webhook.new(tweet_params).consume
|
||||
expect(twitter_inbox.contacts.count).to be 0
|
||||
expect(twitter_inbox.conversations.count).to be 0
|
||||
expect(twitter_inbox.messages.count).to be 0
|
||||
end
|
||||
|
||||
it 'creates incoming message in the twitter inbox' do
|
||||
twitter_webhook.new(dm_params).consume
|
||||
expect(twitter_inbox.contacts.count).to be 1
|
||||
expect(twitter_inbox.conversations.count).to be 1
|
||||
expect(twitter_inbox.messages.count).to be 1
|
||||
|
|
Loading…
Reference in a new issue