Skip to content

Commit

Permalink
resolve unmerged
Browse files Browse the repository at this point in the history
  • Loading branch information
versedpro committed Sep 11, 2020
2 parents 6db445c + fa29606 commit 41918d1
Show file tree
Hide file tree
Showing 8,127 changed files with 61,688 additions and 47 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
115 changes: 115 additions & 0 deletions .env~
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Used to verify the integrity of signed cookies. so ensure a secure value is set
SECRET_KEY_BASE=30qE5OWUlCcCEjV0TJMByWY6hECxq2cbmPcRxQIEILzU4NqQUF4TIOTn4TzkzMj

# Replace with the URL you are planning to use for your app
FRONTEND_URL=http://chat.textyomni.com

# Force all access to the app over SSL, default is set to false
FORCE_SSL=false

# This lets you control new sign ups on your chatwoot installation
# true : default option, allows sign ups
# false : disables all the end points related to sign ups
# api_only: disables the UI for signup, but you can create sign ups via the account apis
ENABLE_ACCOUNT_SIGNUP=true

# Redis config
REDIS_URL=redis://localhost:6379
# If you are using docker-compose, set this variable's value to be any string,
# which will be the password for the redis service running inside the docker-compose
# to make it secure
REDIS_PASSWORD=

# Postgres Database config variables
POSTGRES_HOST=localhost
POSTGRES_USERNAME=chatwoot
POSTGRES_PASSWORD=m5Say5OZAjVU6Oi
RAILS_ENV=production
RAILS_MAX_THREADS=5

# Mail outgoing
[email protected]
#SMTP_PORT=1025
SMTP_PORT=587
SMTP_DOMAIN=textyomni.com
# if you are running docker-compose, set SMTP_ADDRESS value as "mailhog",
# else set the value as "localhost"
SMTP_ADDRESS=smtp.sendgrid.net
SMTP_USERNAME=apikey
SMTP_PASSWORD=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
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS_AUTO=true

# Mail Incoming
# This is the domain set for the reply emails when conversation continuity is enabled
MAILER_INBOUND_EMAIL_DOMAIN=usg.mail.textyomni.com
# Set this to appropriate ingress channel with regards to incoming emails
# Possible values are :
# :relay for Exim, Postfix, Qmail
# :mailgun for Mailgun
# :mandrill for Mandrill
# :postmark for Postmark
# :sendgrid for Sendgrid
RAILS_INBOUND_EMAIL_SERVICE=:sendgrid
# Use one of the following based on the email ingress service
# Ref: https://edgeguides.rubyonrails.org/action_mailbox_basics.html
RAILS_INBOUND_EMAIL_PASSWORD=x3fGwQ95vStP
MAILGUN_INGRESS_SIGNING_KEY=
MANDRILL_INGRESS_API_KEY=

# Storage
ACTIVE_STORAGE_SERVICE=local

# Amazon S3
# documentation: https://www.chatwoot.com/docs/configuring-s3-bucket-as-cloud-storage
S3_BUCKET_NAME=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=

# Sentry
SENTRY_DSN=

# Log settings
# Disable if you want to write logs to a file
RAILS_LOG_TO_STDOUT=true
LOG_LEVEL=info
LOG_SIZE=500

### This environment variables are only required if you are setting up social media channels

# Facebook
# documentation: https://www.chatwoot.com/docs/facebook-setup
FB_VERIFY_TOKEN=
FB_APP_SECRET=
FB_APP_ID=

# Twitter
# documentation: https://www.chatwoot.com/docs/twitter-app-setup
TWITTER_APP_ID=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ENVIRONMENT=

#slack integration
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=

### Change this env variable only if you are using a custom build mobile app
## Mobile app env variables
IOS_APP_ID=6C953F3RX2.com.chatwoot.app

