Class: Nanobot::Channels::Slack
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- Nanobot::Channels::Slack
- Defined in:
- lib/nanobot/channels/slack.rb
Overview
Slack channel integration using Socket Mode via the slack-ruby-client gem. Supports DMs, group mentions, and configurable access control policies.
Instance Attribute Summary
Attributes inherited from BaseChannel
Instance Method Summary collapse
-
#allowed?(_sender_id) ⇒ Boolean
Always returns true; Slack uses its own ACL via allowed_slack? instead.
-
#send(message) ⇒ Object
Send a reply via Slack, threading in channels but not in DMs.
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from BaseChannel
Constructor Details
This class inherits a constructor from Nanobot::Channels::BaseChannel
Instance Method Details
#allowed?(_sender_id) ⇒ Boolean
Always returns true; Slack uses its own ACL via allowed_slack? instead.
58 59 60 |
# File 'lib/nanobot/channels/slack.rb', line 58 def allowed?(_sender_id) true end |
#send(message) ⇒ Object
Send a reply via Slack, threading in channels but not in DMs.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nanobot/channels/slack.rb', line 42 def send() return unless @web_client = .['slack'] || {} thread_ts = ['thread_ts'] channel_type = ['channel_type'] use_thread = thread_ts && channel_type != 'im' @web_client.chat_postMessage( channel: .chat_id, text: .content || '', thread_ts: use_thread ? thread_ts : nil ) end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nanobot/channels/slack.rb', line 14 def start @running = true @bot_user_id = nil ::Slack.configure do |c| c.token = @config.bot_token end @web_client = ::Slack::Web::Client.new @socket_client = ::Slack::RealTime::Client.new(token: @config.app_token) resolve_bot_user_id @socket_client.on :message do |data| (data) end @logger.info 'Slack bot connecting via Socket Mode...' @socket_client.start! end |
#stop ⇒ Object
35 36 37 38 |
# File 'lib/nanobot/channels/slack.rb', line 35 def stop @running = false @socket_client&.stop! end |