Skip to content

Commit 0c6be86

Browse files
chore(function): remove unauthenticated feishu bridge route (#57792)
Co-authored-by: vimtor <[email protected]>
1 parent b2f83b5 commit 0c6be86

3 files changed

Lines changed: 1 addition & 83 deletions

File tree

‎infra/app.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,12 @@ const GITHUB_APP_ID = new sst.Secret("GITHUB_APP_ID")
44
const GITHUB_APP_PRIVATE_KEY = new sst.Secret("GITHUB_APP_PRIVATE_KEY")
55
export const EMAILOCTOPUS_API_KEY = new sst.Secret("EMAILOCTOPUS_API_KEY")
66
const ADMIN_SECRET = new sst.Secret("ADMIN_SECRET")
7-
const DISCORD_SUPPORT_BOT_TOKEN = new sst.Secret("DISCORD_SUPPORT_BOT_TOKEN")
8-
const DISCORD_SUPPORT_CHANNEL_ID = new sst.Secret("DISCORD_SUPPORT_CHANNEL_ID")
9-
const FEISHU_APP_ID = new sst.Secret("FEISHU_APP_ID")
10-
const FEISHU_APP_SECRET = new sst.Secret("FEISHU_APP_SECRET")
117

128
export const api = new sst.cloudflare.Worker("Api", {
139
domain: `api.${domain}`,
1410
handler: "packages/function/src/api.ts",
1511
url: true,
16-
link: [
17-
GITHUB_APP_ID,
18-
GITHUB_APP_PRIVATE_KEY,
19-
ADMIN_SECRET,
20-
DISCORD_SUPPORT_BOT_TOKEN,
21-
DISCORD_SUPPORT_CHANNEL_ID,
22-
FEISHU_APP_ID,
23-
FEISHU_APP_SECRET,
24-
],
12+
link: [GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY, ADMIN_SECRET],
2513
transform: {
2614
worker: (args) => {
2715
args.logpush = true

‎packages/function/src/api.ts‎

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,6 @@ import { parseRepositoryClaim } from "./github"
77

88
export default new Hono()
99
.get("/", (c) => c.text("Hello, world!"))
10-
.post("/feishu", async (c) => {
11-
const body = (await c.req.json()) as {
12-
challenge?: string
13-
event?: {
14-
message?: {
15-
message_id?: string
16-
root_id?: string
17-
parent_id?: string
18-
chat_id?: string
19-
content?: string
20-
}
21-
}
22-
}
23-
console.log(JSON.stringify(body, null, 2))
24-
const challenge = body.challenge
25-
if (challenge) return c.json({ challenge })
26-
27-
const content = body.event?.message?.content
28-
const parsed =
29-
typeof content === "string" && content.trim().startsWith("{")
30-
? (JSON.parse(content) as {
31-
text?: string
32-
})
33-
: undefined
34-
const text = typeof parsed?.text === "string" ? parsed.text : typeof content === "string" ? content : ""
35-
36-
let message = text.trim().replace(/^@_user_\d+\s*/, "")
37-
message = message.replace(/^aiden,?\s*/i, "<@759257817772851260> ")
38-
if (!message) return c.json({ ok: true })
39-
40-
const threadId = body.event?.message?.root_id || body.event?.message?.message_id
41-
if (threadId) message = `${message} [${threadId}]`
42-
43-
const response = await fetch(
44-
`https://discord.com/api/v10/channels/${Resource.DISCORD_SUPPORT_CHANNEL_ID.value}/messages`,
45-
{
46-
method: "POST",
47-
headers: {
48-
"Content-Type": "application/json",
49-
Authorization: `Bot ${Resource.DISCORD_SUPPORT_BOT_TOKEN.value}`,
50-
},
51-
body: JSON.stringify({
52-
content: `${message}`,
53-
}),
54-
},
55-
)
56-
57-
if (!response.ok) {
58-
console.error(await response.text())
59-
return c.json({ error: "Discord bot message failed" }, { status: 502 })
60-
}
61-
62-
return c.json({ ok: true })
63-
})
6410
/**
6511
* Used by the GitHub action to get GitHub installation access token given the OIDC token
6612
*/

‎sst-env.d.ts‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,10 @@ declare module "sst" {
2323
"type": "sst.cloudflare.SolidStart"
2424
"url": string
2525
}
26-
"DISCORD_SUPPORT_BOT_TOKEN": {
27-
"type": "sst.sst.Secret"
28-
"value": string
29-
}
30-
"DISCORD_SUPPORT_CHANNEL_ID": {
31-
"type": "sst.sst.Secret"
32-
"value": string
33-
}
3426
"EMAILOCTOPUS_API_KEY": {
3527
"type": "sst.sst.Secret"
3628
"value": string
3729
}
38-
"FEISHU_APP_ID": {
39-
"type": "sst.sst.Secret"
40-
"value": string
41-
}
42-
"FEISHU_APP_SECRET": {
43-
"type": "sst.sst.Secret"
44-
"value": string
45-
}
4630
"GITHUB_APP_ID": {
4731
"type": "sst.sst.Secret"
4832
"value": string

0 commit comments

Comments
 (0)