A basic example of how to integrate with Azure Functions.
- Create an app on the Slack developer website. Follow the prompts, selecting the "from scratch" option, rather than the app manifest option.
- Request the bot token scopes required by the demo:
users:read
channels:read
groups:read
im:read
mpim:read
for getting user & conversation info.chat:write
for posting messages.
- Install the app to your workspace.
- Follow the Azure Function instructions to start developing Azure Functions and to host this function app in Azure.
- Configure your app with ASP.NET Core integration.
- Set your function's
SlackApiToken
andSlackSigningSecret
application settings in the Azure portal to the values provided in the OAuth & Permissions and Basic Information pages of your Slack app, respectively. - Enable events for your app, and set the request URL to
https://<your function's URL>/event
. Slack will check that your function is up and responding to requests. - Subscribe to the
message.channels
message.groups
message.im
message.mpim
events in order to receive messages. - Add your app to any channels/groups etc. you want it to respond to.
- Say "ping" to get back a "pong".
These URLs aren't used by this example, but may be required for more advanced apps.
- For interactivity & shortcuts:
- Use
https://<your function's URL>/action
for the Interactivity Request URL. - Use
https://<your function's URL>/options
for the Select Menus Options Load URL.
- Use
- For slash commands:
- Use
https://<your function's URL>/command
for the Request URL.
- Use
Instead of configuring SlackNet in Program.cs
, you'll need to enable dependency injection in your project, and then configure SlackNet in your Startup class:
[assembly: FunctionsStartup(typeof(Startup))]
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var apiToken = Environment.GetEnvironmentVariable("SlackApiToken", EnvironmentVariableTarget.Process);
var signingSecret = Environment.GetEnvironmentVariable("SlackSigningSecret", EnvironmentVariableTarget.Process);
builder.Services.AddSlackNet(c => c
// Configure the token used to authenticate with Slack
.UseApiToken(apiToken)
// The signing secret ensures that SlackNet only handles requests from Slack
.UseSigningSecret(signingSecret!)
// Register your Slack handlers here
.RegisterEventHandler<MessageEvent, PingDemo>()
);
}
}