static async Task Main(string[] args) { var oauthAccessMethod = new OauthAccessMethod("Slack app client ID", "Slack app client secret", "temp auth code") { RedirectUri = "Slack app authorized redirect URL" }; var webClient = await SlackWebClientFactory.CreateWebClient("userId", oauthAccessMethod); var connectionResponse = await webClient.CallApiMethod <ConnectResponse>(new RtmConnectMethod()); var slackClient = new SlackRtmClient(); if (connectionResponse.Ok) { await slackClient.Connect(connectionResponse.Url); slackClient.BindEvent <ReactionAddedEvent>(ReactionAddedCallback); slackClient.BindEvent <ReactionRemovedEvent>(ReactionRemovedCallback); Console.WriteLine("User connected"); } Console.Read(); }
public static async Task <SlackWebClient> CreateWebClient(string userId, OauthAccessMethod method) { var response = await new SlackWebClient().CallApiMethod <OauthAccessResponse>(method); if (response.Ok) { return(new SlackWebClient(new SlackUser(response.AccessToken, userId, response.TeamId))); } return(null); }
static async Task Main(string[] args) { var tempAuthCode = "Temporary authorization code given by Slack when a user authorizes your app"; var oauthAccessMethod = new OauthAccessMethod("Slack app client ID", "Slack app client secret", tempAuthCode) { RedirectUri = "Slack app authorized redirect URL" }; var slackClient = await AuthorizeClient(oauthAccessMethod); await TestAuth(slackClient); Console.Read(); }
/// <summary> /// Exchange the temporary code for the user's secret token. /// </summary> /// <param name="oauthAccessMethod">OAuth access method options.</param> /// <returns>Client that will allow taking authorized actions on behalf of the user.</returns> private static async Task <SlackWebClient> AuthorizeClient(OauthAccessMethod oauthAccessMethod) { return(await SlackWebClientFactory.CreateWebClient("userId", oauthAccessMethod)); }