Give a shout-out or kudos to people in your Slack server! Uses a slash command to prompt open the form from any channel, and will post a formatted message in a single channel.
Ruby Version: 2.5.3p105
Rails Version: 5.2.3
Uses Postgres for the database, which saves submissions and those in-progress.
Run tests with bundle exec rspec
.
I recommend forking the repo so you can customize for your server's needs. For example, this view has a multi select for our company values. You may want to change these to your own values, or remove the block and validation if you don't wish to use it. Likewise, you may want to customize how the message displays. Forking will let you use this repo as a base for how to make the changes you need to suit your server!
-
Fork the repo & clone to your computer. Then navigate into the folder.
-
Run
bundle install
-
Run
rake db:setup && db:migrate
After finishing steps 3 and 4, you can run locally with rails s
. The API can be found locally at http://localhost:3000/api/praise
.
Deploy your app to Heroku or another site. You can use Heroku's CLI, or deploy from your forked repo. Add the following add-ons:
- Postgres (required)
- Heroku Scheduler (recommended for running tasks, but you can use something else)
- Create a task to run
rake sync_users:get_users sync_users:get_user_groups
once a week.
- Papertrail (recommended)
Create a new App to your workspace for Praise Bot.
-
Add a bot user under
Features & Functionality
. Then go toOAuth & Permissions
to find your bot's auth key. -
Under this section, be sure the bot has permission to:
usergroups:read
,users.profile:read
,users:read
,chat:write
,chat:write.public
, andchat:write.customize
. -
Run
bundle exec figaro install
to generate aconfig/application.yml
file. Add the following ENV (environment) variables to this file locally. -
Replace this value with your bot's key:
slack_bot_auth: xoxb-xxxxxxx-xxxxxx-xxxxxx
-
In
Basic Information
>App Credentials
you will find your app's client ID and secret. Add the signing secret as an ENV variable.slack_secret_signature: xxxxxxxxxxxxxxxx
-
Also add a ENV variable with the channel ID to post to.
slack_praise_channel: xxxxx
How do I get the channel ID? If you go to the team's Slack in your browser, and then click into the channel you want to post to, the channel ID will be the last string after the last /
in the URL.
Example: https://app.slack.com/client/TEAM_ID/CHANNEL_ID
Add these in your deployed environment also.
---- Do NOT commit this file. ----
-
Back in the bot's Slack App settings, go to
Interactive Components
. Turninteractivity
on and add a request URL with your deployed environment. It should look like this:https://deployed-domain.com/api/praise
-
On this same page (
Interactive Components
), add a request URL underSelect Menus
for our users and user groups using your deployed environment. It should look like this:https://deployed-domain.com/api/user
-
Next go to
Slash Commands
and add a new slash command. Make the command/praise
(or/kudos
if you'd rather). The request URL will be same as the URL you used above.
Make sure it's installed in the team's workspace, you update bot's display name/image, and you're good to go!
- A user, in any channel, can type
/praise
as a command. - Slack uses the API to hit our API's POST
PraiseController
(/api/praise
), which processes all requests from Slack. - The controller calls
view.open
to Slack's API with the form built inlib/assets/view.json
- Slack will open the modal form for the user.
- When the user submits the form, Slack sends a
view_submission
request. The values are sent to be processed and saved (theaction_id
should match the database column name). We validate they've filled out all information quickly. If fields are missing or invalid, we return a list of errors to be displayed. If it is valid, we build the message format to post and submit to Slack. - When the user hits cancel, Slack sends a
view_closed
request. If we have their view saved -- because they filled out an input, for example -- we delete the incomplete view.
The praise controller is responsible only for handling POST requests from Slack, determining what response is required, and then calling the appropiate method.
PraiseBot.submit
: Posts the finalized message to the selected channel.PraiseMessage.build
: Validates the final submission and formats the message to post.PraiseMessage.destroy
: Deletes incomplete submissions.ProcessValues.save
: Saves values received inview_submission
by type.