-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Socket mode client is run as an IHostedService in ASP.NET
Deprecated SlackEndpointConfiguration.SocketModeConnectionOptions setter
- Loading branch information
Showing
5 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace SlackNet.AspNetCore; | ||
|
||
class SocketModeService( | ||
ISlackSocketModeClient socketModeClient, | ||
ILogger<SocketModeService> logger, | ||
SlackEndpointConfiguration config | ||
) : IHostedService | ||
{ | ||
private readonly bool _enabled = config.SocketMode; // Holding onto this to ensure initial state is used when stopping | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
if (_enabled) | ||
{ | ||
try | ||
{ | ||
await socketModeClient.Connect(config.SocketModeConnectionOptions, cancellationToken).ConfigureAwait(false); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e, "Error connecting Slack socket mode client"); | ||
} | ||
} | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
if (_enabled) | ||
socketModeClient.Disconnect(); | ||
return Task.CompletedTask; | ||
} | ||
} |