Skip to content

Commit

Permalink
Create event to post welcome message
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-G committed Feb 18, 2022
1 parent 4e4eb08 commit c43ce58
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/models/slack_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ def self.start_meet!(channel_id, meet_name)
slack_client.pins_add(channel: channel_id, timestamp: message[:ts])
end

def self.users_name(user)
slack_client.users_info(
user: user,
)[:user][:profile][:first_name]
end

def self.user_id(user)
slack_client.users_info(
user: user,
)[:user][:id]
end

def self.channel_name(channel_id)
slack_client.conversations_info(
channel: channel_id,
)[:channel][:name]
end

def self.open_the_modal(trigger_id, view_payload)
slack_client.views_open(
trigger_id: trigger_id,
Expand Down
1 change: 1 addition & 0 deletions bot/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative 'events/welcome_message'
16 changes: 16 additions & 0 deletions bot/events/welcome_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SlackRubyBotServer::Events.configure do |config|
config.on :event, ['event_callback', 'member_joined_channel'] do |event|

name = SlackMethods.users_name(event[:event][:user])
user_id = SlackMethods.user_id(event[:event][:user])

channel_name = SlackMethods.channel_name(event[:event][:channel])

if channel_name.include? 'incident'
incident_title = channel_name.split('_').drop(3).join('-')
SlackMethods.post_a_message_to_user(channel_name, user_id, "Welcome #{name} to the incident channel. Please review the docs and join the <http://g.co/meet/#{incident_title}| discussion>.")
end

{ ok: true }
end
end
1 change: 1 addition & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require_relative 'config/environment'

require_relative 'bot/slash_commands'
require_relative 'bot/actions'
require_relative 'bot/events'
require 'yaml'
require 'erb'

Expand Down

0 comments on commit c43ce58

Please sign in to comment.