class BotFramework::Bot
Attributes
recognizers[RW]
Public Class Methods
add_recognizer(recognizer)
click to toggle source
# File lib/bot_framework/bot.rb, line 21 def add_recognizer(recognizer) recognizers << recognizer end
conversation_data(activity)
click to toggle source
# File lib/bot_framework/bot.rb, line 73 def conversation_data(activity) BotFramework::BotState.new('').get_conversation_data( 'channel_id' => activity.channel_id, 'conversation_id' => activity.conversation.id ).data || {} end
hooks()
click to toggle source
# File lib/bot_framework/bot.rb, line 80 def hooks @hooks ||= {} end
intent_callbacks()
click to toggle source
# File lib/bot_framework/bot.rb, line 88 def intent_callbacks @intent_callbacks ||= {} end
on(event, &block)
click to toggle source
# File lib/bot_framework/bot.rb, line 7 def on(event, &block) hooks[event] = block end
on_intent(intent, &block)
click to toggle source
# File lib/bot_framework/bot.rb, line 11 def on_intent(intent, &block) intent_callbacks[intent] = block end
receive(payload)
click to toggle source
# File lib/bot_framework/bot.rb, line 47 def receive(payload) trigger(payload.type.to_sym) # Run on default trigger(:activity, payload) recognizers.each do |recognizer| recognizer.recognize(message: payload.as_json) do |_error, intents| trigger_intent_call_back(intents[:intent], payload, intents) if intents[:intent] end end end
recognizer=(recognizer)
click to toggle source
# File lib/bot_framework/bot.rb, line 15 def recognizer=(recognizer) warn "DEPRECATED: Use add_recognizer method instead" add_recognizer(recognizer) end
reply(activity, message = '')
click to toggle source
# File lib/bot_framework/bot.rb, line 58 def reply(activity, message = '') activity.reply(message) end
reset_hooks()
click to toggle source
# File lib/bot_framework/bot.rb, line 84 def reset_hooks @hooks = {} end
set_conversation_data(activity, data)
click to toggle source
# File lib/bot_framework/bot.rb, line 66 def set_conversation_data(activity, data) data = BotFramework::BotData.new(data: data, e_tag: '*') if data.is_a? Hash BotFramework::BotState.new('').set_conversation_data('channel_id' => activity.channel_id, 'conversation_id' => activity.conversation.id, 'bot_data' => data) end
trigger(event, *args)
click to toggle source
# File lib/bot_framework/bot.rb, line 29 def trigger(event, *args) # hooks.fetch(event).call(*args) if hooks[event].nil? BotFramework.logger.info "No call back registered for #{event}" return false end instance_exec(*args, &hooks.fetch(event)) end
trigger_intent_call_back(intent, *args)
click to toggle source
# File lib/bot_framework/bot.rb, line 38 def trigger_intent_call_back(intent, *args) if intent_callbacks[intent].nil? BotFramework.logger.info "No call back registered for #{intent}" trigger_intent_call_back(:default, *args) if intent_callbacks[:default] return false end instance_exec(*args, &intent_callbacks.fetch(intent)) end
user_data=(data)
click to toggle source
# File lib/bot_framework/bot.rb, line 62 def user_data=(data) BotFramework.logger.info "Data set as #{data}" end