public async Task <BotResponseCode> TryHandleCallbackQuery(UpdateDto updateDto) { // If the bot can't do anything with the update's callback query, we're done. if (!CanHandleCallbackQuery(updateDto)) { return(BotResponseCode.NoAction); } // Check if a vote should be handled and if so handle it. var voteResponseCode = await _voteService.TryHandleVote(updateDto); if (voteResponseCode != BotResponseCode.NoAction) { // Save users that voted. await _userService.SaveUser(updateDto.ParsedUser, updateDto.Chat.Id); return(voteResponseCode); } if (IsAddToQueueCallback(updateDto)) { if (updateDto.User == null || updateDto.Track == null) { return(BotResponseCode.CommandRequirementNotFulfilled); } var spotifyClient = await _spotifyClientFactory.Create(updateDto.User.Id); if (spotifyClient == null) { var text = $"You didn't connect your Spotify account yet, {updateDto.User.FirstName}. Please connect first."; // TODO: move to commandsservice, get username from telegram me apicall. var url = $"http://t.me/SpotiHenkBot?start={LoginRequestReason.AddToQueue}_{updateDto.Chat.Id}_{updateDto.Track.Id}"; await _sendMessageService.AnswerCallbackQuery(updateDto.ParsedUpdateId, text, url); return(BotResponseCode.AddToQueueHandled); } if (await _spotifyClientService.AddToQueue(spotifyClient, updateDto.Track)) { await _sendMessageService.AnswerCallbackQuery(updateDto.ParsedUpdateId, "Track added to your queue."); } else { await _sendMessageService.AnswerCallbackQuery(updateDto.ParsedUpdateId, "Could not add track to your queue, play something first!"); } return(BotResponseCode.AddToQueueHandled); } // This should never happen. throw new CallbackQueryNotHandledException(); }
/// <summary> /// Let telegram know the callback query has been handled. /// </summary> private Task AnswerCallback(UpdateDto updateDto, string text) { return(_sendMessageService.AnswerCallbackQuery(updateDto.ParsedUpdateId, text)); }