scrapinghub / slackbot

A chat bot for Slack (https://slack.com).
MIT License
1.26k stars 394 forks source link

Middleware #103

Open josefdlange opened 8 years ago

josefdlange commented 8 years ago

Does this library have a "middleware" type functionality, as in, something that intercepts each message as it comes through to attach some additional context or do something else with it, before it hits a responder?

lins05 commented 8 years ago

Not yet, but I like the idea. Middlewares are very good for adding more common functionality in a modularized manner. Do you want to help implement it?

josefdlange commented 8 years ago

Sure, I can take a look at it.

I'm really trying to get toward a way to elegantly shim conversational behavior into an existing Python Slackbot library. Middleware would be a good opportunity to intercept a message, and, by checking some persisted data, see if we were "in the middle of something" so that we can continue that multi-step interaction, instead of going onto the typical command processor. The trick is determining when a "conversation" is done, and whether or not the current incoming message is a continuation or a new command.

I'll keep thinking about it, glad to take any comments or thoughts.

josefdlange commented 8 years ago

FYI, I've started what is a loose ideological fork of this project (as in, borrowing concepts but not an actual real fork of the code) that is oriented more toward conversational (multi-step command) bots. While I'm working on that, I'll be implementing a middleware component that will likely take little effort to integrate here, which I will be glad to do as soon as it exists.

I'm open for discussion of contributing that from my own code or even, on a grander scale, combining the libraries into one bot framework to rule them all.

roperi commented 8 years ago

@josefdlange

It sounds great! But could you please elaborate a bit more about the 'toward conversational (multi-step command) bots bit? An example would be great for me to trigger more ideas. Thanks

josefdlange commented 8 years ago

Hey @h-2-0, check out https://github.com/josefdlange/slackborg for my initial implementation. Essentially, I'm aiming to have bots be more interactive. Here's a potential example:

me > Hey @myBot, can you look up airfare for me?
bot > Sure thing! Looks like you're in Seattle right now. Where are you flying to?
me > Boston
bot > Great town! When do you need to leave, and when will you be returning?
me > October 12th to November 3rd
bot > Got it. Searching now...
bot > Okay, I've got $349 for the *cheapest* flight, $413 for a *direct* flight, and $758 for *first class*. Which one would you like?
me > First class, please.
bot > Okeedokee -- here's a link to the itinerary so you can purchase your airfare: https://some-airline.com/trip/whatever/blah/blah/purchase
josefdlange commented 8 years ago

Obviously the details of the "airfare" example would be challenges left to the consumer of the slackborg library -- things like parsing the input language and interfacing with an airfares API -- but slackborg will keep track of a conversational context that the bot implementation can read and write to and from as a conversation continues, flushing it when the bot says the conversation is over.

roperi commented 8 years ago

@josefdlange, @lins05

Thanks for sharing! I checked slackborg out. Looks very like a clever way to deal with multi-step commands and closing them when done.

I definitely think slackbot users could benefit from slackborg if it were a middleware. In general, the idea of being able to attach middleware to slackbot would expand its user base, use and capabilities (especially since other people can also contribute towards the middleware as long as it is on github).

Thoughts?

P.S. @josefdlange Do you know of any good source to learn basics of parsing input language in a slackbot kind of way (i.e. using python decorators and regex)?