Skip to content

Commit

Permalink
feat: profile options
Browse files Browse the repository at this point in the history
  • Loading branch information
shayypy committed Dec 31, 2023
1 parent 5a78016 commit e3e2233
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Simply replace `media.guilded.gg` in your webhook URL with `guilded.shayy.worker

Guilded sent errors about unknown event types through as a message, but this proxy does not. If you want to see everything without errors in your chat channel, just enable "Send me everything" (although you may want to disable `star` and `watch` for particularly large repositories).

### Custom profiles

Guilded forced a webhook name of GitHub and avatar of the GitHub logo, but this can be disabled in GWP by passing `profile=none` as a query parameter. This will cause the messages to use the default name & avatar configured in Guilded settings. To customize even further, pass `username=xxx` and/or `avatarUrl=yyy`, where `xxx` is a URL-encoded string up to 128 characters, and `yyy` is a URL-encoded image URL for the profile picture. This is particularly useful if you want to use the same webhook for multiple repositories or organizations. This will be ignored for applicable [immersive mode](#immersive-discussion) messages.

### Immersive discussion

Pass `immersive=chat` at the end of the webhook URL to enable immersive discussion mode. This feature makes use of custom profiles to make it appear like GitHub users are chatting in your webhook channel. To display user messages with embeds (different sub/superset of markdown), use `immersive=embeds` instead.
Expand Down
29 changes: 23 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,21 @@ router
const search = new URL(request.url).searchParams;
const showReactions = search.get("reactions") !== "false",
showDrafts = search.get("drafts") === "true",
immersiveRaw = search.get("immersive");
immersiveRaw = search.get("immersive"),
forceProfile = search.get("profile") !== "none",
profileUsername = search.get("username"),
profileAvatarUrl = search.get("avatarUrl");

if (profileUsername && profileUsername.length > 128) {
return json({ code: "ProxyBadUsername", message: "Username is too long." }, { status: 400 });
}
if (profileAvatarUrl) {
try {
new URL(profileAvatarUrl);
} catch {
return json({ code: "ProxyBadAvatar", message: "Avatar URL must be a valid URL." }, { status: 400 });
}
}

const immersiveMode = ["chat", "embeds"].includes(immersiveRaw || "")
? immersiveRaw as "chat" | "embeds"
Expand Down Expand Up @@ -404,11 +418,14 @@ router
embeds?: APIEmbed[];
username?: string;
avatar_url?: string;
} = {
embeds,
username: "GitHub",
avatar_url: "https://cdn.gilcdn.com/UserAvatar/3f8e4273b8b9dcacd57379a637a773f4-Large.png",
};
} = { embeds };

if (forceProfile) {
payload.username = "GitHub";
payload.avatar_url = "https://cdn.gilcdn.com/UserAvatar/3f8e4273b8b9dcacd57379a637a773f4-Large.png";
}
if (profileUsername) payload.username = profileUsername;
if (profileAvatarUrl) payload.avatar_url = profileAvatarUrl;

if (immersiveMode && immContent !== undefined) {
immContent = immContent
Expand Down

0 comments on commit e3e2233

Please sign in to comment.