Class: SignalWire::Prefabs::Concierge

Inherits:
Object
  • Object
show all
Defined in:
lib/signalwire/prefabs/concierge.rb

Overview

Prefab agent for providing virtual concierge services.

agent = Concierge.new(
  venue_name: 'Grand Hotel',
  services: ['room service', 'spa bookings'],
  amenities: { 'pool' => { 'hours' => '7 AM - 10 PM', 'location' => '2nd Floor' } }
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(venue_name:, services:, amenities:, hours_of_operation: nil, special_instructions: nil, welcome_message: nil, name: 'concierge', route: '/concierge', **_opts) ⇒ Concierge

Returns a new instance of Concierge.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/signalwire/prefabs/concierge.rb', line 23

def initialize(venue_name:, services:, amenities:, hours_of_operation: nil,
               special_instructions: nil, welcome_message: nil,
               name: 'concierge', route: '/concierge', **_opts)
  @venue_name     = venue_name
  @services       = services || []
  @amenities      = (amenities || {}).transform_keys(&:to_s)
  @hours          = hours_of_operation
  @instructions   = special_instructions || []
  @welcome        = welcome_message || "Welcome to #{venue_name}! How can I assist you today?"
  @name  = name
  @route = route
end

Instance Attribute Details

#amenitiesObject (readonly)

Returns the value of attribute amenities.



21
22
23
# File 'lib/signalwire/prefabs/concierge.rb', line 21

def amenities
  @amenities
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/signalwire/prefabs/concierge.rb', line 21

def name
  @name
end

#routeObject (readonly)

Returns the value of attribute route.



21
22
23
# File 'lib/signalwire/prefabs/concierge.rb', line 21

def route
  @route
end

#servicesObject (readonly)

Returns the value of attribute services.



21
22
23
# File 'lib/signalwire/prefabs/concierge.rb', line 21

def services
  @services
end

#venue_nameObject (readonly)

Returns the value of attribute venue_name.



21
22
23
# File 'lib/signalwire/prefabs/concierge.rb', line 21

def venue_name
  @venue_name
end

Instance Method Details

#global_dataObject



62
63
64
65
66
67
68
# File 'lib/signalwire/prefabs/concierge.rb', line 62

def global_data
  {
    'venue_name' => @venue_name,
    'services'   => @services,
    'amenities'  => @amenities
  }
end

#handle_amenity_info(args, _raw_data) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/signalwire/prefabs/concierge.rb', line 70

def handle_amenity_info(args, _raw_data)
  amenity = (args['amenity'] || '').downcase
  info = @amenities.find { |k, _v| k.downcase == amenity }&.last
  if info
    detail = info.is_a?(Hash) ? info.map { |k, v| "#{k}: #{v}" }.join(', ') : info.to_s
    Swaig::FunctionResult.new("#{amenity.capitalize}: #{detail}")
  else
    Swaig::FunctionResult.new("I don't have information about '#{amenity}'. Available amenities: #{@amenities.keys.join(', ')}")
  end
end

#handle_service_info(args, _raw_data) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/signalwire/prefabs/concierge.rb', line 81

def handle_service_info(args, _raw_data)
  service = (args['service'] || '').downcase
  match = @services.find { |s| s.downcase.include?(service) }
  if match
    Swaig::FunctionResult.new("#{match} is available at #{@venue_name}.")
  else
    Swaig::FunctionResult.new("Available services: #{@services.join(', ')}")
  end
end

#prompt_sectionsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/signalwire/prefabs/concierge.rb', line 40

def prompt_sections
  amenity_bullets = @amenities.map { |k, v| "#{k}: #{v.is_a?(Hash) ? v.map { |a, b| "#{a}: #{b}" }.join(', ') : v}" }
  service_bullets = @services.map { |s| s.to_s }

  sections = [
    {
      'title' => "#{@venue_name} Concierge",
      'body' => @welcome,
      'bullets' => service_bullets + amenity_bullets
    }
  ]

  if @hours
    sections << {
      'title' => 'Hours of Operation',
      'body' => @hours.is_a?(Hash) ? @hours.map { |k, v| "#{k}: #{v}" }.join('; ') : @hours.to_s
    }
  end

  sections
end

#toolsObject



36
37
38
# File 'lib/signalwire/prefabs/concierge.rb', line 36

def tools
  %w[get_amenity_info get_service_info]
end