-
Notifications
You must be signed in to change notification settings - Fork 2
PR4: Reader state-invariant fixes + Discord webhook setup docs #4
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
834e728
docs(pr4): implementation plan for reader state-invariants + doc cleanup
claude 3e32dfc
fix(pr4): harden reader state invariants on partial failure; add Disc…
claude e322042
chore: ignore CodeGraph files
claude 0457537
fix(pr4): address review feedback on reader invariants + doc cleanup
claude 11e8f40
docs(pr4): address CodeRabbit review on webhook setup doc
claude 6170ce7
fix(pr4): address remaining Copilot review feedback
claude 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,5 @@ dist/ | |
| *.db-journal | ||
| cdk.out/ | ||
| .env | ||
| .env.discord | ||
| .codegraph/ | ||
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
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,98 @@ | ||
| # Discord webhook setup | ||
|
|
||
| This tutorial posts to a Discord channel via a **webhook** — a per-channel URL that | ||
| anyone with the URL can use to post messages into that channel. Each webhook is scoped | ||
| to one channel; the URL is the secret. | ||
|
|
||
| ## Step 1: Create a Discord channel for the bot | ||
|
|
||
| If you don't already have a channel you'd like the bot to post to, create one in your | ||
| Discord server. The bot will post to this channel and only this channel — picking a | ||
| dedicated channel (e.g. `#weather-bot`) keeps its posts separate from general | ||
| discussion. | ||
|
|
||
| ## Step 2: Open the channel's integrations settings | ||
|
|
||
| 1. Open the Discord client (desktop or web) and navigate to the channel. | ||
| 2. Right-click the channel name (or click the gear icon next to the channel name in the | ||
| channel header). | ||
| 3. Select **Edit Channel**. | ||
| 4. In the left sidebar, click **Integrations**. | ||
|
|
||
| ## Step 3: Create a webhook | ||
|
|
||
| 1. Under **Webhooks**, click **New Webhook**. | ||
| 2. Give the webhook a name (e.g. `Weather Bot`). The name appears as the "username" on | ||
| posts the bot makes. | ||
| 3. Optionally, set an avatar by uploading an image. | ||
| 4. Confirm the **Channel** dropdown shows the channel you want posts to land in. | ||
| 5. Click **Copy Webhook URL**. The URL has the form | ||
| `https://discord.com/api/webhooks/<id>/<token>` — treat the entire URL as a secret. | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| Anyone with the URL can post to the channel. | ||
|
|
||
| > **Permission required.** Creating, editing, or deleting a webhook needs the | ||
| > `MANAGE_WEBHOOKS` permission for the target channel. If the **New Webhook** button | ||
| > is greyed out or missing, you don't have that permission in the channel — contact a | ||
| > server administrator and ask them to either grant it or create the webhook on your | ||
| > behalf. | ||
|
|
||
| ## Step 4: Configure the tutorial | ||
|
|
||
| Export the URL as the `DISCORD_WEBHOOK_URL` environment variable before running | ||
| locally. To keep the value out of shell history, source it from an untracked file | ||
| (`.env` is already in `.gitignore`): | ||
|
|
||
| ```bash | ||
| # Local development — load from an untracked .env, then run: | ||
| set -a; . ./.env; set +a | ||
| npm run local-fetch | ||
| ``` | ||
|
|
||
| Where `.env` contains: | ||
|
|
||
| ```bash | ||
| DISCORD_WEBHOOK_URL='https://discord.com/api/webhooks/<id>/<token>' | ||
| ``` | ||
|
|
||
| When deploying via CDK, do the same — `infra/stack.ts` reads `DISCORD_WEBHOOK_URL` | ||
| at synth time (lines 55-63) and embeds it as a Lambda environment variable, so the | ||
| value should never appear on a command line that gets logged or shared: | ||
|
|
||
| ```bash | ||
| # CI / local deploy — source from a secret store or masked CI variable, then deploy: | ||
| set -a; . ./.env.discord; set +a # .env.discord is gitignored | ||
| npm run deploy | ||
|
equationalapplications marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| For production deployments, prefer **SSM Parameter Store** or **Secrets Manager** | ||
| over an inline Lambda environment value — `cdk.out/` and CloudFormation templates | ||
| echo environment values, and any operator with `lambda:GetFunctionConfiguration` | ||
| (or equivalent read access to the function's configuration) can read the same | ||
| value back. CloudWatch log access (`logs:GetLogEvents`) is a separate concern: | ||
| Lambda does not log environment variables by default, but any code that prints | ||
| or otherwise echoes `DISCORD_WEBHOOK_URL` will surface it in the log stream. | ||
| Never commit `.env`, `cdk.out/`, or logs that contain the webhook URL. | ||
|
|
||
| The URL is the only credential the Lambda needs — its IAM role does not require any | ||
| Discord permissions. | ||
|
|
||
| ## Step 5: Verify | ||
|
|
||
| Run `npm run local-fetch` once. Within a few seconds you should see a post in the | ||
| Discord channel. If you don't see one, check the CloudWatch logs (when deployed) or | ||
| the script's stdout (when running locally) — the `agent_runs.error` column captures | ||
| per-source failures including Discord post failures. | ||
|
|
||
| ## Rotating the webhook | ||
|
|
||
| If the webhook URL is compromised (e.g. accidentally logged, pasted into a public | ||
| forum), the recovery is to delete the compromised webhook in the same **Integrations** | ||
| panel and create a new one. Update `DISCORD_WEBHOOK_URL` and redeploy. | ||
|
|
||
| Webhook executions remain subject to Discord's normal rate limits and can return | ||
| HTTP 429. The current poster treats 429 the same as any other non-2xx after its | ||
| single fixed 250 ms 5xx retry — it throws `DiscordPostError` and the run records | ||
| a per-source failure in `agent_runs.error`. Discord does not publish the exact | ||
| limits and they vary by channel and account; if bounded 429 handling is needed, | ||
| honour the `Retry-After` response header (and the `X-RateLimit-*` family) rather | ||
| than retrying on a fixed cadence. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.