forked from soxtoby/SlackNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
46 lines (41 loc) · 1.53 KB
/
Program.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
using SlackNet.WebApi;
namespace SlackNet.Example
{
public class Program
{
public static async Task Main(string[] args)
{
if (args.Length == 0)
Console.WriteLine("Please provide a Slack token as a command line argument.");
else
await Run(args[0]).ConfigureAwait(false);
}
private static async Task Run(string token)
{
var count = 0;
var api = new SlackApiClient(token);
using (var rtmClient = new SlackRtmClient(token))
{
await rtmClient.Connect().ConfigureAwait(false);
Console.WriteLine("Connected");
rtmClient.Messages
.Where(m => m.Text.Contains("ping"))
.Subscribe(async m =>
{
var user = (await api.Users.Info(m.User).ConfigureAwait(false));
Console.WriteLine($"Received ping from @{user.Name}");
await api.Chat.PostMessage(new Message
{
Channel = m.Channel,
Text = "pong",
Attachments = { new Attachment { Text = $"Count: {++count}" } }
}).ConfigureAwait(false);
});
await rtmClient.Events;
}
}
}
}