### In-process functions configuration Source: https://github.com/soxtoby/slacknet/blob/master/Examples/AzureFunctionsExample/readme.md Example of configuring SlackNet for in-process Azure Functions using dependency injection. ```csharp [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() ); } } ``` -------------------------------- ### Connect the bot to Slack Source: https://github.com/soxtoby/slacknet/blob/master/SlackNet.Bot/readme.md Start by adding the SlackNet.Bot package to your project, then connect the bot to Slack. ```csharp var bot = new SlackBot(""); await bot.Connect(); ``` -------------------------------- ### SlackNet Socket Mode Client Source: https://github.com/soxtoby/slacknet/blob/master/readme.md Example of how to build and connect the socket mode client. ```csharp var client = new SlackServiceBuilder() .UseAppLevelToken("") /* Register handlers here */ .GetSocketModeClient(); await client.Connect(); ``` -------------------------------- ### SlackNet.AspNetCore Configuration Source: https://github.com/soxtoby/slacknet/blob/master/readme.md Example of configuring SlackNet in an ASP.NET Core app. ```csharp builder.Services.AddSlackNet(c => c .UseApiToken("") .UseSigningSecret("")); var app = builder.Build(); app.UseSlackNet(); ``` -------------------------------- ### SlackNet Web API Client Source: https://github.com/soxtoby/slacknet/blob/master/readme.md Example of how to build the API client to use the Web API. ```csharp var api = new SlackServiceBuilder() .UseApiToken("") .GetApiClient(); ``` ```csharp await api.Chat.PostMessage(new Message { Text = "Hello, Slack!", Channel = "#general" }); ``` -------------------------------- ### Get common information from Slack Source: https://github.com/soxtoby/slacknet/blob/master/SlackNet.Bot/readme.md SlackNet.Bot includes a simplified API for getting common information from Slack. ```csharp var user = await bot.GetUserByName("someuser"); var conversations = await bot.GetConversations(); // etc. ``` -------------------------------- ### SlackNet.AzureFunctions Configuration Source: https://github.com/soxtoby/slacknet/blob/master/readme.md Example of configuring SlackNet in an Azure Functions app. ```csharp hostBuilder.ConfigureFunctionsWebApplication(builder => builder.UseSlackNet()); hostBuilder.ConfigureServices(services => services .AddSlackNet(c => c .UseApiToken("") .UseSigningSecret(""))); ``` -------------------------------- ### SlackNet.AspNetCore Endpoint Prefix Configuration Source: https://github.com/soxtoby/slacknet/blob/master/readme.md Example of configuring the endpoint prefix for SlackNet in ASP.NET Core. ```csharp public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSlackNet(c => c.MapToPrefix("api/slack")); } ``` -------------------------------- ### SlackNet.AspNetCore Socket Mode Configuration Source: https://github.com/soxtoby/slacknet/blob/master/readme.md Example of enabling socket mode for an ASP.NET Core application during development. ```csharp app.UseSlackNet(c => c.UseSocketMode()); ``` -------------------------------- ### Handle messages Source: https://github.com/soxtoby/slacknet/blob/master/SlackNet.Bot/readme.md You can handle messages in a number of ways using .NET events, adding handlers, or subscribing to an Rx stream. ```csharp // .NET events bot.OnMessage += (sender, message) => { /* handle message */ }; // Adding handlers class MyMessageHandler: IMessageHandler { public Task HandleMessage(IMessage message) { // handle message } } bot.AddHandler(new MyMessageHandler()); // Subscribing to Rx stream bot.Messages.Subscribe(/* handle message */); ``` -------------------------------- ### Reply to messages Source: https://github.com/soxtoby/slacknet/blob/master/SlackNet.Bot/readme.md The easiest way to reply to messages is by using their ReplyWith method. Replies will be sent to the same channel and thread as the message being replied to. ```csharp message.ReplyWith("simple text message"); message.ReplyWith(new BotMessage { Text = "more complicated message", Attachments = { new Attachment { Title = "attachments!" } } }); message.ReplyWith(async () => { // Show typing indication in Slack while message is build built var asyncInfo = await SomeAsyncMethod(); return new BotMessage { Text = "async message: " + asyncInfo }; }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.