forked from soxtoby/SlackNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingDemo.cs
More file actions
38 lines (33 loc) · 1.11 KB
/
PingDemo.cs
File metadata and controls
38 lines (33 loc) · 1.11 KB
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
30
31
32
33
34
35
36
37
38
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using SlackNet;
using SlackNet.Events;
using SlackNet.WebApi;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace AzureFunctionExample;
/// <summary>
/// A simple event handler that says pong when you say ping.
/// </summary>
class PingDemo : IEventHandler<MessageEvent>
{
private readonly ISlackApiClient _slack;
private readonly ILogger _log;
public PingDemo(ISlackApiClient slack, ILogger<PingDemo> log)
{
_slack = slack;
_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
});
}
}
}