internal async Task GetInlineMessageResult(InlineQuery query, TelegramBot bot) { await HandleInlineMessage(query, bot); var jsonEncodeResult = JsonConvert.SerializeObject(results); var keyPairs = new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("inline_query_id", query.ID), new KeyValuePair<string, string>("results", jsonEncodeResult), new KeyValuePair<string, string>("is_personal", true.ToString()), new KeyValuePair<string, string>("cache_time", "0") }; var reply = await bot.HttpClient.PostAsync(bot.AnswerInlineLoc, new FormUrlEncodedContent(keyPairs)); }
protected override async Task HandleInlineMessage(InlineQuery query, TelegramBot.TelegramBot bot) { var userPreferences = PreferenceRegistry.GetUserPreferencesForUser(query.From); if (!query.HasParameters || true) //haal eigen rooster op { var roosterFor = userPreferences.RoosterFor; if (roosterFor == null) return; //Voor parameterloze queries moeten we een roosterfor hebben var day = DateTime.Today; for (var i = 0; i < 7; i++, day = day.AddDays(1)) { if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday) continue; var rooster = await WindesheimRoosterConvertor.GetRooster(userPreferences, day, day); if (!rooster.Success) { bot.PrintError($"Tijdens het opzoeken van het rooster voor een inline query is iets fout gegaan: {rooster.ErrorMessage}"); continue; } TemplateRoosterFormatToImageProvider provider; if (roosterFor.GetType().Name == nameof(Klas)) provider = RoosterFormatToImageProvider.Instance; else provider = DocentRoosterFormatToImageProvider.Instance; var bitmap = provider.GetImageForRooster(rooster.Rooster, userPreferences); if(bitmap == null) continue; var dateDirectory = day.ToString("yyyyMMdd"); var directory = $"images/{dateDirectory}"; if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); var localUrl = $"{directory}/{query.From.ID}.jpeg"; bitmap.Save(localUrl, System.Drawing.Imaging.ImageFormat.Jpeg); string url = $"http://roosterbot.sandervanteinde.nl/{dateDirectory}/{query.From.ID}.jpeg"; AddPhoto($"rooster-{day.ToString("YYYYMMdd")}-{query.From.ID}", url, GetCaptionForDate(day, dateDirectory), photoWidth: bitmap.Width, photoHeight: bitmap.Height, caption: $"Rooster van {query.From} voor {day.ToString("ddd dd MMM")}"); } } }
protected abstract Task HandleInlineMessage(InlineQuery query, TelegramBot bot);