public async Task Hi(string str)
        {
            //Use dependency injection just like you do in ASP.NET.
            //Use extensions to make your life eathier.
            //Some of extension services are included as controller properties:
            // * logger
            // * BotExt (improved bot)
            // * mvc features
            // ...

            //Access current telegram Update as property of controller.

            //Extension too. Send message to current chat.
            await SendTextMessageAsync("Hi.");

            if (IsModelStateValid)
            {
                await SendTextMessageAsync(
                    $"Hi. You passed '{str}' with command. Note, default model binder split all command parameters by space," +
                    $"like in CLI, so you can't pass string with command using default model binder."
                    );
            }

            await UpdateContext.SendTextMessageAsync("Send message with reply to bot.");

            //Improved bot extension. Allow to await new messages from current chat, just like in console applications.
            var message = await BotExt.ReadMessageAsync(ReadCallbackFromType.CurrentUserReply);

            await SendTextMessageAsync($"You send: {message.Text}");

            //Use UpdateContext to get more info about current "request".
        }
        public async Task ReadMsgTest()
        {
            await UpdateContext.SendTextMessageAsync("Send me a message.");

            var message = await BotExt.ReadMessageAsync(ReadCallbackFromType.CurrentUser);

            await SendTextMessageAsync($"You send: {message.Text}");
        }
        public async Task ForceExitTest()
        {
            await SendTextMessageAsync("Send me /cancel");

            await BotExt.ReadMessageAsync(ManagedKeyboard.DefaultUpdatesValidator);

            await SendTextMessageAsync("This will not be send.");
        }
        public async Task TestRestoreMarkup()
        {
            await SendTextMessageAsync($"Send me something like:\n\n" +
                                       $"`Code str` \n```Code``` \n*Bold* \n_Italic_ \n[google link](https://google.com)");

            var readMsg = await BotExt.ReadMessageAsync();

            var markdownText = readMsg.RestoreMarkdown();

            await SendTextMessageAsync(markdownText, parseMode : ParseMode.MarkdownV2);
        }
예제 #5
0
        public async Task NewBot()
        {
            await Bot.SendTextMessageAsync(ChatId, "Enter bot name: ");

            Message msg = await BotExt.ReadMessageAsync();

            var name = msg.Text;
            await Bot.SendTextMessageAsync(ChatId, "Enter bot nikname: ");

            msg = await BotExt.ReadMessageAsync();

            var nick = msg.Text;

            //Creating bot started...
            //If operation is too long, you can use CancellationToken to calcel it when cancellation requested, just like ReadMessageAsync do.
            UpdateProcessingAborted.ThrowIfCancellationRequested();
            //Creating bot finished...

            await Bot.SendTextMessageAsync(ChatId, "Bot created.");

            //In mvc middleware called by default if found command or read-callback.
            //Next middleware can ignore it.
            UpdateContext.Processed();
        }