Class: SignalWire::Prefabs::Receptionist
- Inherits:
-
Object
- Object
- SignalWire::Prefabs::Receptionist
- Defined in:
- lib/signalwire/prefabs/receptionist.rb
Overview
Prefab agent for greeting callers and transferring them to departments.
agent = Receptionist.new(
departments: [
{ 'name' => 'sales', 'description' => 'Product inquiries', 'number' => '+15551235555' },
{ 'name' => 'support', 'description' => 'Technical help', 'number' => '+15551236666' }
]
)
Instance Attribute Summary collapse
-
#departments ⇒ Object
readonly
Returns the value of attribute departments.
-
#greeting ⇒ Object
readonly
Returns the value of attribute greeting.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #global_data ⇒ Object
- #handle_transfer(args, _raw_data) ⇒ Object
-
#initialize(departments:, name: 'receptionist', route: '/receptionist', greeting: 'Thank you for calling. How can I help you today?', **_opts) ⇒ Receptionist
constructor
A new instance of Receptionist.
- #prompt_sections ⇒ Object
- #tools ⇒ Object
Constructor Details
#initialize(departments:, name: 'receptionist', route: '/receptionist', greeting: 'Thank you for calling. How can I help you today?', **_opts) ⇒ Receptionist
Returns a new instance of Receptionist.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 24 def initialize(departments:, name: 'receptionist', route: '/receptionist', greeting: 'Thank you for calling. How can I help you today?', **_opts) raise ArgumentError, 'departments must be a non-empty Array' unless departments.is_a?(Array) && !departments.empty? departments.each_with_index do |d, i| d = d.transform_keys(&:to_s) raise ArgumentError, "Department #{i} missing 'name'" unless d['name'] raise ArgumentError, "Department #{i} missing 'number'" unless d['number'] end @departments = departments.map { |d| d.transform_keys(&:to_s) } @greeting = greeting @name = name @route = route end |
Instance Attribute Details
#departments ⇒ Object (readonly)
Returns the value of attribute departments.
22 23 24 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 22 def departments @departments end |
#greeting ⇒ Object (readonly)
Returns the value of attribute greeting.
22 23 24 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 22 def greeting @greeting end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 22 def name @name end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
22 23 24 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 22 def route @route end |
Instance Method Details
#global_data ⇒ Object
54 55 56 57 58 59 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 54 def global_data { 'departments' => @departments, 'caller_info' => {} } end |
#handle_transfer(args, _raw_data) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 61 def handle_transfer(args, _raw_data) dept_name = args['department'] dept = @departments.find { |d| d['name'] == dept_name } if dept result = Swaig::FunctionResult.new("Transferring you to #{dept_name} now.") result.connect(dept['number']) result else Swaig::FunctionResult.new("I couldn't find that department. Available departments: #{@departments.map { |d| d['name'] }.join(', ')}") end end |
#prompt_sections ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 43 def prompt_sections bullets = @departments.map { |d| "#{d['name']}: #{d['description'] || d['name']} (#{d['number']})" } [ { 'title' => 'Receptionist', 'body' => @greeting, 'bullets' => bullets } ] end |
#tools ⇒ Object
39 40 41 |
# File 'lib/signalwire/prefabs/receptionist.rb', line 39 def tools %w[transfer_to_department collect_caller_info] end |