public void RespondToNotToMatchIntent()
    {
        SimpleResponder responder = new SimpleResponder(
            "ingredient", new List <string>(), null
            );

        Assert.That(() => responder.Respond(new DialogFirm.Intent("not-ingredient", true, new Dictionary <string, string>())),
                    Throws.TypeOf <System.InvalidOperationException>());
    }
    public void RespondToIntent()
    {
        SimpleResponder responder = new SimpleResponder(
            "ingredient", new List <string>()
        {
            "yes that is very tasty."
        }, null
            );

        Assert.AreEqual("yes that is very tasty.", responder.Respond(new DialogFirm.Intent("ingredient", true, new Dictionary <string, string>())));
    }
        // AVRO-625 [Test]
        // Currently, SocketTransceiver does not permit out-of-order requests on a stateful connection.
        public void Test()
        {
            var waitLatch       = new CountdownLatch(1);
            var simpleResponder = new SimpleResponder(waitLatch);

            server = new SocketServer("localhost", 0, simpleResponder);

            server.Start();

            int port = server.Port;

            transceiver = new SocketTransceiver("localhost", port);
            proxy       = new GenericRequestor(transceiver, SimpleResponder.Protocol);

            // Step 1:
            proxy.GetRemote(); // force handshake

            new Thread(x =>
            {
                // Step 2a:
                waitLatch.Wait();

                var ack = new GenericRecord(SimpleResponder.Protocol.Messages["ack"].Request);
                // Step 2b:
                proxy.Request("ack", ack);
            }).Start();


            /*
             * 3. Execute the Client.hello("wait") RPC, which will block until the
             *    Client.ack() call has completed in the background thread.
             */

            var request = new GenericRecord(SimpleResponder.Protocol.Messages["hello"].Request);

            request.Add("greeting", "wait");

            var response = (string)proxy.Request("hello", request);

            // 4. If control reaches here, both RPCs have executed concurrently
            Assert.AreEqual("wait", response);
        }
        // AVRO-625 [Test] 
        // Currently, SocketTransceiver does not permit out-of-order requests on a stateful connection.
        public void Test()
        {
            var waitLatch = new CountdownLatch(1);
            var simpleResponder = new SimpleResponder(waitLatch);
            server = new SocketServer("localhost", 0, simpleResponder);

            server.Start();

            int port = server.Port;

            transceiver = new SocketTransceiver("localhost", port);
            proxy = new GenericRequestor(transceiver, SimpleResponder.Protocol);

            // Step 1:
            proxy.GetRemote(); // force handshake

            new Thread(x =>
                           {
                               // Step 2a:
                               waitLatch.Wait();

                               var ack = new GenericRecord(SimpleResponder.Protocol.Messages["ack"].Request);
                               // Step 2b:
                               proxy.Request("ack", ack);

                           }).Start();


            /*
             * 3. Execute the Client.hello("wait") RPC, which will block until the
             *    Client.ack() call has completed in the background thread.
             */

            var request = new GenericRecord(SimpleResponder.Protocol.Messages["hello"].Request);
            request.Add("greeting", "wait");

            var response = (string)proxy.Request("hello", request);

            // 4. If control reaches here, both RPCs have executed concurrently
            Assert.AreEqual("wait", response); 
        }
Example #5
0
        /// <summary>
        /// If you want to use this application to run your bot, here's where you start. Just scrap as many of the responders
        /// described in this method as you want and start fresh. Define your own responders using the methods describe
        /// at https://github.com/jammerware/margiebot/wiki/Configuring-responses and return them in an IEnumerable<IResponder>.
        /// You can create them in this project, in a separate one, or even in the SampleResponders project if you want.
        ///
        /// Boom! You have your own bot.
        /// </summary>
        /// <returns>A list of the responders this bot should respond with.</returns>
        public IEnumerable <IResponder> GetResponders(Bot bot, IConfigurationRoot appConfig)
        {
            // Some of these are more complicated than they need to be for the sake of example
            var responders = new List <IResponder>();

            // examples of semi-complex or "messier" responders (created in separate classes)
            responders.Add(new ScoreResponder());
            responders.Add(new ScoreboardRequestResponder());
            responders.Add(new WhatsNewResponder());
            responders.Add(new WikipediaResponder());

            // if you want to use these, you'll need to sign up for api keys from http://wunderground.com and http://www.dictionaryapi.com/ - they're free! Put them in your
            // config.json, uncomment the lines below, and you're good to go.
            //responders.Add(new WeatherRequestResponder(appConfig["wundergroundApiKey"]));
            //responders.Add(new DefineResponder(appConfig["dictionaryApiKey"]));

            // examples of simple-ish "inline" responders
            // this one hits on Slackbot when he talks 1/8 times or so
            responders.Add(SimpleResponder.Create
                           (
                               (responseCtx) => responseCtx.Message.User.IsSlackbot && new Random().Next(8) <= 1,
                               (responseCtx) => responseCtx.Get <Phrasebook>().GetSlackbotSalutation()
                           ));

            // this one responds if someone thanks Margie
            responders.Add(SimpleResponder.Create
                           (
                               (responseCtx) => responseCtx.Message.MentionsBot && Regex.IsMatch(responseCtx.Message.Text, @"\b(thx|thanks|thank you)\b", RegexOptions.IgnoreCase),
                               (responseCtx) => responseCtx.Get <Phrasebook>().GetYoureWelcome()
                           ));

            // example of Supa Fly Mega EZ Syntactic Sugary Responder (not their actual name)
            bot
            .RespondsTo("get on that")
            .With("Sure, hun!")
            .With("I'll see what I can do, sugar.")
            .With("I'll try. No promises, though!")
            .IfBotIsMentioned();

            // you can do these with regexes too
            bot
            .RespondsTo("what (can|do) you do", true)
            .With(@"Lots o' things! I mean, potentially, anyway. Right now I'm real good at keepin' score (try plus-one-ing one of your buddies sometime). I'm learnin' about how to keep up with the weather from my friend DonnaBot. I also can't quite keep my eyes off a certain other bot around here :) If there's anythin' else you think I can help y'all with, just say so! The feller who made me tends to keep an eye on me and see how I'm doin'. So there ya have it.")
            .IfBotIsMentioned();

            // this last one just responds if someone says "hi" or whatever to Margie, but only if no other responder has responded
            responders.Add(SimpleResponder.Create
                           (
                               (responseCtx) =>
            {
                return
                (responseCtx.Message.MentionsBot &&
                 !responseCtx.BotHasResponded &&
                 Regex.IsMatch(responseCtx.Message.Text, @"\b(hi|hey|hello|what's up|what's happening)\b", RegexOptions.IgnoreCase) &&
                 responseCtx.Message.User.ID != responseCtx.BotUserID &&
                 !responseCtx.Message.User.IsSlackbot);
            },
                               (responseCtx) => responseCtx.Get <Phrasebook>().GetQuery()
                           ));

            return(responders);
        }