Skip to content

Commit

Permalink
chore: Sidebar icons for new inboxes (chatwoot#3016)
Browse files Browse the repository at this point in the history
- Sidebar icons for line and telegram inboxes
- Sentry fix for contact IP lookup job
  • Loading branch information
sojan-official authored Sep 15, 2021
1 parent 2396b59 commit a14f4ed
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
19 changes: 14 additions & 5 deletions app/builders/messages/facebook/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,30 @@ def message_params
}
end

def process_contact_params_result(result)
{
name: "#{result['first_name'] || 'John'} #{result['last_name'] || 'Doe'}",
account_id: @inbox.account_id,
remote_avatar_url: result['profile_pic'] || ''
}
end

def contact_params
begin
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
result = k.get_object(@sender_id) || {}
rescue Koala::Facebook::AuthenticationError
@inbox.channel.authorization_error!
raise
rescue Koala::Facebook::ClientError => e
result = {}
# OAuthException, code: 100, error_subcode: 2018218, message: (#100) No profile available for this user
# We don't need to capture this error as we don't care about contact params in case of echo messages
Sentry.capture_exception(e) unless outgoing_echo?
rescue StandardError => e
result = {}
Sentry.capture_exception(e)
end
{
name: "#{result['first_name'] || 'John'} #{result['last_name'] || 'Doe'}",
account_id: @inbox.account_id,
remote_avatar_url: result['profile_pic'] || ''
}
process_contact_params_result(result)
end
end
2 changes: 1 addition & 1 deletion app/javascript/dashboard/components/layout/SidebarItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<a href="#" :class="computedChildClass(child)">
<div class="wrap">
<i
v-if="computedInboxClass(child)"
v-if="menuItem.key === 'inbox'"
class="inbox-icon"
:class="computedInboxClass(child)"
/>
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/dashboard/helper/inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const getInboxClassByType = (type, phoneNumber) => {
case INBOX_TYPES.EMAIL:
return 'ion-ios-email';

case INBOX_TYPES.TELEGRAM:
return 'ion-ios-navigate';

default:
return '';
return 'ion-ios-chatbubble';
}
};
1 change: 1 addition & 0 deletions app/javascript/shared/mixins/inboxMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const INBOX_TYPES = {
TWILIO: 'Channel::TwilioSms',
API: 'Channel::Api',
EMAIL: 'Channel::Email',
TELEGRAM: 'Channel::Telegram',
LINE: 'Channel::Line',
};

Expand Down
3 changes: 2 additions & 1 deletion app/jobs/contact_ip_lookup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ def update_contact_location_from_ip(contact)
geocoder_result = Geocoder.search(ip).first
return unless geocoder_result

contact.additional_attributes ||= {}
contact.additional_attributes['city'] = geocoder_result.city
contact.additional_attributes['country'] = geocoder_result.country
contact.additional_attributes['country_code'] = geocoder_result.country_code
contact.save!
end

def get_contact_ip(contact)
contact.additional_attributes['updated_at_ip'] || contact.additional_attributes['created_at_ip']
contact.additional_attributes&.dig('updated_at_ip') || contact.additional_attributes&.dig('created_at_ip')
end

def ensure_look_up_db
Expand Down
14 changes: 10 additions & 4 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ def allowed_ip?

# ref: https://github.com/rack/rack-attack/issues/399
throttle('login/email', limit: 20, period: 5.minutes) do |req|
email = req.params['email'].presence || ActionDispatch::Request.new(req.env).params['email'].presence
email.to_s.downcase.gsub(/\s+/, '') if req.path == '/auth/sign_in' && req.post?
if req.path == '/auth/sign_in' && req.post?
# NOTE: This line used to throw ArgumentError /rails/action_mailbox/sendgrid/inbound_emails : invalid byte sequence in UTF-8
# Hence placed in the if block
email = req.params['email'].presence || ActionDispatch::Request.new(req.env).params['email'].presence
email.to_s.downcase.gsub(/\s+/, '')
end
end

throttle('reset_password/email', limit: 5, period: 1.hour) do |req|
email = req.params['email'].presence || ActionDispatch::Request.new(req.env).params['email'].presence
email.to_s.downcase.gsub(/\s+/, '') if req.path == '/auth/password' && req.post?
if req.path == '/auth/password' && req.post?
email = req.params['email'].presence || ActionDispatch::Request.new(req.env).params['email'].presence
email.to_s.downcase.gsub(/\s+/, '')
end
end
end

Expand Down
10 changes: 7 additions & 3 deletions lib/integrations/dialogflow/processor_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ def perform
return unless processable_message?(message)
return unless message.conversation.pending?

response = get_dialogflow_response(message.conversation.contact_inbox.source_id, message_content(message))
process_response(message, response)
content = message_content(message)
response = get_dialogflow_response(message.conversation.contact_inbox.source_id, content) if content.present?
process_response(message, response) if response.present?
end

private

def message_content(message)
return message.content_attributes['submitted_values'].first['value'] if event_name == 'message.updated'
# TODO: might needs to change this to a way that we fetch the updated value from event data instead
# cause the message.updated event could be that that the message was deleted

return message.content_attributes['submitted_values']&.dig 'value' if event_name == 'message.updated'

message.content
end
Expand Down
2 changes: 2 additions & 0 deletions lib/integrations/slack/send_on_slack_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def avatar_url(sender)
end

def send_message
return if message_content.blank?

@slack_message = slack_client.chat_postMessage(
channel: hook.reference_id,
text: message_content,
Expand Down

0 comments on commit a14f4ed

Please sign in to comment.