Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-new-slash-command #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .env
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RAILS_HOST_NAME=scibot.test
RAILS_HOST_NAME=localhost:3000
BASE_URL=https://${RAILS_HOST_NAME}
DATABASE_URL="postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?pool=30"
DATABASE_HOST=db
DATABASE_NAME=scibot
DATABASE_PASSWORD=testing123
DATABASE_USER=postgres
DATABASE_HOST=db
RAILS_ENV=development
RAILS_SECRET_TOKEN=
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=
SLACK_OAUTH_SCOPE=
SLACK_SIGNING_SECRET=
DATABASE_URL="postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?pool=30"
RAILS_SECRET_TOKEN=CHANGEME
SLACK_CLIENT_ID=CHANGEME
SLACK_CLIENT_SECRET=CHANGEME
SLACK_SIGNING_SECRET=CHANGEME
SLACK_OAUTH_SCOPE=users:read,channels:read,groups:read,chat:write,commands,incoming-webhook
GITHUB_REPOSITORY=scientist-softserv/dev-ops
1 change: 1 addition & 0 deletions bot/actions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative 'actions/default'
require_relative 'actions/quiz'
require_relative 'actions/modal'
require_relative 'actions/ticket'
26 changes: 26 additions & 0 deletions bot/actions/ticket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
SlackRubyBotServer::Events.configure do |config|
config.on :action, 'block_actions' do |action|
payload = action[:payload]
action_id = payload["actions"][0]["action_id"]
channel_id = payload["channel"]["id"]
team_id = payload["team"]["id"]
user_id = payload["user"]["id"]
action.logger.info "Action #{action_id} has been processed in channel #{channel_id}"
team = Team.find_by(team_id: team_id)
slack_client = Slack::Web::Client.new(token: team.token)

case action_id
when 'create_issue'
# Handle the create issue action for /ticket
issue_title = payload["state"]["values"]["ticket_title"]["value"]
issue_description = payload["state"]["values"]["ticket_description"]["value"]

# scibot channel id for now
channel_id = 'C065NSAGFAM'
# Go to scibot channel and put the payload there.
slack_client.chat_postMessage(channel: channel_id, text: "Issue title: #{issue_title}\nIssue description: #{issue_description}")
end

nil
end
end
1 change: 1 addition & 0 deletions bot/slash_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
require_relative 'slash_commands/ping'
require_relative 'slash_commands/quiz'
require_relative 'slash_commands/modal'
require_relative 'slash_commands/ticket'
76 changes: 76 additions & 0 deletions bot/slash_commands/ticket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
def ticket_message(channel_id)
{
channel: channel_id,
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Please enter the title of the issue:",
"emoji": true
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "ticket_title"
},
"label": {
"type": "plain_text",
"text": "Title",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Please enter the description of the issue:",
"emoji": true
}
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"multiline": true,
"action_id": "ticket_description"
},
"label": {
"type": "plain_text",
"text": "Description",
"emoji": true
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Create Issue",
"emoji": true
},
"value": "create_issue",
"action_id": "create_issue"
}
]
}
]
}
end

SlackRubyBotServer::Events.configure do |config|
config.on :command, '/ticket' do |command|
p command
team_id = command[:team_id]
channel_id = command[:channel_id]
command.logger.info "Someone started a ticket creation in channel #{channel_id}."
team = Team.find_by(team_id: team_id)
slack_client = Slack::Web::Client.new(token: team.token)
slack_client.chat_postMessage(ticket_message(channel_id))
nil
end
end
27 changes: 0 additions & 27 deletions db/seed.rb

This file was deleted.

28 changes: 6 additions & 22 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
Group.find_or_create_by(name: 'devops') do |group|
group.description = "SoftServ DevOps Team"
end

Group.find_or_create_by(name: 'gcsupport') do |group|
group.description = "Glass Canvas Support Team"
end

Group.find_or_create_by(name: 'gcdev') do |group|
group.description = "Glass Canvas Dev Team"
end
# frozen_string_literal: true

Member.find_or_create_by(handle: 'rob') do |member|
member.name = "Rob Kaufman"
member.group = Group.find_by(name: 'devops')
member.member_id = "U0E347KGF"
Group.find_or_create_by(name: 'devops') do |group|
group.description = 'SoftServ DevOps Team'
end

Member.find_or_create_by(handle: 'crystal') do |member|
member.name = "Crystal Richardson"
Member.find_or_create_by(member_id: 'U02QC5MTU8N') do |member|
member.handle = 'april'
member.name = 'April Rieger'
member.group = Group.find_by(name: 'devops')
end

Member.find_or_create_by(handle: 'stefan') do |member|
member.name = "Stefan"
member.group = Group.find_by(name: 'gcdev')
end