Class: ChatSDK::Thread
- Inherits:
-
Object
- Object
- ChatSDK::Thread
- Defined in:
- lib/chat_sdk/thread.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#chat ⇒ Object
readonly
Returns the value of attribute chat.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #delete(message_id) ⇒ Object
- #edit(message_id, content) ⇒ Object
- #hash ⇒ Object
-
#initialize(id:, channel_id:, adapter:, chat:) ⇒ Thread
constructor
A new instance of Thread.
- #mention_user(user_id) ⇒ Object
- #messages(cursor: nil, limit: 50) ⇒ Object
- #open_modal(trigger_id:, modal:) ⇒ Object
- #post(content) ⇒ Object
- #post_ai_stream(enumerable, placeholder: "Thinking...") ⇒ Object
- #post_ephemeral(content, user_id:) ⇒ Object
- #post_stream(placeholder: nil, &block) ⇒ Object
- #react(message_id, emoji) ⇒ Object
- #set_state(value) ⇒ Object
- #state ⇒ Object
- #subscribe ⇒ Object
- #subscribed? ⇒ Boolean
- #unreact(message_id, emoji) ⇒ Object
- #unsubscribe ⇒ Object
- #upload(io:, filename:, comment: nil) ⇒ Object
Constructor Details
#initialize(id:, channel_id:, adapter:, chat:) ⇒ Thread
Returns a new instance of Thread.
7 8 9 10 11 12 |
# File 'lib/chat_sdk/thread.rb', line 7 def initialize(id:, channel_id:, adapter:, chat:) @id = id @channel_id = channel_id @adapter = adapter @chat = chat end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/chat_sdk/thread.rb', line 5 def adapter @adapter end |
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
5 6 7 |
# File 'lib/chat_sdk/thread.rb', line 5 def channel_id @channel_id end |
#chat ⇒ Object (readonly)
Returns the value of attribute chat.
5 6 7 |
# File 'lib/chat_sdk/thread.rb', line 5 def chat @chat end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/chat_sdk/thread.rb', line 5 def id @id end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
92 93 94 |
# File 'lib/chat_sdk/thread.rb', line 92 def ==(other) other.is_a?(ChatSDK::Thread) && id == other.id && channel_id == other.channel_id end |
#delete(message_id) ⇒ Object
52 53 54 |
# File 'lib/chat_sdk/thread.rb', line 52 def delete() adapter.(channel_id: channel_id, message_id: ) end |
#edit(message_id, content) ⇒ Object
47 48 49 50 |
# File 'lib/chat_sdk/thread.rb', line 47 def edit(, content) = PostableMessage.from(content) adapter.(channel_id: channel_id, message_id: , message: ) end |
#hash ⇒ Object
97 98 99 |
# File 'lib/chat_sdk/thread.rb', line 97 def hash [id, channel_id].hash end |
#mention_user(user_id) ⇒ Object
84 85 86 |
# File 'lib/chat_sdk/thread.rb', line 84 def mention_user(user_id) adapter.mention(user_id) end |
#messages(cursor: nil, limit: 50) ⇒ Object
72 73 74 |
# File 'lib/chat_sdk/thread.rb', line 72 def (cursor: nil, limit: 50) adapter.(channel_id: channel_id, thread_id: id, cursor: cursor, limit: limit) end |
#open_modal(trigger_id:, modal:) ⇒ Object
88 89 90 |
# File 'lib/chat_sdk/thread.rb', line 88 def open_modal(trigger_id:, modal:) adapter.open_modal(trigger_id: trigger_id, modal: modal) end |
#post(content) ⇒ Object
26 27 28 29 |
# File 'lib/chat_sdk/thread.rb', line 26 def post(content) = PostableMessage.from(content) adapter.(channel_id: channel_id, message: , thread_id: id) end |
#post_ai_stream(enumerable, placeholder: "Thinking...") ⇒ Object
64 65 66 |
# File 'lib/chat_sdk/thread.rb', line 64 def post_ai_stream(enumerable, placeholder: "Thinking...") ChatSDK::AI::StreamHandler.stream_to_thread(self, enumerable, placeholder: placeholder) end |
#post_ephemeral(content, user_id:) ⇒ Object
31 32 33 34 |
# File 'lib/chat_sdk/thread.rb', line 31 def post_ephemeral(content, user_id:) = PostableMessage.from(content) adapter.post_ephemeral(channel_id: channel_id, user_id: user_id, message: , thread_id: id) end |
#post_stream(placeholder: nil, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chat_sdk/thread.rb', line 36 def post_stream(placeholder: nil, &block) stream = Streaming::Stream.new( adapter: adapter, channel_id: channel_id, thread_id: id, placeholder: placeholder, update_interval: chat.config.streaming_update_interval ) stream.run(&block) end |
#react(message_id, emoji) ⇒ Object
56 57 58 |
# File 'lib/chat_sdk/thread.rb', line 56 def react(, emoji) adapter.add_reaction(channel_id: channel_id, message_id: , emoji: emoji) end |
#set_state(value) ⇒ Object
80 81 82 |
# File 'lib/chat_sdk/thread.rb', line 80 def set_state(value) chat.state.set(state_key(:state), value, ttl: 30 * 24 * 3600) end |
#state ⇒ Object
76 77 78 |
# File 'lib/chat_sdk/thread.rb', line 76 def state chat.state.get(state_key(:state)) end |
#subscribe ⇒ Object
14 15 16 |
# File 'lib/chat_sdk/thread.rb', line 14 def subscribe chat.state.subscribe(state_key) end |
#subscribed? ⇒ Boolean
22 23 24 |
# File 'lib/chat_sdk/thread.rb', line 22 def subscribed? chat.state.subscribed?(state_key) end |
#unreact(message_id, emoji) ⇒ Object
60 61 62 |
# File 'lib/chat_sdk/thread.rb', line 60 def unreact(, emoji) adapter.remove_reaction(channel_id: channel_id, message_id: , emoji: emoji) end |
#unsubscribe ⇒ Object
18 19 20 |
# File 'lib/chat_sdk/thread.rb', line 18 def unsubscribe chat.state.unsubscribe(state_key) end |
#upload(io:, filename:, comment: nil) ⇒ Object
68 69 70 |
# File 'lib/chat_sdk/thread.rb', line 68 def upload(io:, filename:, comment: nil) adapter.upload_file(channel_id: channel_id, io: io, filename: filename, thread_id: id, comment: comment) end |