Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 3.93 KB

File metadata and controls

87 lines (63 loc) · 3.93 KB

Concurrency: Goroutines & Practical Applications

Learning Objectives

  1. Define how concurrency works in Golang.
  2. Build an interactive slackbot using goroutines.

Overview/TT I (30 min)

Present Learning Go's Concurrency Through Illustrations.

In Class Activity I (15 min)

Before Starting: Brainstorm command(s) you'd like your Slackbot to perform.

Create New Slack App

  1. Have these docs open and ready as you configure a Slack Bot User.
  2. Point your browser to the Create a Slack App page.
  3. Enter a name that fits the problem you're trying to solve.
  4. Select Product College workspace from the Workspace drop-down.
  5. Click the Create App button.
  6. On the sidebar, under the Features header, click Bot Users.
  7. Git your bot a display name and a default username.
  8. Click the Save Changes button.
  9. Go to OAuth & Permissions and scroll down to the Scopes > Select Permission Scopes text entry field.
  10. Add channels:history, channels:read, and channels:write permission scope and click Save Changes.
  11. Click Install App to Workplace, and make sure you set the contents of the dialog to match the below screenshot. This ensures your bot replies in a particular channel:#golang-slackbots. Make sure your OAuth dialog matches the following:

Setup Project

  1. Fork this starter repo.
    1. It is best if you work from one computer today.
  2. Clone the forked repo to your local machine and cd REPO_NAME.
  3. Create a .env file by running cp .env.sample .env.
  4. Paste the Bot Token from Step 9 in .env after BOT_OAUTH_ACCESS_TOKEN=.
  5. Run go run main.go to start the server.
    1. If it fails to start, let the instructor know.

BREAK (10 min)

In Class Activity II (60 min)

If you get stuck, the following tutorial can assist: Writing Slackbots with Goroutines

  • There are 3 challenges written in the project's comments.
    • Search the project for TODO in order to find them.
  • Complete each with the help of your team.
    • Examine the output of go run main.go.
    • Manually test the bot via Slack while completing the activity.
  • An additional stretch challenge is available if you finish early.

After Class (10 min)

Heroku Deployment

Deploying your bot means it will run forever --- even when your computer isn't on!

Use this sample script to deploy your bot to Heroku:

$ git clone [email protected]:USERNAME/goslackit.git PROJECT_NAME
$ cd PROJECT_NAME
$ heroku create PROJECT_NAME
$ heroku config:set BOT_OAUTH_ACCESS_TOKEN=YOUR_BOT_TOKEN
$ git push heroku master
$ heroku ps:scale worker=1

Additional Resources