Exemplo n.º 1
0
 private async Task GetParameterValueFromClient(MethodInfo methodInfo, ParameterInfo parameterInfo, TelegramClientInfo clientInfo, MessageEventArgs e)
 {
     if (!CurrentBotStructureInfo.OnParameterSelecting(methodInfo, parameterInfo, clientInfo, e.Message.Text))
     {
         if (parameterInfo == null)
         {
             List <List <BotButtonInfo> > buttons = GetMethodParametersButtons(methodInfo, clientInfo);
             CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Parameters, clientInfo.CurrentServiceName, clientInfo.CurrentMethodName, clientInfo);
             ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
             {
                 Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
             };
             await _botClient.SendTextMessageAsync(
                 chatId : e.Message.Chat,
                 text : CurrentBotStructureInfo.GetParameterNotFoundText(e.Message.Text, clientInfo),
                 replyMarkup : replyMarkup
                 );
         }
         else
         {
             clientInfo.CurrentParameterName = parameterInfo.Name;
             List <List <BotButtonInfo> > buttons = GetMethodParametersButtons(methodInfo, clientInfo);
             CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Parameters, clientInfo.CurrentServiceName, clientInfo.CurrentMethodName, clientInfo);
             ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
             {
                 Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
             };
             await _botClient.SendTextMessageAsync(
                 chatId : e.Message.Chat,
                 text : CurrentBotStructureInfo.GetParameterSelectedText(GetParameterCaption(methodInfo, parameterInfo), clientInfo),
                 replyMarkup : replyMarkup
                 );
         }
     }
 }
Exemplo n.º 2
0
 private async Task ShowServiceMethods(string serviceName, TelegramClientInfo clientInfo, Message message)
 {
     clientInfo.CurrentServiceName = serviceName;
     clientInfo.CurrentMethodName  = null;
     if (Services.TryGetValue(serviceName, out Type service))
     {
         List <List <BotButtonInfo> > buttons = GetServiceMethodsButtons(service, clientInfo);
         CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Services, serviceName, null, clientInfo);
         ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
         {
             Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
         };
         await _botClient.SendTextMessageAsync(
             chatId : message.Chat,
             text : CurrentBotStructureInfo.GetServiceSelectedText(GetServiceName(service), GetServiceCaption(service), service, clientInfo),
             replyMarkup : replyMarkup
             );
     }
     else
     {
         await _botClient.SendTextMessageAsync(
             chatId : message.Chat,
             text : CurrentBotStructureInfo.GetServiceNotFoundText(serviceName, clientInfo)
             );
     }
 }
Exemplo n.º 3
0
        private async Task ShowResultValue(Shared.Models.CallMethodResultInfo <OperationContext> callMethodResultInfo, MethodInfo methodInfo, TelegramClientInfo clientInfo, Message message)
        {
            clientInfo.CurrentParameterName = null;
            List <List <BotButtonInfo> > buttons = GetMethodParametersButtons(methodInfo, clientInfo);

            CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Parameters, clientInfo.CurrentServiceName, clientInfo.CurrentMethodName, clientInfo);
            ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
            {
                Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
            };

            if (callMethodResultInfo.CallbackInfo.Data.Length > 4000)
            {
                using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(callMethodResultInfo.CallbackInfo.Data)))
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    InputOnlineFile inputOnlineFile = new InputOnlineFile(stream);
                    inputOnlineFile.FileName = "reponse.txt";
                    await _botClient.SendDocumentAsync(
                        chatId : message.Chat,
                        document : inputOnlineFile,
                        caption : $"Response of {methodInfo.Name}",
                        replyMarkup : replyMarkup
                        );
                }
            }
            else
            {
                await _botClient.SendTextMessageAsync(
                    chatId : message.Chat,
                    text : callMethodResultInfo.CallbackInfo.Data,
                    replyMarkup : replyMarkup
                    );
            }
        }
