-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathPingDemo.cs
More file actions
28 lines (24 loc) · 935 Bytes
/
PingDemo.cs
File metadata and controls
28 lines (24 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using SlackNet;
using SlackNet.Events;
using SlackNet.WebApi;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace AspNetCoreExample;
/// <summary>
/// A simple event handler that says pong when you say ping.
/// </summary>
class PingDemo(ISlackApiClient slack, ILogger<PingDemo> log) : IEventHandler<MessageEvent>
{
private readonly ILogger _log = log;
public async Task Handle(MessageEvent slackEvent)
{
if (slackEvent.Text?.Contains("ping", StringComparison.OrdinalIgnoreCase) == true)
{
_log.LogInformation("Received ping from {User} in the {Channel} channel", (await slack.Users.Info(slackEvent.User)).Name, (await slack.Conversations.Info(slackEvent.Channel)).Name);
await slack.Chat.PostMessage(new Message
{
Text = "pong",
Channel = slackEvent.Channel
});
}
}
}