## Push Notification
## generate a new key value here : https://d3v.one/vapid-key-generator/
VAPID_PUBLIC_KEY=BH5x28p4-mDyIEsHKvIC648hqM4kWuTxlxxIhXSUMt-ZK73JUDXDV1jKPSif4PlTEWRC7sXGRnzYFZJqFpaafRU
VAPID_PRIVATE_KEY=NGcV6dhwjhnNZLFsHIf73qk3fxnZZ_LwDO4ZtjWifiY
#
# for mobile apps
# FCM_SERVER_KEY=

## Bot Customizations
USE_INBOX_AVATAR_FOR_BOT=true

## Development Only Config
# if you want to use letter_opener for local emails
# LETTER_OPENER=true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node_modules

public/uploads
public/packs*
public/assets

# VIM files
*.swp
Expand Down Expand Up @@ -58,4 +59,5 @@ package-lock.json


# cypress
test/cypress/videos/*
test/cypress/videos/*
/config/master.key
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.1
2.7.1@chatwoot_signalwire
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ gem 'twitty'
gem 'koala'
# slack client
gem 'slack-ruby-client'
# signal wire client
gem 'signalwire'

##--- gems for debugging and error reporting ---##
# static analysis
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ GEM
railties (>= 3.2)
equalizer (0.0.11)
erubi (1.9.0)
eventmachine (1.2.7)
execjs (2.7.0)
facebook-messenger (1.5.0)
httparty (~> 0.13, >= 0.13.7)
Expand All @@ -196,6 +197,9 @@ GEM
multipart-post (>= 1.2, < 3)
faraday_middleware (1.0.0)
faraday (~> 1.0)
faye-websocket (0.11.0)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1)
fcm (1.0.2)
faraday (~> 1.0.0)
ffi (1.13.1)
Expand Down Expand Up @@ -236,6 +240,7 @@ GEM
activesupport (>= 5)
haikunator (1.1.0)
hana (1.3.6)
has-guarded-handlers (1.6.3)
hashdiff (1.0.1)
hashie (4.1.0)
hkdf (0.3.0)
Expand Down Expand Up @@ -283,6 +288,7 @@ GEM
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.4.2)
loofah (2.7.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -457,7 +463,14 @@ GEM
sidekiq (6.1.1)
connection_pool (>= 2.2.2)
rack (~> 2.0)
rack-protection (>= 2.0.0)
redis (>= 4.2.0)
signalwire (2.3.3)
concurrent-ruby (~> 1.1)
faye-websocket (~> 0.10)
has-guarded-handlers (~> 1.6.3)
logger (~> 1.3)
twilio-ruby (~> 5.0)
signet (0.14.0)
addressable (~> 2.3)
faraday (>= 0.17.3, < 2.0)
Expand Down Expand Up @@ -614,6 +627,7 @@ DEPENDENCIES
sentry-raven
shoulda-matchers
sidekiq
signalwire
simplecov (= 0.17.1)
slack-ruby-client
spring
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
class Api::V1::Accounts::Channels::SignalwireChannelsController < Api::V1::Accounts::BaseController
protect_from_forgery except: :create
before_action :authorize_request

def create
ActiveRecord::Base.transaction do
authenticate_signal_wire
build_inbox
setup_webhooks if @signal_wire_channel.sms?
render json: @inbox
rescue ::Twilio::REST::SignalwireError => e
render_could_not_create_error(e.message)
rescue StandardError => e
render_could_not_create_error(e.message)
end
end

private

def authorize_request
authorize ::Inbox
end

def authenticate_signal_wire
client = Signalwire::REST::Client.new(
permitted_params[:account_sid],
permitted_params[:auth_token],
signalwire_space_url: permitted_params[:space_url]
)
client.messages.list(limit: 1)
end

def setup_webhooks
::Signalwire::WebhookSetupService.new(inbox: @inbox).perform
end

def medium
permitted_params[:medium]
end

def build_inbox
@signal_wire_channel = Current.account.signalwire_sms.create!(
account_sid: permitted_params[:account_sid],
auth_token: permitted_params[:auth_token],
phone_number: permitted_params[:phone_number],
space_url: permitted_params[:space_url],
medium: medium
)
@inbox = Current.account.inboxes.create(
name: permitted_params[:name],
channel: @signal_wire_channel
)
end

def permitted_params
params.require(:signalwire_channel).permit(
:account_id, :phone_number, :account_sid, :space_url, :phone_number, :auth_token, :name, :medium
)
end
end
33 changes: 10 additions & 23 deletions app/controllers/api/v1/widget/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ def update
if @message.content_type == 'input_email'
@message.update!(submitted_email: contact_email)
update_contact(contact_email)
<<<<<<< HEAD
else
=======
elsif @message.content_type == 'form'
@message.update!(message_update_params[:message])
update_contact(contact_email_original, contact_name_original, contact_phone_number)
else
>>>>>>> 27387460... Upgrade bot enable to collect contact info at start widget
@message.update!(message_update_params[:message])
end
rescue StandardError => e
Expand All @@ -42,6 +38,7 @@ def build_attachment
)
attachment.file.attach(uploaded_attachment)
end
Rails.logger.debug "MESSAGE WILL BE SAVED WITH #{@message}"
@message.save!
end

Expand Down Expand Up @@ -94,17 +91,6 @@ def message_finder
@message_finder ||= MessageFinder.new(conversation, message_finder_params)
end

<<<<<<< HEAD
def update_contact(email)
contact_with_email = @account.contacts.find_by(email: email)
if contact_with_email
@contact = ::ContactMergeAction.new(
account: @account,
base_contact: contact_with_email,
mergee_contact: @contact
).perform
else
=======
def update_contact(email=nil, name=nil, phone_number=nil)
if email
contact_with_email = @account.contacts.find_by(email: email)
Expand All @@ -129,34 +115,35 @@ def update_contact(email=nil, name=nil, phone_number=nil)
end

if name
>>>>>>> 27387460... Upgrade bot enable to collect contact info at start widget
@contact.update!(
email: email,
name: contact_name
name: name,
phone_number: phone_number
)
end
end

def contact_email
permitted_params[:contact][:email].downcase
end
<<<<<<< HEAD
=======


def contact_email_original
permitted = params.permit(message: [{submitted_values: :value}])
permitted[:message][:submitted_values][2][:value]
end

def contact_name_original
permitted = params.permit(message: [{submitted_values: :value}])
permitted[:message][:submitted_values][0][:value]
end
>>>>>>> 27387460... Upgrade bot enable to collect contact info at start widget

def contact_name
contact_email.split('@')[0]
end

def contact_phone_number
permitted = params.permit(message: [{submitted_values: :value}])
permitted[:message][:submitted_values][1][:value]
end

def message_update_params
params.permit(message: [{ submitted_values: [:name, :title, :value] }])
Expand Down
44 changes: 44 additions & 0 deletions app/controllers/signalwire/callback_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Signalwire::CallbackController < ApplicationController
# protect_from_forgery with: :null_session
protect_from_forgery except: :create

def create
# {
# "SmsSid"=>"6487c887-4c02-43d5-9b3c-a9fb31b0ee80",
# "From"=>"+13305104190",
# "AccountSid"=>"ce607000-9d51-4699-85d3-f628a36da245",
# "MessageSid"=>"6487c887-4c02-43d5-9b3c-a9fb31b0ee80",
# "To"=>"+13305104190",
# "Body"=>"You've received a 12-character message. Upgrade your Trial account to view this message."
# }
# permitted_params example
# ToDo: remove
::Signalwire::IncomingMessageService.new(params: permitted_params).perform

head :no_content
end

private

def permitted_params
params.permit(
:ApiVersion,
:SmsSid,
:From,
:ToState,
:ToZip,
:AccountSid,
:MessageSid,
:FromCountry,
:ToCity,
:FromCity,
:To,
:FromZip,
:Body,
:ToCountry,
:FromState,
:MediaUrl0,
:MediaContentType0
)
end
end
Loading

0 comments on commit 41918d1

Please sign in to comment.