Skip to content

Commit

Permalink
[Feature] Detect browser on conversation initiation (chatwoot#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrajs authored Nov 16, 2019
1 parent ccd3d8d commit 88ac20e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'therubyracer', platforms: :ruby
##-- rails helper gems --##
gem 'acts-as-taggable-on', git: 'https://github.com/mbleigh/acts-as-taggable-on'
gem 'attr_extras'
gem 'browser'
gem 'hashie'
gem 'jbuilder', '~> 2.5'
gem 'kaminari'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ GEM
bootsnap (1.4.5)
msgpack (~> 1.0)
brakeman (4.7.0)
browser (2.7.0)
buftok (0.2.0)
builder (3.2.3)
byebug (11.0.1)
Expand Down Expand Up @@ -454,6 +455,7 @@ DEPENDENCIES
attr_extras
bootsnap
brakeman
browser
byebug
carrierwave-aws
chargebee (~> 2)
Expand Down
15 changes: 14 additions & 1 deletion app/controllers/api/v1/widget/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@ def conversation_params
{
account_id: inbox.account_id,
inbox_id: inbox.id,
contact_id: cookie_params[:contact_id]
contact_id: cookie_params[:contact_id],
additional_attributes: {
browser: browser_params
}
}
end

def browser_params
{
browser_name: browser.name,
browser_version: browser.full_version,
device_name: browser.device.name,
platform_name: browser.platform.name,
platform_version: browser.platform.version
}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdditionalAttributesToConversation < ActiveRecord::Migration[6.1]
def change
add_column :conversations, :additional_attributes, :jsonb
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_10_27_054756) do
ActiveRecord::Schema.define(version: 2019_11_16_073924) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -101,6 +102,7 @@
t.datetime "user_last_seen_at"
t.datetime "agent_last_seen_at"
t.boolean "locked", default: false
t.jsonb "additional_attributes"
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
t.index ["account_id"], name: "index_conversations_on_account_id"
end
Expand Down

0 comments on commit 88ac20e

Please sign in to comment.