Example #1
0
        private static void Test()
        {
            var api = new Telegram.Bot.Api("Paste some key for debugging purposes");

            var flowEngine = new FlowEngine(api, new DatabaseStateProvider(@"Data Source=(localdb)\ProjectsV13;Initial Catalog=MafiaGM;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"), null);

            var mainMenu = flowEngine.AddCommand("start")
                           .EchoReply(new OneLanguageString("Welcome"));

            flowEngine.AddAnyInput()
            .EchoReply(new OneLanguageString("Please, type /Start to start"));
            mainMenu.AddCommand("help")
            .EchoReply(new OneLanguageString("No help for now"));
            mainMenu.AddCommand("sum")
            .EchoReply(new OneLanguageString("Provide A"))
            .AddAnyInput()
            .EchoReply(new OneLanguageString("Provide B (A is {0}"))
            .AddAnyInput()
            .AddDelegateInput(context => (int.Parse(context[0]) + int.Parse(context[1])).ToString())
            .EchoReply(new OneLanguageString("Result is {0}"))
            .Execute(context => context.Echo(context[1] + context[2], context.UserMessageIdOrZero)); //а тут сразу же показываем конкатенацию
            mainMenu.AddCommand("testPar", true)
            .EchoReply(new OneLanguageString("parameter is {0}"));
            mainMenu.AddCommandWithParameter("testAnyPar", new OneLanguageString("Please, enter value"))
            .ForEach(step => step.EchoReply(new OneLanguageString("Value is {0}")));

            int lastUpdate = 0;

            do
            {
                var updates = api.GetUpdates(lastUpdate + 1).Result;
                if (!updates.Any())
                {
                    Thread.Sleep(3000); continue;
                }
                foreach (var update in updates)
                {
                    IState state;
                    flowEngine.Process(update, null, out state);
                    ((DatabaseState)state).SaveAndDispose();
                    lastUpdate = update.Id;
                }
            } while (true);
        }