Pipeline & Middleware - noobot/noobot GitHub Wiki

How to customise

Pipeline & Middleware

When a message is detected by Noobot a pipeline is created, it then passes the incoming message through the pipeline. The pipeline is formed of middleware that can intercept a message, modify a message, respond to it or ignore it (or do all of them).

Using the pipeline pattern gives middleware lots of power over how incoming messages are handled, and using the base classes provided allow you to get up and running really quickly (however they are not required).

Any middleware have to simply implement the interface IMiddleware to be compatible.

Middleware are built with StructureMap, so it fully supports DI. This allows you to communicate easily with any plugins you have built. (plugins are singletons, so when you are communicating with a plugin it is always the same plugin)

How are messages sent?

Using the super handy yield return method, you can return messages in real time when long running processes are executing without having to wait for an operation to execute:

yield return incomingMessage.ReplyToChannel("Waiting before");
Thread.Sleep(TimeSpan.FromSeconds(3));
yield return incomingMessage.ReplyToChannel("Waiting after");

How do I setup my pipeline?

Within the project you will find a class called src/Noobot.Custom/PipelineManager, simply add your middleware to the Initialise() function.

protected override void Initialise()
{
    Use<WelcomeMiddleware>();
    Use<JokeMiddleware>();
    Use<YieldTestMiddleware>();
    Use<PingMiddleware>();
    Use<FlickrMiddleware>();
}

Please note: the ordering of the pipeline is important.

Async?

YUP. The pipeline is contained within a TPL Task which means a response can take as long as it needs.