public async Task HandleGetMesssagesChosenInlineResult(ChosenInlineResult sender, Service service) { var messageId = sender.ResultId; var formattedMessage = await Methods.GetMessage(service, messageId); await _botActions.ShowShortMessageAsync(sender.From, formattedMessage); }
public async Task <bool?> Handle(ChosenInlineResult data, object context = default, CancellationToken cancellationToken = default) { var resultParts = data.ResultId.Split(':'); switch (resultParts[0]) { case PollEx.InlineIdPrefix: if (!PollEx.TryGetPollId(resultParts.ElementAtOrDefault(1), out var pollId, out var format)) { return(null); } var pollMessage = await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { PollId = pollId }, myUrlHelper, format, cancellationToken); if (pollMessage != null) { if (pollMessage.Poll is Poll poll && (poll.Portal?.Guid ?? poll.PortalId) is string guid) { await myPoGoToolsClient.UpdateWayspot(guid, poll.ExRaidGym?Wayspot.ExRaidGym : Wayspot.Gym, cancellationToken); } return(true); } return(false); } return(null); }
private async Task HandleRecipientChosenInlineResult <T>(ChosenInlineResult sender, string recipentProperyName) where T : class, IUserInfo, new() { var model = await _dbWorker.FindNmStoreAsync(sender.From); if (model == null) { await _botActions.SendLostInfoMessage(sender.From); return; } if (!Methods.EmailAddressValidation(sender.ResultId)) { await _botActions.NotRecognizedEmailMessage(sender.From, sender.ResultId); return; } var property = model.GetPropertyValue(recipentProperyName) as ICollection <T>; var addressModel = new T { Email = sender.ResultId }; property?.Add(addressModel); await _dbWorker.UpdateNmStoreRecordAsync(model); await _botActions.UpdateNewMailMessage(sender.From, SendKeyboardState.Continue, model); }
public async Task HandleEditDraftChosenInlineResult(ChosenInlineResult sender) { var draftId = sender.ResultId; var nmStore = await _dbWorker.FindNmStoreAsync(sender.From); if (nmStore == null) { var draft = await Methods.GetDraft(sender.From, draftId, UsersResource.DraftsResource.GetRequest.FormatEnum.Full); nmStore = await _dbWorker.AddNewNmStoreAsync(sender.From); var formattedMessage = new FormattedMessage(draft); Methods.ComposeNmStateModel(nmStore, formattedMessage); var textMessage = await _botActions.SpecifyNewMailMessage(sender.From, SendKeyboardState.Continue, nmStore); nmStore.MessageId = textMessage.MessageId; nmStore.DraftId = draft.Id; await _dbWorker.UpdateNmStoreRecordAsync(nmStore); } else { await _botActions.SaveAsDraftQuestionMessage(sender.From, SendKeyboardState.Store); } }
public async Task Should_Answer_Inline_Query_With_Contact() { await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldAnswerInlineQueryWithContact, startInlineQuery : true); Update update = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync(); const string resultId = "contact:john-doe"; InlineQueryResultBase[] results = { new InlineQueryResultContact( id: resultId, phoneNumber: "+1234567", firstName: "John") { LastName = "Doe" } }; await BotClient.AnswerInlineQueryAsync( inlineQueryId : update.InlineQuery.Id, results : results, cacheTime : 0 ); var inlieQueryUpdates = await GetInlineQueryResultUpdates(MessageType.Contact); ChosenInlineResult chosenResult = inlieQueryUpdates.ChosenResultUpdate.ChosenInlineResult; Assert.Equal(MessageType.Contact, inlieQueryUpdates.MessageUpdate.Message.Type); Assert.Equal(resultId, chosenResult.ResultId); Assert.Empty(chosenResult.Query); }
public void HandleChosenInlineResult(ChosenInlineResult chosenInlineResult) { var ids = chosenInlineResult.ResultId.Split(':'); var list = _checkListService.GetCheckList(int.Parse(ids[0])); _workCheckListService.BindWorkCheckListToInlineMessage(int.Parse(ids[1]), chosenInlineResult.InlineMessageId); }
private void TryRaiseNewChosenInlineResult(ChosenInlineResult sender) { if (sender == null) { return; } TelegramChosenInlineEvent?.Invoke(sender); }
public async Task SaveLogAsync(long botId, ChosenInlineResult chosenInlineResult) { var tableName = "bot" + botId + "year" + DateTimeOffset.UtcNow.Year; var table = await GetTable(tableName); var entity = ChatMessage.Create(chosenInlineResult); await table.ExecuteAsync(TableOperation.InsertOrReplace(entity)); }
private static async void OnInlineResultChosen(object sender, ChosenInlineResultEventArgs e) { ChosenInlineResult res = e.ChosenInlineResult; if (res != null) { await router.HandleAsync(res.Query, res); } Console.WriteLine($"{res.From.FirstName} {res.From.LastName}: {res.Query}"); }
public static ChatMessage Create(ChosenInlineResult chosenInlineResult) { var key = GetKey(0, DateTimeOffset.Now); return(new ChatMessage() { PartitionKey = key.PartitionKey, RowKey = key.RowKey, ChosenInlineResult = chosenInlineResult, ChatId = 0, FromId = chosenInlineResult.From.Id, }); }
public async Task OnChosenResult(ChosenInlineResult argsChosenInlineResult) { string resultId = argsChosenInlineResult.ResultId; string messageId = argsChosenInlineResult.InlineMessageId; Log.Information($"Chose result {resultId} with message {messageId}"); if (!_resultsStorage.TryRemove(resultId, out var finalMessage)) { return; } var(image, caption) = finalMessage; await Bot.Client.EditMessageMediaAsync(messageId, new InputMediaPhoto(new InputMedia(image))); await Bot.Client.EditMessageCaptionAsync(messageId, caption); Log.Information("Edited"); }
public async Task <bool?> Handle(ChosenInlineResult data, object context = default, CancellationToken cancellationToken = default) { var resultParts = data.ResultId.Split(':'); switch (resultParts[0]) { case PREFIX: if (myTimeZoneNotifyService.DecodeId(resultParts.Skip(1).FirstOrDefault(), out var chatId, out var messageId) && resultParts.Skip(2).FirstOrDefault() is {} timeZoneId&& myDateTimeZoneProvider.GetZoneOrNull(timeZoneId) is {}) { if (!await CheckRights(chatId, data.From, cancellationToken)) { await myBot.EditMessageTextAsync(data.InlineMessageId !, new InputTextMessageContent("You have no rights"), cancellationToken : cancellationToken); return(false); } var settings = myDB.Set <TimeZoneSettings>(); if (await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(settings.Where(s => s.ChatId == chatId && s.TimeZone == timeZoneId), cancellationToken) == null) { settings.Add(new TimeZoneSettings { ChatId = chatId, TimeZone = timeZoneId }); await myDB.SaveChangesAsync(cancellationToken); } var(content, replyMarkup) = await myTimeZoneNotifyService.GetSettingsMessage(new Chat { Id = chatId, Type = ChatType.Sender }, cancellationToken : cancellationToken); await myBot.EditMessageTextAsync(data.InlineMessageId !, content, replyMarkup, cancellationToken); if (messageId != 0) { await myBot.DeleteMessageAsync(chatId, messageId, cancellationToken); } return(true); } break; }
public async Task Should_Answer_Inline_Query_With_Article() { // ToDo: add exception: Bad Request: QUERY_ID_INVALID await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldAnswerInlineQueryWithArticle, startInlineQuery : true); Update queryUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync(); const string resultId = "article:bot-api"; InputMessageContentBase inputMessageContent = new InputTextMessageContent("https://core.telegram.org/bots/api"); InlineQueryResultBase[] results = { new InlineQueryResultArticle( id: resultId, title: "Telegram Bot API", inputMessageContent: inputMessageContent) { Description = "The Bot API is an HTTP-based interface created for developers", }, }; await BotClient.AnswerInlineQueryAsync( inlineQueryId : queryUpdate.InlineQuery.Id, results : results, cacheTime : 0 ); var inlieQueryUpdates = await GetInlineQueryResultUpdates(MessageType.Text); Update resultUpdate = inlieQueryUpdates.ChosenResultUpdate; ChosenInlineResult chosenResult = resultUpdate.ChosenInlineResult; Assert.Equal(UpdateType.ChosenInlineResult, resultUpdate.Type); Assert.Equal(resultId, chosenResult.ResultId); Assert.Empty(chosenResult.Query); }
public async Task Should_Answer_Inline_Query_With_Article() { await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldAnswerInlineQueryWithArticle, startInlineQuery : true); Update iqUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync(); const string resultId = "article:bot-api"; InlineQueryResultBase[] results = { new InlineQueryResultArticle( id: resultId, title: "Telegram Bot API", inputMessageContent: new InputTextMessageContent( "https://core.telegram.org/bots/api") ) { Description = "The Bot API is an HTTP-based interface created for developers", }, }; await BotClient.AnswerInlineQueryAsync( inlineQueryId : iqUpdate.InlineQuery.Id, results : results, cacheTime : 0 ); (Update messageUpdate, Update chosenResultUpdate) = await _fixture.UpdateReceiver.GetInlineQueryResultUpdates(MessageType.Text); ChosenInlineResult chosenResult = chosenResultUpdate.ChosenInlineResult; Assert.Equal(MessageType.Text, messageUpdate.Message.Type); Assert.Equal(resultId, chosenResult.ResultId); Assert.Equal(iqUpdate.InlineQuery.Query, chosenResultUpdate.ChosenInlineResult.Query); }
public PollMessage(ChosenInlineResult inlineResult) { UserId = inlineResult.From?.Id; InlineMesssageId = inlineResult.InlineMessageId; }
private Task ChosenInlineResultAsync(ChosenInlineResult chosenInlineResult) { return(Task.CompletedTask); }
/// <summary> /// Initializes a new instance of the <see cref="ChosenInlineResultEventArgs"/> class. /// </summary> /// <param name="chosenInlineResult">The chosen inline result.</param> internal ChosenInlineResultEventArgs(ChosenInlineResult chosenInlineResult) { ChosenInlineResult = chosenInlineResult; }
/// <summary> /// Initializes a new instance of the <see cref="ChosenInlineResultEventArgs"/> class. /// </summary> /// <param name="update">The update.</param> internal ChosenInlineResultEventArgs(Update update) { ChosenInlineResult = update.ChosenInlineResult; }
public async Task HandleChosenInlineResult(ChosenInlineResult chosenInlineResult) { _logger.LogInformation($"Received inline result: {chosenInlineResult.ResultId}"); await Task.CompletedTask; }
public async Task HandleSetBccChosenInlineResult(ChosenInlineResult sender) { await HandleRecipientChosenInlineResult <BccModel>(sender, "Bcc"); }
public async Task HandleSetToChosenInlineResult(ChosenInlineResult sender) { await HandleRecipientChosenInlineResult <ToModel>(sender, "To"); }
private async Task onChosenInlineResultReceived(ChosenInlineResult result) { }
/// <summary> /// Initializes a new instance of the <see cref="ChosenInlineResultEventArgs"/> class /// </summary> /// <param name="chosenInlineResult">The chosen inline result</param> public ChosenInlineResultEventArgs(ChosenInlineResult chosenInlineResult) { ChosenInlineResult = chosenInlineResult; }
private async Task OnChosenInlineResultReceived(object sender, Result result) { ChosenInlineResult chosenInlineResult = (ChosenInlineResult)result.data; await Logger.WriteLogAsync($"Received choosen inline result: {chosenInlineResult.ResultId}"); }
public virtual async Task OnChosenInlineResultAsync(ChosenInlineResult chosenInlineResult) { await storageService.SaveLogAsync(Id, chosenInlineResult); logger.LogInformation("Choosen inline result (override OnChosenInlineResultAsync() to handle):" + Environment.NewLine + chosenInlineResult.ResultId); }
private static async Task BotOnChosenInlineResultReceived(ChosenInlineResult chosenInlineResult) { Console.WriteLine($"Received inline result: {chosenInlineResult.ResultId}"); }
private async Task BotOnChosenInlineResultReceived(ChosenInlineResult chosenInlineResult) { _logger.LogInformation($"Received inline result: {chosenInlineResult.ResultId}"); }