Class: BotPlatform::Adapter
- Inherits:
-
Object
- Object
- BotPlatform::Adapter
show all
- Includes:
- Asserts, Singleton
- Defined in:
- lib/bot_platform/adapter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#continue_conversation(bot_id, bot_cb_handler) ⇒ Object
-
#create_conversation(bot_id, channel_id, service_url, audience, bot_callback_handler, cancel_token) ⇒ Object
-
#delete_activity(turn_context, conversation, cancel_token) ⇒ Object
-
#initialize ⇒ Adapter
constructor
A new instance of Adapter.
-
#process_activity(headers, body, &block) ⇒ Object
-
#process_activity_async(claims_identity, activity, bot_callback_handler, cancel_token) ⇒ Object
-
#run_pipeline_async(turn_context, callback, cancel_token) ⇒ Object
-
#send_activities(turn_context, activities) ⇒ Object
-
#update_activity(turn_context, activity, cancel_token) ⇒ Object
Methods included from Asserts
#assert_activity_is_not_null, #assert_activity_list_is_not_null, #assert_activity_type_is_not_null, #assert_context_is_not_null, #assert_conversation_reference_is_not_null, #assert_dialog_context_is_valid, #assert_dialog_id_is_valid, #assert_dialog_is_uniq, #assert_dialog_is_valid, #assert_dialog_set_is_valid, #assert_dialog_state_is_valid, #assert_is_not_empty, #assert_middleware_is_not_null, #assert_middleware_list_is_not_null, #assert_prompt_options_is_valid, #assert_turn_context_is_valid, #assert_waterfall_step_context_is_valid
Constructor Details
Returns a new instance of Adapter.
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/bot_platform/adapter.rb', line 13
def initialize
@channels = []
@channel_map = {}
channels = ENV['BOT_CHANNELS']
raise 'No BOT_CHANNELS found in environment variables.' if channels.nil? || channels.length == 0
channels.split(',').each do |ch|
channel = Object.const_get("BotPlatform").const_get("Channels").const_get(ch.capitalize).new
@channels << channel
@channel_map[ch] = channel
end
end
|
Instance Attribute Details
#channel_map ⇒ Object
Returns the value of attribute channel_map.
11
12
13
|
# File 'lib/bot_platform/adapter.rb', line 11
def channel_map
@channel_map
end
|
#channels ⇒ Object
Returns the value of attribute channels.
11
12
13
|
# File 'lib/bot_platform/adapter.rb', line 11
def channels
@channels
end
|
Instance Method Details
#continue_conversation(bot_id, bot_cb_handler) ⇒ Object
43
44
|
# File 'lib/bot_platform/adapter.rb', line 43
def continue_conversation(bot_id, bot_cb_handler)
end
|
#create_conversation(bot_id, channel_id, service_url, audience, bot_callback_handler, cancel_token) ⇒ Object
46
47
|
# File 'lib/bot_platform/adapter.rb', line 46
def create_conversation(bot_id, channel_id, service_url, audience, bot_callback_handler, cancel_token)
end
|
#delete_activity(turn_context, conversation, cancel_token) ⇒ Object
40
41
|
# File 'lib/bot_platform/adapter.rb', line 40
def delete_activity(turn_context, conversation, cancel_token)
end
|
#process_activity(headers, body, &block) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/bot_platform/adapter.rb', line 52
def process_activity(, body, &block)
channel = nil
raise 'No channel registered.' if @channels.nil? || @channels.length==0
@channels.each do |ch|
if ch.match_request(, body)
channel = ch
break
end
end
raise 'No channel found' if channel.nil?
activity = channel.parse_incoming_to_activity(, body)
context = BotPlatform::TurnContext.new self, activity
block.call(context)
end
|
#process_activity_async(claims_identity, activity, bot_callback_handler, cancel_token) ⇒ Object
49
50
|
# File 'lib/bot_platform/adapter.rb', line 49
def process_activity_async(claims_identity, activity, bot_callback_handler, cancel_token)
end
|
#run_pipeline_async(turn_context, callback, cancel_token) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/bot_platform/adapter.rb', line 70
def run_pipeline_async(turn_context, callback, cancel_token)
assert_context_is_not_null(turn_context)
if turn_context.activity != nil
else
unless callback.nil?
callback(turn_context, cancel_token)
end
end
end
|
#send_activities(turn_context, activities) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/bot_platform/adapter.rb', line 26
def send_activities(turn_context, activities)
assert_context_is_not_null turn_context
assert_activity_is_not_null activities
assert_activity_is_not_null activities[0]
activities.each do |activity|
@channel_map[turn_context.channel_id].send_activity(activity)
end
end
|
#update_activity(turn_context, activity, cancel_token) ⇒ Object
36
37
38
|
# File 'lib/bot_platform/adapter.rb', line 36
def update_activity(turn_context, activity, cancel_token)
end
|