Slack For Beginners



I’ve previously written before about simple formatting on Slack but what if you want to add syntax highlighting?

Say you want to share a block of Ruby code with a colleague and a simple code block just won’t cut it?

Slack has a solution for you!

Manage your account. Adjust your notifications. Change your settings & preferences. Get troubleshooting tips. Connect tools from the Slack App Directory. Automate tasks with Workflow Builder. Explore apps in the Slack App Directory. Create customised apps. Slack is a team messaging and collaboration software tool. This instructor-led, live training (online or onsite) is aimed at persons who wish to learn how to use Slack to collaborate and communicate seamlessly with team members within their organization. By the end of this training, participants will be able to. Slack free download for Windows: the latest version for your PC, phone or tablet on the official website. Previous video: Team website: In this video, Austin covers four basic core functions of Slack: Direct Messages, Channels.

If you click on the + symbol at the side of the text entry box, you will see an option for Code or text snippet, click on this. A pop out will appear. You can paste or type your code block into the large text input box. Then if you click on the drop down in the top right corner, you can select the language you’d like to format to. It has many popular languages such as C#, JavaScript, and HTML. It also has a text wrap option. From this view you can choose which room you’d like to share the code snippet.

This is part of our Slack mini series, wherewe quickly explain simple and more advanced Slack features.Excellent for beginners or if you just need a quick refresher.

If there is a feature you would like us to cover please drop us anemail ortweet.

By Vishwa Shah

Update: code and tutorial updated on June 28 to reflect Slack API changes.

Before we get into the tutorial part of this post, let’s take a look at why this can be a worthy project and tool.

Slack is an increasingly popular tool for team-wide communication. It’s grown to include plugins for other widely used project management tools, like JIRA, Google Drive, and the likes. Any slack user knows — the more you can do from within the conversation, the better.

Common uses for a slackbot range from a simple notifier for when a task is complete (like a test build, or when your lunch is ready) to interactive, button-based bots that execute commands at the user’s will. You can build polling mechanisms, conversational bots, and more.

If you’re a windows user and you haven’t used python before, you’ll need to install it. Linux/Mac users: Unix comes with python!

Slack For Beginners

Once installed, fire up your terminal and type python or python3 (if you have multiple installations) to make sure it works and is there.

Slack Tips For Beginners

Also check to see you have a good text editor for code: sublime and atom are great choices.

Optional: It might also be useful to work in a virtual environment — it’s good practice for when you have a lot of dependencies.

You should also fork the tutorial GitHub repo and clone to your local machine, as we’ll be using that code as a framework for this tutorial.

To do this, go to the repo and click Fork on the top right. The forked repo should be <yourusername>/slackbot-tutorial. Hit the green Clone or download button on the right under the stats bar, and copy the url. Return to the terminal to clone the repository:

There are two ways to go about creating your slackbot: standalone bots, or Slack apps. Apps allow a wider range of functionality going forward, and is Slack’s recommended route for creating a bot user.

Go to https://api.slack.com/apps and hit Create New App on the top right. Give it a name and pick a workspace where you can create a channel to test your bot in. You can always reconfigure your bot for another workspace later, or even post it to the Slack App Directory.

I recommend making a #test channel in a workspace you create just for development purposes, or one that has relatively few users who wouldn’t mind you testing something out there.

The first thing you’ll want to do is get the bot token. When you get to the above page, click Bots. Add some scopes; these determine what permissions your app’s bot user will have. To start, chat:writeandim:writeare probably enough.

How To Use Slack For Beginners

Now, to actually get your tokens, you’ll want to go to OAuth & Permissions on the left sidebar.

Here, you’ll be able to Install the App to the Workspace and generate the necessary tokens. As a rule of thumb, bot tokens start with xoxb-.

You’ll also want the signing secret, which is located under Basic Information > App Credentials.

Acting as your Bot

Now you have the credentials necessary to make API calls and act as your bot. To test this out, fire up a terminal and run this (with the correct token and channel name):

If you go to that channel in your slack workspace, you should now see a message from your bot! You just made an HTTP POST request — asked a server to post a message somewhere.

We want to do the above programatically. There are a few different ways you can set up a slackbot. I’ll cover the following:

  • Triggered periodically (on a schedule) to say something
  • /slash commands

The second requires a server running, while the first does not.

Scheduled Messages

Let’s say you want to periodically send a message somewhere — maybe every Monday morning. Go to the text editor where you opened up slackbot-tutorial.

You should see a file scheduled.py. Take a look: sendMessage is a function that fires off the API call to slack and posts a message. At the bottom, you’ll see the main method: what executes when you run the script. Here, you’ll see a few things to note:

Slack For Beginners

Beginners
  • SLACK_BOT_TOKEN is pulled from os.environ['SLACK_BOT_TOKEN'] — how? Run export SLACK_BOT_TOKEN='xoxb-your-token' in your terminal to set this variable.
  • a scheduler is used here, and there’s an infinite loop that checks for events on the scheduler. By default here, I’ve scheduled the sendMessage function to be called every minute.

To test this out, go back to the terminal where you’re in the slackbot-tutorial directory and run

Slack Tutorial

You should see the log messages print. Make sure you’ve changed channel=#test in the code to your test channel name (if different) and added your bot (in the slack channel, type /invite @botname. Let it run for a couple minutes and watch the messages show up on Slack!

This is, of course, a super basic implementation of a scheduled message sender — you can actually do this just with slackbot /remind #test “Hello, Slack!” every Monday at 9am.

The true power here is that you can substitute in any function for sendMessage, leveraging the power of interfacing with external services through APIs, doing math, etc and then constructing a message to post.

Slash Commands

This one requires a little more setup — go back to your app settings > Slash Commands. Create a new slash command: for example, /test. For the request URL, you’ll need to either deploy this web server (I use Heroku), or run a local ngrok instance to test it. The latter will run it locally, and is best for testing. You can brew install ngrok or get it from here.

In the starter code repo, look for slashCommand.py to start understanding this method. To start the server, run python server.py. The Request URL to put in Slack will be given by your ngrok instance and the @app.route in your code — it would be something like http://a1234b5cde6f.ngrok.io/slack/test (the bold part comes from the route defined in the code). You should be able to test the slash commands in your Slack workspace. From the tutorial code, try /test.

Now you have a very basic slackbot that either operates on a command or runs every so often. Be creative with how you use it! Think about what else you can link this skeleton to to make it more useful.

Slack For Beginners Youtube

Other ways your bot might respond

Slack User Guide

  1. Actions/responses could be triggered by mentions or certain phrases. This requires running a server and listening the messages somewhere.
  2. You bot could be conversational, and might contribute to threads. Check out some NLP to get started on having intelligible conversation! Word2Vec + TensorFlow or Keras might be a place to start. DialogFlow is also great.
  3. Link it up with some other APIs. Maybe you want to be able to interact with a Google Sheet and run some calculations. You might want to send other users a message based on some actions. Integrate buttons. Perhaps you want to trigger messages based on something else.