forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from DigitalTolk/staging-webflow
feat: webflow webhook and ticket api
- Loading branch information
Showing
11 changed files
with
354 additions
and
37 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
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 @@ | ||
<p>You just got a form submission!</p> | ||
<br> | ||
|
||
<b>Form</b> | ||
<div><%= @form_name %></div> | ||
|
||
<br> | ||
<b>Site</b> | ||
<div>Digitaltolk</div> | ||
|
||
<br> | ||
<div><b>Submitted content</b></div> | ||
<% if @content.present? %> | ||
<% @content.each do |key, value| %> | ||
<div><%= key %>: <%= value %></div> | ||
<% 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,10 @@ | ||
class DigitaltolkEmailWorker | ||
include Sidekiq::Worker | ||
sidekiq_options queue: :mailers, retry: 3 | ||
|
||
def perform(params) | ||
data = JSON.parse(params).with_indifferent_access | ||
|
||
Digitaltolk::DigitaltolkMailer.send_email(data).deliver_later | ||
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
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,69 @@ | ||
class Digitaltolk::AddConversationService | ||
attr_accessor :inbox_id, :params | ||
|
||
def initialize(inbox_id, params) | ||
@inbox_id = inbox_id | ||
@params = params | ||
end | ||
|
||
def perform | ||
find_or_create_contact | ||
|
||
ConversationBuilder.new(params: ActionController::Parameters.new(conversation_params), contact_inbox: @contact_inbox).perform | ||
end | ||
|
||
private | ||
|
||
def inbox | ||
@inbox ||= Inbox.find_by(id: @inbox_id) | ||
end | ||
|
||
def find_or_create_contact | ||
@contact = inbox.contacts.find_by(email: email_address) | ||
|
||
if @contact.present? | ||
@contact_inbox = ContactInbox.find_by(inbox: @inbox, contact: @contact) | ||
else | ||
create_contact | ||
end | ||
end | ||
|
||
def create_contact | ||
@contact_inbox = ::ContactInboxWithContactBuilder.new( | ||
source_id: email_address, | ||
inbox: inbox, | ||
contact_attributes: { | ||
name: identify_contact_name, | ||
email: email_address, | ||
additional_attributes: { | ||
source_id: "email:" | ||
} | ||
} | ||
).perform | ||
@contact = @contact_inbox.contact | ||
end | ||
|
||
def email_address | ||
params.dig(:email) | ||
end | ||
|
||
def identify_contact_name | ||
email_address.split('@').first | ||
end | ||
|
||
def conversation_params | ||
{ | ||
account_id: params.dig(:account_id), | ||
assignee_id: params.dig(:assignee_id), | ||
contact_id: @contact.id, | ||
inbox_id: params.dig(:inbox_id), | ||
source_id: params.dig(:email), | ||
additional_attributes: { | ||
mail_subject: params.dig(:subject) | ||
}, | ||
message: { | ||
content: params.dig(:content) | ||
} | ||
} | ||
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,35 @@ | ||
class Digitaltolk::AddMessageService | ||
attr_accessor :sender, :conversation, :content, :is_incoming | ||
|
||
def initialize(sender, conversation, content, is_incoming = false) | ||
@conversation = conversation | ||
@content = content | ||
@sender = sender | ||
@is_incoming = is_incoming | ||
end | ||
|
||
def perform | ||
return unless @conversation.present? | ||
|
||
create_message | ||
end | ||
|
||
private | ||
|
||
def create_message | ||
return unless content.present? | ||
|
||
Messages::MessageBuilder.new(sender, @conversation, message_params).perform | ||
end | ||
|
||
def message_type | ||
is_incoming ? 'incoming' : 'outgoing' | ||
end | ||
|
||
def message_params | ||
{ | ||
message_type: message_type, | ||
content: content | ||
} | ||
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,22 @@ | ||
class Digitaltolk::DigitaltolkMailer < ApplicationMailer | ||
def send_email(params) | ||
return unless smtp_config_set_or_development? | ||
return unless params.dig(:to).present? | ||
return unless params.dig(:from).present? | ||
|
||
@form_name = params.dig(:form_name) | ||
@content = params.dig(:data) | ||
|
||
email_params = { | ||
to: params.dig(:to), | ||
reply_to: params.dig(:from), | ||
subject: params.dig(:subject) | ||
} | ||
|
||
mail(email_params) do |format| | ||
format.html do | ||
render 'mailers/digitaltolk_mailer/send_email', layout: false | ||
end | ||
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
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
Oops, something went wrong.