Creating Multi response responders
madslyng opened this issue · 5 comments
I've been working on an implimentation using Margiebot, for automating tasks for my teams. I'm wondering if it has been considered how Margiebot could be extended to have a variant of responders, that doesn't only allow a single response.
A use case I have:
- Send a request to the bot, that will take some time to complete
- Bot sends a reply that it is working on the response.
- After the task is completed, it sends another response.
I implemented this exact functionality myself, and it's very possible. Here's a snapshot from the constructor of a custom responder that only responds to messages from me. When the bot is fully online, it sends me a DM :
public MasterResponder(string masterName, Bot botRef)
{
_masterName = masterName;
TimerHelper.SetTimeout(async () =>
{
while (botRef.ConnectedHubs == null) ;
await botRef.Say(new BotMessage()
{
Text = "hello master.",
ChatHub = botRef.ConnectedDMs.Where(x => x.Name == "@" + _masterName).Single()
});
}, 5000);
}
where TimerHelper is a little utility class that mimic's javascript's setTimeout():
public static class TimerHelper
{
public static IDisposable SetTimeout(Action method, int delayInMilliseconds)
{
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
timer.Elapsed += (source, e) =>
{
method();
};
timer.AutoReset = false;
timer.Enabled = true;
timer.Start();
return timer as IDisposable;
}
}
I see, so you use this inside a normal responder, correct ?
Yes, correct. I just passed the Bot reference to the constructor (in this
case).
You could broadcast a message from a background thread from any responder,
provided you have a reference to the Bot
On Wed, Oct 28, 2015 at 10:03 AM, Steffen Sun Lyng <notifications@github.com
wrote:
I see, so you use this inside a normal responder, correct ?
—
Reply to this email directly or view it on GitHub
#6 (comment).
Okay, thanks a lot for the information.
This is an interesting idea. I'll think about this when I have time and see if I can come up with a clean way to do add architectural support for this.