Sha256: 6e692a1933d1b76f1a7690072865b67cb4cd59b60017ff9b0b1f6b0a0a550865

Contents?: true

Size: 978 Bytes

Versions: 1

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

SlackRubyBotServer::Events.configure do |config|
  config.on :event, 'event_callback', 'app_mention' do |event|
    data = event['event']
    next unless data

    team = Team.where(team_id: event['team_id']).first
    next unless team

    bot_regexp = Regexp.new("^\<\@#{team.bot_user_id}\>[[:space:]]*")

    data = Slack::Messages::Message.new(data).merge(
      text: data.text.gsub(bot_regexp, ''),
      team: team
    )

    SlackRubyBotServer::Events::AppMentions.config.handlers.detect { |c| c.invoke(data) }
  end

  config.on :event, 'event_callback', 'message' do |event|
    data = event['event']
    next unless data

    # direct message only
    next unless data['channel_type'] == 'im'

    team = Team.where(team_id: event['team_id']).first
    next unless team

    data = Slack::Messages::Message.new(data).merge(team: team)

    SlackRubyBotServer::Events::AppMentions.config.handlers.detect { |c| c.invoke(data) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-ruby-bot-server-events-app-mentions-0.1.0 lib/slack-ruby-bot-server-events-app-mentions/events.rb