public static void OnMessageSent(object sender, MessageEventArgs e, TelegramInteractivity interactivity) { // If it's a command, ignore it. if (e.Message.Text?.StartsWith(interactivity.Configuration.CommandPrefix) == true) { return; } // Get the interactivity object of this message. var iObject = interactivity.CurrentMessageInteractivityObjects .FirstOrDefault(obj => e.Message.Chat.Id == obj.Chat.Id && (obj.Predicate == null || obj.Predicate.Invoke(e.Message))); // Null check if (iObject != null) { // Set its result. iObject.InteractivityResult = new InteractivityResult <Message> (e.Message, iObject.InteractivityResult?.TimedOut ?? false); // If it hasn't timed out if (iObject.InteractivityResult?.TimedOut == false) { interactivity.CurrentMessageInteractivityObjects.Remove(iObject); iObject.TimeoutThreadToken.Cancel(); iObject.WaitHandle.Set(); } } }
/// <summary> /// Use Interactivity with this Bot Client. /// </summary> /// <param name="client">Your TelegramBotClient</param> /// <param name="configuration">Interactivity Configuration</param> public static void UseInteractivity(this TelegramBotClient client, InteractivityConfiguration configuration) { var interactivity = new TelegramInteractivity(client, configuration); currentInteractivities.Add(client, interactivity); }