Class: Agents::TtsAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_tts_agent/tts_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



100
101
102
# File 'lib/huginn_tts_agent/tts_agent.rb', line 100

def check
  trigger_action
end

#default_optionsObject



52
53
54
55
56
57
58
59
60
# File 'lib/huginn_tts_agent/tts_agent.rb', line 52

def default_options
  {
    'type' => 'elevenlabs',
    'api_key' => '',
    'text' => '',
    'debug' => 'false',
    'expected_receive_period_in_days' => '2',
  }
end

#receive(incoming_events) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/huginn_tts_agent/tts_agent.rb', line 91

def receive(incoming_events)
  incoming_events.each do |event|
    interpolate_with(event) do
      log event
      trigger_action
    end
  end
end

#validate_optionsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/huginn_tts_agent/tts_agent.rb', line 67

def validate_options
  errors.add(:base, "type has invalid value: should be 'elevenlabs'") if interpolated['type'].present? && !%w(elevenlabs).include?(interpolated['type'])

  unless options['api_key'].present? || !['elevenlabs'].include?(options['type'])
    errors.add(:base, "api_key is a required field")
  end

  unless options['text'].present?
    errors.add(:base, "text is a required field")
  end

  if options.has_key?('debug') && boolify(options['debug']).nil?
    errors.add(:base, "if provided, debug must be true or false")
  end

  unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
    errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
  end
end

#working?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/huginn_tts_agent/tts_agent.rb', line 87

def working?
  event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
end