-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathPingDemo.cs
More file actions
29 lines (26 loc) · 882 Bytes
/
PingDemo.cs
File metadata and controls
29 lines (26 loc) · 882 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
29
using Microsoft.Extensions.Logging;
using SlackNet;
using SlackNet.Events;
using SlackNet.WebApi;
namespace AzureFunctionsExample;
/// <summary>
/// A simple event handler that says pong when you say ping.
/// </summary>
class PingDemo(
ISlackApiClient slack,
ILogger<PingDemo> logger
) : IEventHandler<MessageEvent>
{
public async Task Handle(MessageEvent slackEvent)
{
if (slackEvent.Text?.Contains("ping", StringComparison.OrdinalIgnoreCase) == true)
{
logger.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
});
}
}
}