Slack has fundamentally changed how employees within teams, offices, and entire organizations communicate and collaborate with one another. There are myriad ways to customize your company's Slack but, beyond using the channels, GIF files, app integrations, and reaction emojis, the most dynamic way to enhance your Slack experience is by using bots.

Part chatbot interface and part automated action engine, Slack bots have a ton of potential uses. Within a specific channel, the 100-plus bots currently available in Slack's Bot Directory can conjure up anything from a poll, survey, or time tracking form to message analytics, lunch orders, and restaurant recommendations—all with a quick direct message (DM) or slash command.

Plenty of business software providers, including SurveyMonkey and Zenefits (Visit Site at Zenefits) have already built bots that you can enable within Slack. But you don't have to wait for someone else to build the Slack bot that your organization needs. By using Slack's developer resources, documentation, and tutorials, you can let the company guide you through building your own Slack bot.

PCMag spoke to Amir Shevat, Head of Developer Relations at Slack, and John Agan, Senior Developer Relations Manager at Slack (Visit Site at Slack) , about how to build a Slack bot from scratch. The process requires some considerable developer know-how in spots, but Shevat and Agan walked us through two simple bot creation scenarios to which all businesses can relate: building a basic helpdesk bot and enabling in-channel notifications. Read on for step-by-step instructions on how to build your very own Slack bot.


1. 1. Create a New Slack App To start, open the left-hand navigation menu from your Slack client and click "Apps and Integrations." On the top right-hand side of the App Directory, click "Build." This takes you to the Slack application programming interface (API) where you click "Start Building" in the center of the page. Give your app a name (in this case, Helpdesk), choose the team in which you want to deploy the app, and click "Create App."



This takes you to the Basic Information page for your app. For extra customization, scroll down to the Display Information box in which you can add a description, change the background color, and add an icon for your soon-to-be bot. For the Helpdesk bot, for instance, Agan gave the bot the robot emoji as its icon.

2. 2. Write Your Bot's Messages Now that you've created your app, the Slack API gives you a number of options to begin customizing what it can do. For our Helpdesk app, we're building a bot that makes it easy to file a helpdesk ticket on your behalf. First, Slack's Agan said you need to write the messages that will appear when a user types in a slash command.



In the Messages section of the Slack API menu, choose the Message Builder tool. This gives you some preformatted JSON code, with a space for you to write in and then preview your text. For this bot, Agan typed in, "Would you like to file this helpdesk ticket?"



When a user clicks "Create" to file their helpdesk ticket, this is the confirmation message that will show up. So, next to the text, Agan added the command for :white_check_mark: to give the Slack user a green check mark emoji confirming submission of their ticket. Just like that, you've written your bot's automated message code. Keep this handy because you'll need it in a bit.





3. 3. Add Notifications Agan and Shevat gave separate demos, but Shevat explained that one of the most common bot integrations Slack has seen since opening up the capability is a bot that pulls in notifications from third-party services. This could be something such as a weekly sales report from Salesforce (Visit Site at Salesforce.com) , or in this case, from the helpdesk platform for which your bot is creating tickets.

4. 4. Activate Incoming Webhooks To add notifications within your Helpdesk bot (Shevat demonstrated these steps with a separate example he named "ReportBot"), you first have to enable incoming Webhooks. A Webhook is a simple HTTP callback that posts a message to a URL when a specific action is triggered.



To do this, go back to the Basic Information page of your Slack API. The first box says "Add Features and Functionality." Choose the "Incoming Webhooks" option. On the top right-hand side of the Activate Incoming Webhooks page is a slider button. Click it to switch the button from Off to On.

5. 5. Authorize Channel Notifications Once Webhooks are activated, scroll down and click "Add New Webhook to Team." You'll be asked to choose the channel to which you'd like your bot to post automated notifications. In this example, Shevat chose #general, but in this case, you might want to post this notification to your helpdesk team or IT department's channel. So, not only will a new ticket be created in your helpdesk platform, but an automatic notification will be sent to the IT department's Slack channel to notify them of the ticket. Once you choose your channel, click "Authorize."

6. 6. Customize Your Webhook Once authorized, you'll see a basic Webhook URL on the page and a button to copy it. Above that is your sample curl request, which you can copy to a text editor to say anything you want. In this scenario, instead of "Hello, World," you may want to write in "New Helpdesk Ticket Submitted" or whatever accurately describes the notifications you'd like your bot to send. From here, you can take your curl request code and Webhooks URL and run it in any script. You'll need this code in the next step as well.

7. 7. Build Your Bot



This step requires some coding expertise. Agan created a new Glitch project and then began adding some open-source JavaScript code. If you don't want to write all of the code yourself (or reinvent the wheel), then you can choose from countless



Agan named his project "Index.js," added a package he built himself called Now that you've got your message code written and your Webhooks URL handy, you're ready to build your bot. Most Slack integrations require a server to respond to and initiate requests, particularly when automated bot logic and slash commands are involved. Slack supports a number of providers, but Agan built the helpdesk bot by using a service called Glitch This step requires some coding expertise. Agan created a new Glitch project and then began adding some open-source JavaScript code. If you don't want to write all of the code yourself (or reinvent the wheel), then you can choose from countless bot frameworks and libraries to import your basic bot logic.Agan named his project "Index.js," added a package he built himself called TinySpeck , and then pasted in the Message Builder code we wrote earlier. With the main bot code now in place, he simply added a callback command to trigger a new ticket and the "A helpdesk ticket has been created" confirmation message. That's it. If you want to add your Webhooks code to trigger a notification in the channel you've designated, then you can paste that in here as well. Glitch creates a unique URL for your bot server, so copy that URL once you've added all your code and we're on to the next step.

8. 8. Enable Interactive Messages You've already created your Helpdesk bot, so now all you have to do is go back into the API. Instead of choosing "Create New App," just click "Manage Apps" and choose the Helpdesk app. Under the Basic Information page, choose "Interactive Messages" in the Add Features and Functionality box. Once on that page, click "Enable Interactive Messages," paste in your server URL from the previous step, and save changes.

9. 9. Create a Slash Command Once that's done, go back to the Add Features and Functionality box and go into Slash Commands. Click "Create New Command." This takes you to a form page with a few fields.



In the Command box, enter your slash command. In this instance, Agan typed in "/helpdesk." In the Request URL field, he pasted in the same server URL from Glitch. Then all you do is enter a short description for the command ("Create a helpdesk ticket"), a usage hint for how the user should type their request, check the preview below it to make sure it all looks right, and then click Save.

10. 10. Install Your App The Helpdesk bot is now ready to rock. Back on the main API page for your app, go to the Install App page that can found in the left-hand side Settings menu. Click "Install App to Your Team." This will prompt you to authorize the app. Once you do so, your bot is live. You'll see a green "Success!" notification ribbon atop your screen that confirms your bot is installed.

11. 11. Take Your Bot for a Spin Back in your team's Slack client, head to the channel in which you've designated to put your new bot to work. Enter the slash command with a query, for example: "/helpdesk my Wi-Fi is broken." You then will be prompted with a button to create a helpdesk ticket. Congratulations; you've just built a working Slack bot!

Further Reading

Business Reviews

Business Best Picks