-
Notifications
You must be signed in to change notification settings - Fork 0
feat: send Discord notifications for waitlist and new Google signups #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from datetime import UTC | ||
|
|
||
| import httpx | ||
|
|
||
| from app.models.waitlist import WaitlistEntry | ||
| from app.services.youtube import extract_video_id | ||
|
|
||
|
|
||
| def _build_youtube_thumbnail_url(youtube_url: str) -> str | None: | ||
| try: | ||
| video_id = extract_video_id(youtube_url) | ||
| except ValueError: | ||
| return None | ||
| return f"https://i.ytimg.com/vi/{video_id}/hqdefault.jpg" | ||
|
|
||
|
|
||
| def build_waitlist_signup_payload(entry: WaitlistEntry) -> dict: | ||
| timestamp = int(entry.created_at.astimezone(UTC).timestamp()) | ||
| embed = { | ||
| "title": f"{entry.name} joined the waitlist", | ||
| "description": f"[Open submitted video]({entry.youtube_url})", | ||
| "url": entry.youtube_url, | ||
| "color": 0x5865F2, | ||
| "fields": [ | ||
| {"name": "Email", "value": entry.email, "inline": True}, | ||
| {"name": "Source", "value": entry.source, "inline": True}, | ||
| { | ||
| "name": "Signed Up", | ||
| "value": f"<t:{timestamp}:F>\n<t:{timestamp}:R>", | ||
| "inline": False, | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| if entry.picture: | ||
| embed["thumbnail"] = {"url": entry.picture} | ||
|
|
||
| youtube_thumbnail_url = _build_youtube_thumbnail_url(entry.youtube_url) | ||
| if youtube_thumbnail_url: | ||
| embed["image"] = {"url": youtube_thumbnail_url} | ||
|
|
||
| return {"content": None, "embeds": [embed]} | ||
|
|
||
|
|
||
| def notify_waitlist_signup(entry: WaitlistEntry, webhook_url: str) -> None: | ||
| response = httpx.post( | ||
| webhook_url, | ||
| json=build_waitlist_signup_payload(entry), | ||
| timeout=5.0, | ||
| ) | ||
| response.raise_for_status() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from datetime import UTC, datetime | ||
|
|
||
| from app.models.waitlist import WaitlistEntry | ||
| from app.services.discord import build_waitlist_signup_payload | ||
|
|
||
|
|
||
| def test_build_waitlist_signup_payload_includes_user_and_video_context(): | ||
| entry = WaitlistEntry( | ||
| id=1, | ||
| user_id=7, | ||
| email="waitlist@example.com", | ||
| name="Waitlist User", | ||
| picture="https://example.com/profile.png", | ||
| youtube_url="https://www.youtube.com/watch?v=abc123XYZ00&t=1237s", | ||
| source="landing_early_access", | ||
| created_at=datetime(2026, 5, 13, 13, 6, 35, tzinfo=UTC), | ||
| ) | ||
|
|
||
| payload = build_waitlist_signup_payload(entry) | ||
|
|
||
| assert payload["content"] is None | ||
| embed = payload["embeds"][0] | ||
| assert embed["title"] == "Waitlist User joined the waitlist" | ||
| assert embed["description"] == "[Open submitted video](https://www.youtube.com/watch?v=abc123XYZ00&t=1237s)" | ||
| assert embed["url"] == "https://www.youtube.com/watch?v=abc123XYZ00&t=1237s" | ||
| assert embed["thumbnail"] == {"url": "https://example.com/profile.png"} | ||
| assert embed["image"] == {"url": "https://i.ytimg.com/vi/abc123XYZ00/hqdefault.jpg"} | ||
| assert embed["fields"] == [ | ||
| {"name": "Email", "value": "waitlist@example.com", "inline": True}, | ||
| {"name": "Source", "value": "landing_early_access", "inline": True}, | ||
| { | ||
| "name": "Signed Up", | ||
| "value": "<t:1778677595:F>\n<t:1778677595:R>", | ||
| "inline": False, | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| def test_build_waitlist_signup_payload_omits_images_when_not_available(): | ||
| entry = WaitlistEntry( | ||
| id=1, | ||
| user_id=7, | ||
| email="waitlist@example.com", | ||
| name="Waitlist User", | ||
| picture=None, | ||
| youtube_url="https://example.com/not-youtube", | ||
| source="landing_early_access", | ||
| created_at=datetime(2026, 5, 13, 13, 6, 35, tzinfo=UTC), | ||
| ) | ||
|
|
||
| payload = build_waitlist_signup_payload(entry) | ||
|
|
||
| embed = payload["embeds"][0] | ||
| assert "thumbnail" not in embed | ||
| assert "image" not in embed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entry.created_at.astimezone(UTC)produces incorrect epoch values whencreated_atis naive (common with SQLite and some DB/driver timezone settings), because Python assumes the host local timezone for naive datetimes. In non-UTC deployments this shifts the displayed Discord "Signed Up" time by the server offset, so notifications show wrong signup times even though the stored value represents UTC.Useful? React with 👍 / 👎.