示例#1
0
        public static IDisposable Use(ITelegramBotClient bot, IChatBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();
            var engine = bootstrapper.GetEngine();

            var disp1 = bot.GetMessageReceivedObservable()
                        .Where(msg => msg.Text != null)
                        .Select(async msg =>
            {
                var chatRequest = new Request(msg, bot);
                var context     = await engine.HandleRequest(chatRequest);
                context.Dispose();
            })
                        .Subscribe();

            var disp2 = bot.GetMessageReceivedObservable()
                        .Where(msg => msg.ReplyToMessage != null)
                        .Select(async msg =>
            {
                await engine.HandleReply(msg);
            })
                        .Subscribe();

            return(new CompositeDisposable(disp1, disp2));
        }