Exemplo n.º 4
0
        private async Task ShowServiceMethods(MethodInfo method, TelegramClientInfo clientInfo, Message message, string customText = null)
        {
            clientInfo.CurrentMethodName = method.Name;
            List <List <BotButtonInfo> > buttons = GetMethodParametersButtons(method, clientInfo);

            CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Parameters, clientInfo.CurrentServiceName, clientInfo.CurrentMethodName, clientInfo);
            ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
            {
                Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
            };
            await _botClient.SendTextMessageAsync(
                chatId : message.Chat,
                text : string.IsNullOrEmpty(customText)?CurrentBotStructureInfo.GetMethodSelectedText(method.Name, clientInfo) : customText,
                replyMarkup : replyMarkup
                );
        }
Exemplo n.º 5
0
        private async Task ShowServices(TelegramClientInfo clientInfo, MessageEventArgs e)
        {
            string text = CurrentBotStructureInfo.GetServicesGeneratedText(clientInfo);

            clientInfo.CurrentServiceName = null;
            List <List <BotButtonInfo> > buttons = GetListOfServicesButtons(clientInfo);

            CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Services, null, null, clientInfo);
            ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
            {
                Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
            };
            await _botClient.SendTextMessageAsync(
                chatId : e.Message.Chat,
                text : text,
                replyMarkup : replyMarkup
                );
        }
Exemplo n.º 6
0
        private async Task SetParameterValueFromClient(MethodInfo methodInfo, ParameterInfo parameterInfo, TelegramClientInfo clientInfo, MessageEventArgs e)
        {
            string value = e.Message.Text;

            clientInfo.CurrentParameterName = null;
            List <List <BotButtonInfo> > buttons = GetMethodParametersButtons(methodInfo, clientInfo);

            CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Parameters, clientInfo.CurrentServiceName, clientInfo.CurrentMethodName, clientInfo);
            ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
            {
                Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
            };

            ChangeParameterValue(methodInfo, parameterInfo, clientInfo, value);
            await _botClient.SendTextMessageAsync(
                chatId : e.Message.Chat,
                text : CurrentBotStructureInfo.GetParameterValueChangedText(GetParameterCaption(methodInfo, parameterInfo), clientInfo),
                replyMarkup : replyMarkup
                );
        }
Exemplo n.º 7
0
        private async Task ShowResultValue(string response, MethodInfo methodInfo, TelegramClientInfo clientInfo, MessageEventArgs e)
        {
            if (string.IsNullOrEmpty(response))
            {
                return;
            }
            clientInfo.CurrentParameterName = null;
            List <List <BotButtonInfo> > buttons = GetMethodParametersButtons(methodInfo, clientInfo);

            CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Parameters, clientInfo.CurrentServiceName, clientInfo.CurrentMethodName, clientInfo);
            ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
            {
                Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
            };
            await _botClient.SendTextMessageAsync(
                chatId : e.Message.Chat,
                text : response,
                replyMarkup : replyMarkup
                );
        }
Exemplo n.º 8
0
 public async void SendText(string text, TelegramClientInfo clientInfo, List <List <BotButtonInfo> > botButtons)
 {
     try
     {
         clientInfo.CurrentServiceName = null;
         CurrentBotStructureInfo.OnButtonsGenerating(botButtons, BotLevelType.Services, null, null, clientInfo);
         ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
         {
             Keyboard = BotButtonsToKeyboardButtons(botButtons, clientInfo)
         };
         await _botClient.SendTextMessageAsync(
             chatId : clientInfo.Message.Chat,
             text : text,
             replyMarkup : replyMarkup
             );
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Exemplo n.º 9
0
 public async void ShowServices(TelegramClientInfo clientInfo, string message = null)
 {
     try
     {
         clientInfo.CurrentServiceName = null;
         List <List <BotButtonInfo> > buttons = GetListOfServicesButtons(clientInfo);
         CurrentBotStructureInfo.OnButtonsGenerating(buttons, BotLevelType.Services, null, null, clientInfo);
         ReplyKeyboardMarkup replyMarkup = new ReplyKeyboardMarkup
         {
             Keyboard = BotButtonsToKeyboardButtons(buttons, clientInfo)
         };
         await _botClient.SendTextMessageAsync(
             chatId : clientInfo.Message.Chat,
             text : message == null?CurrentBotStructureInfo.GetServicesGeneratedText(clientInfo) : message,
             replyMarkup : replyMarkup
             );
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }