Module: Rubotnik

Defined in:
lib/rubotnik.rb,
lib/rubotnik/cli.rb,
lib/rubotnik/helpers.rb,
lib/rubotnik/version.rb,
lib/rubotnik/autoloader.rb,
lib/rubotnik/message_dispatch.rb,
lib/rubotnik/postback_dispatch.rb

Defined Under Namespace

Modules: Autoloader, Helpers Classes: CLI, Generator, MessageDispatch, PostbackDispatch, User, UserStore

Constant Summary collapse

VERSION =
"0.2.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



26
27
28
29
30
# File 'lib/rubotnik.rb', line 26

def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = name
  end
end

Class Method Details

.route(event, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubotnik.rb', line 32

def route(event, &block)
  if %i[message postback].include?(event)
    Bot.on event do |e|
      case e
      when Facebook::Messenger::Incoming::Message
        Rubotnik::MessageDispatch.new(e).route(&block)
      when Facebook::Messenger::Incoming::Postback
        Rubotnik::PostbackDispatch.new(e).route(&block)
      end
    end
  else
    Bot.on(event, &block)
  end
end

.set_profile(*payloads) ⇒ Object



54
55
56
57
58
# File 'lib/rubotnik.rb', line 54

def set_profile(*payloads)
  payloads.each do |payload|
    Facebook::Messenger::Profile.set(payload, access_token: ENV['ACCESS_TOKEN'])
  end
end

.subscribe(token) ⇒ Object



47
48
49
50
51
52
# File 'lib/rubotnik.rb', line 47

def subscribe(token)
  Facebook::Messenger::Subscriptions.subscribe(
    access_token: token,
    subscribed_fields: %w[messages messaging_postbacks]
  )
end