/// <summary> /// Parses the messages sent to the bot and answers to the best of its abilities. /// Extend this method to include more commands. /// </summary> /// <param name="message">The message sent to the bot.</param> /// <returns>No object or value is returned by this method when it completes.</returns> async Task MessageReceived(SlackMessage message) { try { VerifyMessageIsComplete(message); if (message.ChatHub.Type != SlackChatHubType.DM) { return; } var command = MessageParser.ParseCommand(message, adminUser); switch (command) { case AnswerRegularUserCommand _: await AnswerRegularUser(message.User); break; case ValidateAllProfilesCommand _: await ValidateAllProfiles(); break; case NotifyAllProfilesCommand _: await ValidateAllProfiles(true); break; case ValidateSingleProfileCommand c: await ValidateSingleProfile(message.User, c.Payload); break; case NotifySingleProfileCommand c: await ValidateSingleProfile(message.User, c.Payload, true); break; case WhitelistSingleProfileCommand c: await WhitelistProfile(c.Payload); break; case ShowVersionNumberCommand _: await SendVersionNumber(); break; case ShowWhitelistedUsersCommand _: await SendWhitelistedUsers(); break; default: await slackIntegration.SendDirectMessage(message.User, $"Available commands are:{Environment.NewLine}- validate all users{Environment.NewLine}- notify all users{Environment.NewLine}- validate @user{Environment.NewLine}- notify @user{Environment.NewLine}- whitelist{Environment.NewLine}- whitelist @user{Environment.NewLine}- version"); break; } } catch (Exception e) { logger.Error(e); try { await slackIntegration.SendDirectMessage(adminUser, $"I crashed:{Environment.NewLine}{e}"); } catch (Exception exception) { logger.Fatal(exception); throw; } } }
/// <summary> /// Parses the messages sent to the bot and answers to the best of its abilities. /// /// Extend this method to include more commands. /// </summary> /// <param name="message">The message sent to the bot.</param> /// <returns>No object or value is returned by this method when it completes.</returns> async Task MessageReceived(SlackMessage message) { try { VerifyMessageIsComplete(message); var command = MessageParser.ParseCommand(message, adminUserId); switch (command) { case AnswerRegularUserCommand _: await AnswerRegularUser(message.User); break; case ValidateAllProfilesCommand _: await ValidateAllProfiles(); break; case NotifyAllProfilesCommand _: await ValidateAllProfiles(true); break; case ValidateSingleProfileCommand c: await ValidateSingleProfile(message.User.Id, c.Payload); break; case NotifySingleProfileCommand c: await ValidateSingleProfile(message.User.Id, c.Payload, true); break; default: await slackIntegration.SendDirectMessage(message.User.Id, $"Available commands are:{Environment.NewLine}- validate all users{Environment.NewLine}- notify all users{Environment.NewLine}- validate @user{Environment.NewLine}- notify @user"); break; } } catch (Exception e) { logger.Error(e); try { await slackIntegration.SendDirectMessage(adminUserId, $"I crashed:{Environment.NewLine}{e}"); } catch (Exception exception) { logger.Fatal(exception); } } }