Module: Assistly::Client::Interaction

Included in:
Assistly::Client
Defined in:
lib/assistly/client/interaction.rb

Overview

Defines methods related to interactions

Instance Method Summary collapse

Instance Method Details

#create_inbound_interaction(*args) ⇒ Array

Creates an interaction from a customer

Examples:

Create a new interaction

Assistly.create_interaction(:interaction_subject => "this is an api test", :customer_email => "[email protected]")

Returns:

  • (Array)

    The requested users.

See Also:

Rate Limited:

  • true

Requires Authentication:

  • true

Supported formats:

  • :json



44
45
46
47
48
49
50
51
52
# File 'lib/assistly/client/interaction.rb', line 44

def create_inbound_interaction(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = post('interactions', options)
  if response['success']
    return response['results']
  else
    return response
  end
end

#create_interaction(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/assistly/client/interaction.rb', line 21

def create_interaction(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  if options[:direction].to_s == "outbound"
    options.delete(:direction)
    to      = options.delete(:customer_email)
    subject = options.delete(:interaction_subject)
    body    = options.delete(:interaction_body)
    
    create_outbound_interaction(to, subject, body, options)
  else
    create_inbound_interaction(options)
  end
end

#create_outbound_interaction(to, subject, body, *args) ⇒ Object

Create an interaction from an agent

Assistly's API doesn't support creating a new case/interaction initiated by an agent so we'll use send an email to the customer directly that is BCC'd to the support email address which will create the ticket



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/assistly/client/interaction.rb', line 62

def create_outbound_interaction(to, subject, body, *args)
  raise Assistly::SupportEmailNotSet if support_email.blank?
  options = args.last.is_a?(Hash) ? args.pop : {}
  options.merge!(:to => to, :subject => subject, :body => body, :from => support_email, :bcc => support_email)
  headers = { "x-assistly-customer-email" => to, 
              "x-assistly-interaction-direction" => "out",
              "x-assistly-case-status" => options[:status]||"open"}
  headers.merge!(options[:headers]) if options[:headers]
  options.merge!(:headers => headers)
  Pony.mail(options)
end

#interactions(*args) ⇒ Object

Returns extended information of up to 100 interactions

@option options [Boolean, String, Integer] @example Return extended information for 12345 Assistly.interactions(:since_id => 12345) Assistly.interactions(:since_id => 12345, :count => 5)

See Also:

Requires Authentication:

  • true

Supported formats:

  • :json



15
16
17
18
19
# File 'lib/assistly/client/interaction.rb', line 15

def interactions(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  response = get("interactions",options)
  response
end