Class: BoltRb::Assistant::MemoryThreadContextStore
- Inherits:
-
Object
- Object
- BoltRb::Assistant::MemoryThreadContextStore
- Defined in:
- lib/bolt_rb/assistant/memory_thread_context_store.rb
Overview
In-memory store for assistant thread context.
Slack sends the user's active channel with assistant_thread_started
and assistant_thread_context_changed. This store keeps that context
so later user messages in the same thread can read it.
Data lives only in the current process. Give
BoltRb.configuration.assistant_thread_context_store an object with
the same get and save methods to persist across processes.
Instance Method Summary collapse
-
#get(channel_id:, thread_ts:) ⇒ Hash?
Read the saved context for a thread.
-
#initialize ⇒ MemoryThreadContextStore
constructor
A new instance of MemoryThreadContextStore.
-
#save(channel_id:, thread_ts:, context:) ⇒ void
Save the context for a thread.
Constructor Details
#initialize ⇒ MemoryThreadContextStore
Returns a new instance of MemoryThreadContextStore.
27 28 29 30 |
# File 'lib/bolt_rb/assistant/memory_thread_context_store.rb', line 27 def initialize @contexts = {} @mutex = Mutex.new end |
Instance Method Details
#get(channel_id:, thread_ts:) ⇒ Hash?
Read the saved context for a thread
37 38 39 |
# File 'lib/bolt_rb/assistant/memory_thread_context_store.rb', line 37 def get(channel_id:, thread_ts:) @mutex.synchronize { @contexts[key(channel_id, thread_ts)] } end |
#save(channel_id:, thread_ts:, context:) ⇒ void
This method returns an undefined value.
Save the context for a thread
47 48 49 |
# File 'lib/bolt_rb/assistant/memory_thread_context_store.rb', line 47 def save(channel_id:, thread_ts:, context:) @mutex.synchronize { @contexts[key(channel_id, thread_ts)] = context } end |