forked from soxtoby/SlackNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PingDemo.cs
28 lines (24 loc) · 889 Bytes
/
PingDemo.cs
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;
namespace NoContainerExample;
/// <summary>
/// A simple event handler that says pong when you say ping.
/// </summary>
class PingDemo : IEventHandler<MessageEvent>
{
private readonly ISlackApiClient _slack;
public PingDemo(ISlackApiClient slack) => _slack = slack;
public async Task Handle(MessageEvent slackEvent)
{
if (slackEvent.Text?.Contains("ping", StringComparison.OrdinalIgnoreCase) == true)
{
Console.WriteLine($"Received ping from {(await _slack.Users.Info(slackEvent.User)).Name} in the {(await _slack.Conversations.Info(slackEvent.Channel)).Name} channel");
await _slack.Chat.PostMessage(new Message
{
Text = "pong",
Channel = slackEvent.Channel
});
}
}
}