An Introduction to Slack Integration

An Introduction to Slack Integration

Tudip

Tudip

11 May 2020

Slack is an interactive hub that has replaced email to help you and your team work together seamlessly. It is a simple interactive toll where many people can connect through a channel. It’s designed to support the way people naturally work together, so you can collaborate with people online as efficiently as you do face-to-face. Team members can communicate and interact together with channels.

For Integration of slack through our application you need to create a slack app. Pick a name for your new app and a workspace to associate it with. You can change the app’s name as often as you want. You can often distribute your slack app to another workspace if you want. Following these simple steps creates your slack app. That’s it, Once created, you have a slack app to build and manage.

It has the following features which includes incoming webhooks, interactive components, slash commands, Event subscriptions etc. Out of these features, the foremost feature to integrate with the project is slash commands and event subscriptions.

Slash Commands

Before describing the slash command first, we need to understand what interactive components are. As the name suggests, any interactions with actions, modals, or interactive components (such as buttons, select menus, and datepickers) will be sent to a URL you specify. Request URL will be the POST url which will be in the form:

For Example:  https://dev.api.trainingamigo.tudip.uk/v1/slackPing

Slack will send an HTTP POST request with information to this URL when users interact with an action or interactive component. You can add the action names.
For example: Thank you, congrats followed by description and call back ids

Coming to slash commands. Slash Commands allow users to invoke your app by typing a string into the message composer box. A submitted Slash Command will cause a payload of data to be sent from Slack to the associated app. The app can then respond in whatever way it wants using the context provided by that payload. These commands are the entry points for complex workflows, integrations with external services, or even just simple message responses. They’re the knock at your app’s front door that could be the start of a great conversation.
For creating a slash command you need to go through the following steps, attached below is the screenshot of the entered slash command for the app.

slack-1

The command name should be written, followed by the request url of the project through which the slack api are integrated through curl operation, the description is necessary so as to give a clear understanding of what this slash command actually does. Like here whenever you recognize anyone on the slack channel and followed by this slash command a curl operation will be done and the details of the mentioned users who are associated in that particular channel can be fetched. Slack has provided us various methods to fetch the details of the user and that details can be used in our project. It follows the following procedure when one types the slash command.

  • A user in Slack types in the message box with the command, and submits it.
  • A payload is sent via an HTTP POST request to your app.
  • Your app responds in some way.

For Example if we write: /recognition @jon thank you for the awesome work

We will receive the response in our app in the following format : <@U012ABCDEF> thank you for the awesome work.

In this way we get the slack user id from the slack we can get the user information through this user id by integrating the slack api: https://slack.com/api/users.info

We will get the user information through this slack api which we will integrate through curl in our project. The information we can fetch from this API will be name, last name, email, channel id, slack user id. So whatever the user information we have stored in our app we can fetch from this details and if the details exist than we can do whatever operations we want for that particular user like:

  • Sending the push notifications whenever the user gets recognized along with the user who has recognised.
  • Sending the email reminder for the same.
  • We can allot points to the user for the recognition

Not only the user id we can store the text that has been written on the slack channel so that if we have a post feed in our project then we can show the slack messages in our project directly. So, whatever the user writes in the slack channel we can fetch from the slack and can show in our project.

This is the brief of how we can interact with the slack messages in a particular workspace. Moreover we can create multiple channels and this is how users can interact very easily.

OAuth Authentication

OAuth 2.0 is a protocol that lets your app request authorization to private details in a user’s Slack account without getting their password. It’s also the vehicle by which Slack apps are installed on a team. When you install the app the slack provides the access token with the client id and secret. This provides a two way authentication so that the data remains secured throughout. Your app asks for specific permission scopes and is rewarded with access tokens upon a user’s approval. You’ll need to register your app before getting started. A registered app is assigned a unique Client ID and Client Secret which will be used in the OAuth flow. The Client Secret should not be shared.  This is the authentication process that is required at the time of registering slack.

search

Blog Categories

Request a quote