public MessengingPipelineContextFactory(IMessengerFactory messengerFactory, ICommandIngesterFactory ingesterFactory, Func <ITimeout, IConfirmationTimeoutChecker> confirmationTImeoutChecker, Func <ICommandIngester, ITimeout, ICompletitionTimeoutChecker> completitionCheckFactory, Func <IIncomingMessageProcessor> processorFactory, Func <IConfirmationFactory> confirmationFactory, Func <IIdGenerator> idGeneratorFactory, ITimeoutFactory timeoutFactory, Func <IMessenger, ICommandIngester, IIncomingMessageProcessor, ICompletitionTimeoutChecker, IConfirmationTimeoutChecker, IIdGenerator, IConfirmationFactory, IMessagingPipelineContext> messengingPipelineContextAF) { _messengerFactory = messengerFactory ?? throw new ArgumentNullException(nameof(messengerFactory)); _ingesterFactory = ingesterFactory ?? throw new ArgumentNullException(nameof(ingesterFactory)); _confirmationTImeoutChecker = confirmationTImeoutChecker ?? throw new ArgumentNullException(nameof(confirmationTImeoutChecker)); _completitionCheckFactory = completitionCheckFactory ?? throw new ArgumentNullException(nameof(completitionCheckFactory)); _processorFactory = processorFactory ?? throw new ArgumentNullException(nameof(processorFactory)); _confirmationFactory = confirmationFactory ?? throw new ArgumentNullException(nameof(confirmationFactory)); _idGeneratorFactory = idGeneratorFactory ?? throw new ArgumentNullException(nameof(idGeneratorFactory)); _timeoutFactory = timeoutFactory ?? throw new ArgumentNullException(nameof(timeoutFactory)); _messengingPipelineContextAF = messengingPipelineContextAF ?? throw new ArgumentNullException(nameof(messengingPipelineContextAF)); }
public BotModule( BotConfig botConfig, IMessengerFactory messengerFactory, IPluginManager pluginManager, ICommandParser commandParser, ILoggingService loggingService, IReporter reporter) : base("/bot") { #region Bot Route Post["/{token}", true] = async(parameters, ct) => { try { // Get the request's body as a string, for logging string request_string = this.Request.Body.AsString(); string sentToken = parameters.token; // If the passed token segment does not match the secret token, return NotAcceptable status if (botConfig.BotRoutes.FirstOrDefault(r => r.SecretToken == sentToken) == null) { string errMsg = string.Format("POST request from {0}: Token '{1}' was invalid.\nREQUEST = {2}", this.Request.UserHostAddress, sentToken, request_string); loggingService.Warning(errMsg); reporter.Warning(errMsg); return(HttpStatusCode.NotAcceptable); } var message = new GroupMeMessage(); // Bind and validate the request to GroupMeMessage var msg = this.BindToAndValidate(message); if (!ModelValidationResult.IsValid) { string errMsg = string.Format("POST request from {0}: Message was invalid.\nREQUEST = {1}", this.Request.UserHostAddress, request_string); loggingService.Warning(errMsg); reporter.Warning(errMsg); return(HttpStatusCode.NotAcceptable); } // Don't handle messages sent from ourself if (message.name.ToLower() == botConfig.BotName.ToLower()) { return(HttpStatusCode.NotAcceptable); } if (string.IsNullOrEmpty(message.text)) { loggingService.Debug("POST request from {0}: Message text is empty or null.\nREQUEST = {1}", this.Request.UserHostAddress, request_string); return(HttpStatusCode.NotAcceptable); } loggingService.Trace("MSG: From: {0} [UID: {1}]; Body: {2}", message.name, message.user_id, message.text); // Parse the command var command = commandParser.Parse(message.text); if (command != null) { if (!string.IsNullOrEmpty(command.Cmd)) { // Get instance of IMessenger for this bot route var botMessenger = messengerFactory.Create(sentToken); loggingService.Trace("Received command: {0}", command.Cmd); if (command.Cmd.ToLower() == "help") { bool helpHandled = await pluginManager.HandledHelpCommand(command, botMessenger); } else { // If a message is in a command format '<cmd>\s[message]', // have the plugin manager see if any loaded plugins are set to respond to that command bool handled = await pluginManager.HandleCommand(command, message, botMessenger); if (!handled) { pluginManager.SendMessage(message, botMessenger); } } } } return(HttpStatusCode.Accepted); } catch (Exception er) { reporter.Error("MAIN ERROR", er); loggingService.Error(er, string.Format("** MAIN ERROR: {0}", er.Message)); return(HttpStatusCode.BadGateway); } }; #endregion }
public ServiceInterfaceFactory(IServiceLocator serviceLocator, IMessengerFactory messengFactory) { this.serviceLocator = serviceLocator; this.messengerFactory = messengFactory; }