Beispiel #1
0
        private async Task RequestSpotifyAuthForUser(MBUser user, Message message, ILogger logger)
        {
            if (message.Chat.Type != ChatType.Private)
            {
                await TelegramClient.SendTextMessageAsync(
                    message.Chat.Id,
                    $"Sure thing... Sending you a message shortly to get us connected to Spotify");
            }

            var state = new AuthorizationState()
            {
                Message = message,
                UserId  = user.Id,
            };

            await TelegramClient.SendTextMessageAsync(
                user.ServiceId,
                $"OK, in order to continue, I need to connect to your Spotify so I can add you to the fun. Click the button below to get started.",
                replyMarkup : new InlineKeyboardMarkup(
                    new InlineKeyboardButton()
            {
                Text = "Connect Spotify Account",
                Url  = SpotifyService.GetAuthorizationUri(user, state, GetNetSpotifyScopesRequired(user)).ToString()
            }));
        }
Beispiel #2
0
        private async Task ProcessMissingScopes(MBUser user, Message message, bool isAuthorizationCallback, ILogger log)
        {
            var scopesRequierd = GetNetSpotifyScopesRequired(user);
            var missingScopes  = scopesRequierd.Except(user.SpotifyScopesList);

            if (isAuthorizationCallback)
            {
                // User already setup, this is an auth callback.. they must have denied scopes?
                // TODO: Send through error state from auth call

                log.LogWarning("User {user} denied scopes {scopes} for commmand {command}", user, string.Join(" ", missingScopes), this);

                await TelegramClient.SendTextMessageAsync(
                    message.Chat.Id,
                    $@"Sorry {user.ToTelegramUserLink()} but you need to grant additional permissions in order for us to run this command.",
                    ParseMode.Html);

                return;
            }

            // Request additional scopes
            var state = new AuthorizationState()
            {
                Message = message,
                UserId  = user.Id
            };

            log.LogInformation("User {user} needs to grant additional scopes for {command} ({misingScopes})", user, this, string.Join(' ', missingScopes));

            if (message.Chat.Id != message.From.Id)
            {
                await TelegramClient.SendTextMessageAsync(
                    message.Chat.Id,
                    $"Sure thing {user.ToTelegramUserLink()}... we need a few more permissions from you first. Check your private messages.",
                    ParseMode.Html
                    );
            }

            var response = string.IsNullOrWhiteSpace(user.SpotifyId)
                ? $"Sure! lets get you connected first. Click this link and authorize me to manage your Spotify player."
                : $"We need additional Spotify permissions from you to run the command {this.Command}. Please click this link and we'll get that sorted";

            await TelegramClient.SendTextMessageAsync(
                message.From.Id,
                response,
                ParseMode.Html,
                replyMarkup : new InlineKeyboardMarkup(
                    new InlineKeyboardButton()
            {
                Text = "Connect Account",
                Url  = SpotifyService.GetAuthorizationUri(user, state, GetNetSpotifyScopesRequired(user)).ToString()
            })
                );
        }