Slack Integration

Thi Nguyen - Aug 16 - - Dev Community

Let's make a SlackBot !!

1. On Slack developer dashboard

  • Create your very own Slack workspace if not already, head over to this link https://slack.com/help/articles/206845317-Create-a-Slack-workspace
  • Click on “Create a Slack app” to begin building your application
  • Input your application name and select the workspace you just created or where you will be developing your app.
  • After creating your app, Slack presents you with the ‘Basic Information’ page.

Image description

Image description

  • Turn on Socket Mode

  • Proceed to OAuth and permissions on the sidebar to add scopes and obtain OAuth Token. For our use case, bot will be capable of chat:write

Image description

  • Install the app into the Slack workspace on Basic Information page

There are 2 tokens: OAuth Token and App Level Token. The first one can be found on OAuth and permissions page. The latter can be found on Basic Information page

2. Add SlackBot To Your Slack channel

To add your bot to a channel, follow these steps:

  • Inside Slack, locate your bot in the left-hand sidebar.
  • Click on the dropdown arrow next to your bot’s name.
  • Select “Add this app to a channel.”
  • Choose the channel you want to add your bot to. In this case, we will select the desired channel.

3. In your project

  • Install the above package to establish communication with Slack
  • Create an settings.json to store the secrets: OAuthToken and slack channel name. In our use case, we will have them in an azure function project in local.settings.json file
{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "WEBSITE_TIME_ZONE": "AUS Eastern Standard Time",
        "SlackApiToken": "token",
        "SlackChannel": "#chanel"
    },
    }
}
Enter fullscreen mode Exit fullscreen mode

Reference
[(https://danieldonbavand.com/2023/05/03/how-to-create-a-custom-slack-bot-with-net-7/)]

. . . . .