Class: BotPlatform::ConversationState
- Inherits:
-
Object
- Object
- BotPlatform::ConversationState
- Includes:
- Singleton
- Defined in:
- lib/bot_platform/conversation_state.rb
Instance Attribute Summary collapse
-
#conversation ⇒ Object
Returns the value of attribute conversation.
Instance Method Summary collapse
- #get(turn_context) ⇒ Object
-
#initialize ⇒ ConversationState
constructor
A new instance of ConversationState.
- #set(context, key, value) ⇒ Object
Constructor Details
#initialize ⇒ ConversationState
Returns a new instance of ConversationState.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bot_platform/conversation_state.rb', line 9 def initialize user_id = turn_context.from.user_id room_id = turn_context.from.room_id key = "#{user_id}@#{room_id}" user_state = MemoryStorage.instance.get(key) || {} conversation_state = user_state[:conversation] || {} user_state[:conversation] = conversation_state MemoryStorage.instance.set(key, user_state) end |
Instance Attribute Details
#conversation ⇒ Object
Returns the value of attribute conversation.
6 7 8 |
# File 'lib/bot_platform/conversation_state.rb', line 6 def conversation @conversation end |
Instance Method Details
#get(turn_context) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/bot_platform/conversation_state.rb', line 20 def get(turn_context) user_id = turn_context.from.user_id room_id = turn_context.from.room_id key = "#{user_id}@#{room_id}" MemoryStorage.instance.get(key)[:conversation] end |
#set(context, key, value) ⇒ Object
28 29 30 |
# File 'lib/bot_platform/conversation_state.rb', line 28 def set(context, key, value) MemoryStorage.instance.get(context).set(key, value) end |