Module: Ambo::Contexts::Periodic

Included in:
Ambo::Context
Defined in:
lib/ambo/contexts/periodic.rb

Overview

Context methods for defining bots with Periodic functionality.

Instance Method Summary collapse

Instance Method Details

#every(min, max = nil, repeat_after: nil) ⇒ Ambo::Context


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ambo/contexts/periodic.rb', line 14

def every(min, max = nil, repeat_after: nil)
  config.every = {}

  if max.nil?
    config.every[:delay] = validate(min)
  else
    config.every.update(min: validate(min), max: validate(max))
  end

  config.every[:repeat_after] = repeat_after
end

#next_message {|last_message| ... } ⇒ Object

Yields:

  • (last_message)

    A block that is called to generate the next message

Yield Parameters:

  • last (Message)

    message sent, if any


29
30
31
# File 'lib/ambo/contexts/periodic.rb', line 29

def next_message(&block)
  config.on_next_message = block
end

#periodic?TrueClass, FalseClass


34
35
36
# File 'lib/ambo/contexts/periodic.rb', line 34

def periodic?
  !config.every.blank?
end