forked from soxtoby/SlackNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
61 lines (48 loc) · 2.43 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SlackNet.Blocks;
using SlackNet.Events;
using SlackNet.Extensions.DependencyInjection;
using SlackNetDemo;
Console.WriteLine("Configuring...");
var settings = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddUserSecrets<Program>()
.Build()
.Get<AppSettings>();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSlackNet(c => c
// Configure the tokens used to authenticate with Slack
.UseApiToken(settings.ApiToken) // This gets used by the API client
.UseAppLevelToken(settings.AppLevelToken) // This gets used by the socket mode client
// Start with the app home screen - it lets you know what you can do with this demo
.RegisterEventHandler<AppHomeOpened, AppHome>()
// Ping demo - a simple event handler that says pong when you say ping
.RegisterEventHandler<MessageEvent, PingDemo>()
// Counter demo - an interactive message that updates itself
.RegisterEventHandler<MessageEvent, CounterDemo>()
.RegisterBlockActionHandler<ButtonAction, CounterDemo>(CounterDemo.Add1)
.RegisterBlockActionHandler<ButtonAction, CounterDemo>(CounterDemo.Add5)
.RegisterBlockActionHandler<ButtonAction, CounterDemo>(CounterDemo.Add10)
// Modal view demo - opens a modal view with a range of different inputs
.RegisterEventHandler<MessageEvent, ModalViewDemo>()
.RegisterBlockActionHandler<ButtonAction, ModalViewDemo>(ModalViewDemo.OpenModal)
.RegisterViewSubmissionHandler<ModalViewDemo>(ModalViewDemo.ModalCallbackId)
// Echo demo - a slash command for telling you what you already know
.RegisterSlashCommandHandler<EchoDemo>(EchoDemo.SlashCommand)
// Workflow demo - posts a simple message to a user as part of a workflow
.RegisterWorkflowStepEditHandler<WorkflowDemo>(WorkflowDemo.StepCallbackId)
.RegisterViewSubmissionHandler<WorkflowDemo>(WorkflowDemo.ConfigCallback)
.RegisterEventHandler<WorkflowStepExecute, WorkflowDemo>()
);
var services = serviceCollection.BuildServiceProvider();
Console.WriteLine("Connecting...");
var client = services.SlackServices().GetSocketModeClient();
await client.Connect();
Console.WriteLine("Connected. Press any key to exit...");
await Task.Run(Console.ReadKey);
record AppSettings
{
public string ApiToken { get; init; } = string.Empty;
public string AppLevelToken { get; init; } = string.Empty;
}