private static void Bot_OnMessage(object sender, global::Telegram.Bot.Args.MessageEventArgs e) { //Chamar API pra cadastrar o pedido { ChatMq chat; if (ActiveChats.ContainsKey(e.Message.Chat.Id)) { chat = ActiveChats[e.Message.Chat.Id]; } else { chat = new ChatMq() { ChatId = e.Message.Chat.Id, QueueName = MqHelper.GetQueueChatName(e.Message.Chat.Id) }; ActiveChats.Add(e.Message.Chat.Id, chat); } Console.WriteLine($"Getting sender information:\n\tChatId: {chat.ChatId}\n\tLastUsedQueue: {chat.QueueName}\n\tLastAppUse: {chat.LastQuery}"); chat.LastQuery = DateTime.Now; //Criando o conteudo para a Azure function var str = new StringContent(JsonConvert.SerializeObject(new { name = e.Message.Text, queue = chat.QueueName }), Encoding.Default, "application/json"); //Cadastrar uma fila pra escutar até voltar as imagens mq.CreateQueue(chat.QueueName); mq.ConfigureConsumeQueueListener(chat.QueueName, false, sendResultSheets); //Chamando a Azure Function _client.PostAsync(TelegramConstants.OrquestradorGetSheetUrl, str).GetAwaiter().GetResult(); } }
public void Run([TimerTrigger("0 */10 * * * *")] TimerInfo myTimer, ILogger log) { var scheduledSearches = _database.GetSheetsToSearch(); Parallel.ForEach(scheduledSearches, search => { //Chamar API pra cadastrar o pedido using (var client = new HttpClient()) { string queueName = MqHelper.GetQueueChatName(search.ChatId); //Criando o conteudo para a Azure function var str = new StringContent(JsonConvert.SerializeObject(new { name = search.Term, queue = queueName }), Encoding.Default, "application/json"); //Cadastrar uma fila pra escutar até voltar as imagens _mq.CreateQueue(queueName); //Chamando a Azure Function client.PostAsync(EnvironmentHelper.GetValue(DictionaryConstants.OrquestradorGetSheetUrl), str).GetAwaiter().GetResult(); } }); log.LogInformation($"Scheduler runned at '{DateTime.Now}'"); }