-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature basic chatwoot integration (#13)
* Continue integration.. * Fix chatwoot create flow * Init embedding view * Embedding continue implementation * Authentication flow * Frontend init * Improve embeding layout * Backend search, create and show contact * Remove duplicate code and UI improves * css code improves * Remove unecessary codes and improves authenticate flow
- Loading branch information
Showing
28 changed files
with
647 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: bin/rails server -p 3000 | ||
web: bin/rails server -p 3001 | ||
css: bin/rails tailwindcss:watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.w-btn-block { | ||
color: #888599 !important; | ||
border-radius: 5px; | ||
border: 1.8px solid #F2F1F7; | ||
padding: 10px !important; | ||
i { | ||
font-size: 15px !important; | ||
margin: 0px !important; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.w-btn-outline { | ||
font-weight: 600; | ||
font-size: 12px; | ||
line-height: 30px; | ||
padding: 0.3rem 0.8rem; | ||
letter-spacing: .5px; | ||
|
||
color: #6857D9; | ||
background-color: #FFFFFF; | ||
border: 1.5px solid #F2F1F7; | ||
border-radius: 5px; | ||
} | ||
|
||
.w-btn-outline:hover { | ||
border-radius: 5px; | ||
border: 1.5px solid #D9DEFF; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.component-chatwoot-embed{ | ||
padding: 32px; | ||
background-color: #F6F8FE; | ||
p { | ||
margin-bottom: 0px; | ||
} | ||
|
||
input[disabled] { | ||
background-color: #FFF; | ||
} | ||
button { | ||
background: none !important; | ||
} | ||
|
||
.btn-clock { | ||
border-radius: 5px; | ||
border: 1.5px solid #FBE0D8; | ||
background: #FAEEEB; | ||
color: #CF4F27; | ||
padding-left: 5px; | ||
padding-right: 5px; | ||
svg { | ||
height: 16px; | ||
} | ||
} | ||
|
||
.custom-btn-user { | ||
color: #888599 !important; | ||
border-radius: 5px; | ||
border: 1.8px solid #F2F1F7; | ||
padding: 10px !important; | ||
i { | ||
font-size: 15px !important; | ||
margin: 0px !important; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/controllers/accounts/contacts/chatwoot_embed_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
class Accounts::Contacts::ChatwootEmbedController < InternalController | ||
layout "embed" | ||
before_action :set_contact, only: %i[ show ] | ||
|
||
def search | ||
contact = contact_search | ||
|
||
if contact.present? | ||
redirect_to account_chatwoot_embed_path(current_user.account, contact) | ||
else | ||
redirect_to new_account_chatwoot_embed_path(current_user.account, chatwoot_contact: params['chatwoot_contact']) | ||
end | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
chatwoot_contact = JSON.parse(params['chatwoot_contact']) | ||
@contact = current_user.account.contacts.new({ | ||
full_name: chatwoot_contact['name'], | ||
email: chatwoot_contact['email'], | ||
phone: chatwoot_contact['phone_number'], | ||
additional_attributes: {'chatwoot_id': chatwoot_contact['id']} | ||
}) | ||
end | ||
|
||
def create | ||
@contact = current_user.account.contacts.new(contact_params) | ||
|
||
if @contact.save | ||
redirect_to account_chatwoot_embed_path(current_user.account, @contact), notice: "Contact was successfully created." | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
def set_contact | ||
@contact = Contact.find(params[:id]) | ||
end | ||
|
||
def contact_params | ||
params.require(:contact).permit(:full_name, :phone, :email, additional_attributes: {}) | ||
end | ||
|
||
def chatwoot_contact | ||
@chatwoot_contact ||= JSON.parse(params['chatwoot_contact']) | ||
end | ||
|
||
def contact_search() | ||
if chatwoot_contact['email'].present? && chatwoot_contact['phone_number'].present? | ||
return current_user.account.contacts.where( | ||
":chatwoot_id <@ additional_attributes OR email LIKE :email OR phone LIKE :phone", | ||
chatwoot_id: { chatwoot_id: "#{chatwoot_contact['id']}" }.to_json, | ||
email: "#{chatwoot_contact['email']}", | ||
phone: "#{chatwoot_contact['phone_number']}" | ||
).first | ||
elsif chatwoot_contact['email'].present? | ||
return current_user.account.contacts.where( | ||
":chatwoot_id <@ additional_attributes OR email LIKE :email", | ||
chatwoot_id: { chatwoot_id: "#{chatwoot_contact['id']}" }.to_json, | ||
email: "#{chatwoot_contact['email']}" | ||
).first | ||
elsif chatwoot_contact['phone_number'].present? | ||
return current_user.account.contacts.where( | ||
":chatwoot_id <@ additional_attributes OR phone LIKE :phone", | ||
chatwoot_id: { chatwoot_id: "#{chatwoot_contact['id']}" }.to_json, | ||
phone: "#{chatwoot_contact['phone_number']}" | ||
).first | ||
else | ||
return current_user.account.contacts.where( | ||
":chatwoot_id <@ additional_attributes", | ||
chatwoot_id: { chatwoot_id: "#{chatwoot_contact['id']}" }.to_json | ||
).first | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class Apps::ChatwootsController < ActionController::Base | ||
before_action :load_chatwoot, execpt: :webhooks | ||
before_action :authenticate_by_token, if: -> { current_user.blank? } | ||
skip_before_action :verify_authenticity_token, execpt: :embedding | ||
layout "embed" | ||
|
||
def webhooks | ||
render json: { ok: true }, status: 200 | ||
end | ||
|
||
def embedding | ||
end | ||
|
||
def embedding_init_authenticate | ||
@token = params['token'] | ||
end | ||
|
||
def embedding_authenticate | ||
event = JSON.parse(params['event']) | ||
user_email = event['data']['currentAgent']['email'] | ||
user = User.find_by(email: user_email, account_id: @chatwoot.account_id) | ||
return render plain: "User not found", status: 400 if user.blank? | ||
sign_in(user) | ||
redirect_to embedding_apps_chatwoots_path() | ||
end | ||
|
||
private | ||
|
||
def authenticate_by_token | ||
if @chatwoot.present? && action_name == 'embedding' | ||
redirect_to embedding_init_authenticate_apps_chatwoots_path(token: params['token']) if action_name != 'embedding_authenticate' | ||
else | ||
render plain: "Unauthorized", status: 400 if @chatwoot.blank? | ||
end | ||
end | ||
|
||
def load_chatwoot | ||
@chatwoot = Apps::Chatwoot.find_by(embedding_token: params['token']) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.