Module: Sinbotra::Messenger::Handler::ClassMethods
- Defined in:
- lib/sinbotra/messenger/handler.rb
Defined Under Namespace
Classes: DefaultListener, Listener, Postback
Constant Summary
collapse
- GET_STARTED_ID =
"GET_STARTED"
Instance Method Summary
collapse
Instance Method Details
#action(name, &blk) ⇒ Object
71
72
73
74
|
# File 'lib/sinbotra/messenger/handler.rb', line 71
def action(name, &blk)
@actions ||= {}
@actions[name] = blk
end
|
#conversation(id) {|c| ... } ⇒ Object
#enable_get_started! ⇒ Object
33
34
35
36
|
# File 'lib/sinbotra/messenger/handler.rb', line 33
def enable_get_started!
@client = MessengerClient::Client.new(ENV.fetch("FACEBOOK_PAGE_TOKEN"))
@client.get_started(GET_STARTED_ID)
end
|
#get_intent(text) ⇒ Object
76
77
78
79
|
# File 'lib/sinbotra/messenger/handler.rb', line 76
def get_intent(text)
puts "NOOP get_intent"
nil
end
|
#get_started(&blk) ⇒ Object
38
39
40
|
# File 'lib/sinbotra/messenger/handler.rb', line 38
def get_started(&blk)
postback(GET_STARTED_ID, &blk)
end
|
#handle_message(msg) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/sinbotra/messenger/handler.rb', line 16
def handle_message(msg)
user = Sinbotra::Messenger::User.load(msg)
bot = Sinbotra::Messenger::Bot.new(user)
if user.in_conversation?
convo = user.current_conversation
convo.perform_current_step(bot)
elsif intent = match_intent(bot)
intent.callback.(bot) unless intent.nil?
else
intent = default_intent
intent.callback.(bot) unless intent.nil?
end
end
|
#hear(matcher = nil, &blk) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/sinbotra/messenger/handler.rb', line 62
def hear(matcher=nil, &blk)
@listeners ||= []
if matcher.nil?
return @listeners << DefaultListener.new(blk)
end
@listeners << Listener.new(matcher, blk)
end
|
#next_dont_understand_phrase ⇒ Object
89
90
91
|
# File 'lib/sinbotra/messenger/handler.rb', line 89
def next_dont_understand_phrase
puts "NOOP next_dont_understand_phrase"
end
|
#postback(matcher, &blk) ⇒ Object
56
57
58
59
60
|
# File 'lib/sinbotra/messenger/handler.rb', line 56
def postback(matcher, &blk)
@postbacks ||= []
@postbacks << Postback.new(matcher, blk)
end
|
#typing(delay = 1) ⇒ Object
85
86
87
|
# File 'lib/sinbotra/messenger/handler.rb', line 85
def typing(delay=1)
puts "NOOP show typing for #{delay} seconds"
end
|
#yes?(str) ⇒ Boolean
81
82
83
|
# File 'lib/sinbotra/messenger/handler.rb', line 81
def yes?(str)
str =~ yes_matcher
end
|