Add admin support contact form
This commit is contained in:
parent
5053d4a7d9
commit
b9af07b845
7 changed files with 155 additions and 4 deletions
|
@ -3,6 +3,8 @@ class Helpscout::API
|
|||
CONVERSATIONS = 'conversations'
|
||||
TAGS = 'tags'
|
||||
FIELDS = 'fields'
|
||||
CUSTOMERS = 'customers'
|
||||
PHONES = 'phones'
|
||||
OAUTH2_TOKEN = 'oauth2/token'
|
||||
|
||||
def add_tags(conversation_id, tags)
|
||||
|
@ -42,6 +44,21 @@ class Helpscout::API
|
|||
call_api(:post, CONVERSATIONS, body)
|
||||
end
|
||||
|
||||
def add_phone_number(email, phone)
|
||||
query = URI.encode("(email:#{email})")
|
||||
response = call_api(:get, "#{CUSTOMERS}?mailbox=#{mailbox_id}&query=#{query}")
|
||||
if response.success?
|
||||
body = parse_response_body(response)
|
||||
if body[:page][:totalElements] > 0
|
||||
customer_id = body[:_embedded][:customers].first[:id]
|
||||
call_api(:post, "#{CUSTOMERS}/#{customer_id}/#{PHONES}", {
|
||||
type: "work",
|
||||
value: phone
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def attachments(file)
|
||||
|
|
|
@ -20,6 +20,18 @@ class Helpscout::FormAdapter
|
|||
[I18n.t(TYPE_AUTRE, scope: [:support]), TYPE_AUTRE]
|
||||
]
|
||||
|
||||
ADMIN_TYPE_RDV = 'admin demande rdv'
|
||||
ADMIN_TYPE_QUESTION = 'admin question'
|
||||
ADMIN_TYPE_SOUCIS = 'admin soucis'
|
||||
ADMIN_TYPE_AUTRE = 'admin autre'
|
||||
|
||||
ADMIN_OPTIONS = [
|
||||
[I18n.t(ADMIN_TYPE_QUESTION, scope: [:supportadmin]), ADMIN_TYPE_QUESTION],
|
||||
[I18n.t(ADMIN_TYPE_RDV, scope: [:supportadmin]), ADMIN_TYPE_RDV],
|
||||
[I18n.t(ADMIN_TYPE_SOUCIS, scope: [:supportadmin]), ADMIN_TYPE_SOUCIS],
|
||||
[I18n.t(ADMIN_TYPE_AUTRE, scope: [:supportadmin]), ADMIN_TYPE_AUTRE]
|
||||
]
|
||||
|
||||
def send_form
|
||||
conversation_id = create_conversation
|
||||
|
||||
|
@ -51,6 +63,11 @@ class Helpscout::FormAdapter
|
|||
params[:file]
|
||||
)
|
||||
|
||||
response.success? ? response.headers['Resource-ID'] : nil
|
||||
if response.success?
|
||||
if params[:phone].present?
|
||||
@api.add_phone_number(params[:email], params[:phone])
|
||||
end
|
||||
response.headers['Resource-ID']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue