Updated CLI walkthrough for setting up with Facebook#8
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR enhances the Facebook setup CLI experience by adding comprehensive credential validation, interactive help dialogs, and improved documentation. The changes aim to reduce user errors during the Facebook bot setup process.
Changes:
- Added credential validation for Facebook Page ID, Access Token, and Verify Token with format checking
- Implemented interactive help system (type
?at prompts for detailed instructions) - Created
FACEBOOK_SETUP_QUICK.mdquick reference guide - Added webhook configuration file generation (
WEBHOOK_INFO.txt) for easy reference - Enhanced user feedback with confirmation prompts and better error messages
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
src/cli/setup_cli.py |
Added validation functions, interactive help system, confirmation prompts, and webhook info file generation |
tests/unit/test_setup_cli.py |
Updated mocks for new confirmation prompts and added comprehensive validation function tests |
docs/FACEBOOK_SETUP_QUICK.md |
New quick reference guide for Facebook setup process |
.gitignore |
Added WEBHOOK_INFO.txt to prevent sensitive webhook configuration from being committed |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VALID_VERIFY_TOKEN, | ||
| ] | ||
| setup() | ||
|
|
||
| webhook_file = tmp_path / "WEBHOOK_INFO.txt" |
There was a problem hiding this comment.
The validation accepts 15-17 digit Page IDs, but the tests only verify 15 and 17 digits. Consider adding a test case for 16 digits to ensure complete coverage of the regex range {15,17}.
| def _prompt_with_validation( | ||
| message: str, | ||
| validator: Callable[[str], bool], | ||
| error_message: str, | ||
| hide_input: bool = False, | ||
| max_attempts: int = 3, | ||
| ) -> str: | ||
| """Prompt user with input validation.""" | ||
| for attempt in range(max_attempts): | ||
| value = typer.prompt(message, hide_input=hide_input).strip() | ||
| if validator(value): | ||
| return value | ||
| typer.echo( | ||
| typer.style(f"❌ {error_message}", fg=typer.colors.RED), | ||
| err=True, | ||
| ) | ||
| if attempt < max_attempts - 1: | ||
| typer.echo(f" {max_attempts - attempt - 1} attempts remaining\n") | ||
| else: | ||
| typer.echo("❌ Maximum attempts reached. Exiting.") | ||
| raise typer.Exit(1) | ||
| return value # unreachable but satisfies type checker | ||
|
|
||
|
|
There was a problem hiding this comment.
The _prompt_with_validation function is defined but never used in the codebase. It appears to be superseded by _prompt_with_help. Consider removing this dead code to improve maintainability.
| def _prompt_with_validation( | |
| message: str, | |
| validator: Callable[[str], bool], | |
| error_message: str, | |
| hide_input: bool = False, | |
| max_attempts: int = 3, | |
| ) -> str: | |
| """Prompt user with input validation.""" | |
| for attempt in range(max_attempts): | |
| value = typer.prompt(message, hide_input=hide_input).strip() | |
| if validator(value): | |
| return value | |
| typer.echo( | |
| typer.style(f"❌ {error_message}", fg=typer.colors.RED), | |
| err=True, | |
| ) | |
| if attempt < max_attempts - 1: | |
| typer.echo(f" {max_attempts - attempt - 1} attempts remaining\n") | |
| else: | |
| typer.echo("❌ Maximum attempts reached. Exiting.") | |
| raise typer.Exit(1) | |
| return value # unreachable but satisfies type checker |
| typer.echo(" Option 1: Use the default we generate for you") | ||
| typer.echo(" Option 2: Type your own (e.g., 'my-bot-token-2024')") | ||
| typer.echo(" Option 3: Generate random in terminal:") | ||
| typer.echo(" openssl rand -base64 32") |
There was a problem hiding this comment.
The documentation suggests using openssl rand -base64 32 to generate a verify token, but this command produces base64-encoded strings containing /, +, and = characters, which will fail the validation regex that only allows [a-zA-Z0-9_-].
Consider changing the suggestion to:
openssl rand -hex 16(produces 32 hex characters)- Or document that base64 output needs to be sanitized
| typer.echo(" openssl rand -base64 32") | |
| typer.echo(" openssl rand -hex 16 # 32 hex chars, regex-safe") |
| ) -> str: | ||
| """Prompt with optional help dialog (type '?' for detailed help).""" | ||
| if credential_type == "page_id": | ||
| typer.echo("💡 Tip: Page ID is a 15-digit number") |
There was a problem hiding this comment.
Inconsistency: The tip says "Page ID is a 15-digit number" but the validation regex ^\d{15,17}$ accepts 15-17 digits. While this may be intentional to handle different Facebook Page ID formats, the documentation should clarify that Page IDs can be 15-17 digits to avoid user confusion.
| typer.echo("💡 Tip: Page ID is a 15-digit number") | |
| typer.echo("💡 Tip: Page ID is a 15–17 digit number") |
| typer.echo(" Format: EAAA... (very long)") | ||
| typer.echo("") | ||
| typer.echo(" 3. Verify Token: Any string you create (save it!)") | ||
| typer.echo(" Tip: Use 'openssl rand -base64 32' to generate") |
There was a problem hiding this comment.
Same suggestion issue as in the help dialog: openssl rand -base64 32 produces characters that will fail validation. Consider suggesting openssl rand -hex 16 instead, which produces 32 alphanumeric characters that will pass validation.
| typer.echo(" Tip: Use 'openssl rand -base64 32' to generate") | |
| typer.echo(" Tip: Use 'openssl rand -hex 16' to generate") |
| def _validate_verify_token(token: str) -> bool: | ||
| """Validate verify token format.""" | ||
| token = token.strip() | ||
| return bool(re.match(r"^[a-zA-Z0-9_-]{8,100}$", token)) |
There was a problem hiding this comment.
The suggested command openssl rand -base64 32 will generate tokens containing characters like /, +, and = that are not allowed by the validation regex ^[a-zA-Z0-9_-]{8,100}$. This will cause user confusion when they follow the documentation but their token is rejected.
Consider either:
- Updating the validation regex to accept base64 characters:
^[a-zA-Z0-9_+/=-]{8,100}$ - Changing the suggestion to use a URL-safe base64 variant:
openssl rand -base64 32 | tr '+/' '-_' | tr -d '=' - Changing the suggestion to use hex encoding:
openssl rand -hex 16
| return bool(re.match(r"^[a-zA-Z0-9_-]{8,100}$", token)) | |
| return bool(re.match(r"^[a-zA-Z0-9_+/=-]{8,100}$", token)) |
| typer.echo("") | ||
| typer.echo("📌 Quick Reference:") | ||
| typer.echo(" 1. Page ID: Find in Messenger Settings → Access Tokens dropdown") | ||
| typer.echo(" Format: 123456789012345 (15 digits)") |
There was a problem hiding this comment.
Same inconsistency: The message says "15 digits" but the validation accepts 15-17 digits. Consider updating to say "15-17 digits" to match the actual validation.
| ).hexdigest()[:12] | ||
|
|
||
| page_id = _prompt_with_help( | ||
| "🎯 Facebook Page ID (15-digit number)", |
There was a problem hiding this comment.
The prompt message says "15-digit number" but the validation accepts 15-17 digits. This inconsistency appears throughout the code. Consider updating to "(15-17 digit number)" to match the actual validation and accommodate different Facebook Page ID formats.
|
|
||
| ### 5. Create Verify Token (1 min) | ||
|
|
||
| - Use: `openssl rand -base64 32` |
There was a problem hiding this comment.
The suggested command openssl rand -base64 32 will generate tokens with /, +, and = characters that fail the validation regex in setup_cli.py which only accepts [a-zA-Z0-9_-]. Consider changing to openssl rand -hex 16 which produces 32 hex characters that will pass validation.
| - Use: `openssl rand -base64 32` | |
| - Use: `openssl rand -hex 16` |
| Paste when prompted: | ||
|
|
||
| - Website URL | ||
| - Page ID (15 digits) |
There was a problem hiding this comment.
The documentation says "Page ID (15 digits)" but the validation accepts 15-17 digits. For consistency, update to "(15-17 digits)" to match the actual validation.
| - Page ID (15 digits) | |
| - Page ID (15-17 digits) |
99fa9c2 to
7c155a8
Compare

TL;DR
Enhanced Facebook setup experience with improved credential validation, detailed help guides, and better error handling.
What changed?
FACEBOOK_SETUP_QUICK.mdquick reference guide for Facebook setup?for detailed instructions)WEBHOOK_INFO.txtHow to test?
?at any credential promptWEBHOOK_INFO.txtis createdWhy make this change?
Users were struggling with Facebook setup, particularly finding and entering the correct credentials. This change makes the process more user-friendly by: