From e48b5af0296e11c2b1eab7f1ceb0ba003d4b36ae Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Tue, 2 May 2023 15:31:20 +0800 Subject: [PATCH] refactor: key --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index faab940..0c55b39 100644 --- a/src/index.ts +++ b/src/index.ts @@ -71,16 +71,17 @@ async function processUpdate(update: Update): Promise { chatId, messageThreadId: update.message.message_thread_id, }; - const key = `chat-webhook:${JSON.stringify(chat)}`; + const chatKey = JSON.stringify(chat); + const key = `chat-webhook:${chatKey}`; const result = await TG_GROUPS.get(key); let webhookUrl: string; if (result == null) { const uuid = crypto.randomUUID(); await TG_GROUPS.put(key, uuid); - await TG_GROUPS.put(`webhook-chat:${uuid}`, JSON.stringify(chat)); + await TG_GROUPS.put(`webhook-chat:${uuid}`, chatKey); webhookUrl = `${WEBHOOK_PREFIX}/t/${uuid}`; } else { - await TG_GROUPS.put(`webhook-chat:${result}`, JSON.stringify(chat)); + await TG_GROUPS.put(`webhook-chat:${result}`, chatKey); webhookUrl = `${WEBHOOK_PREFIX}/t/${result}`; } await sendToChat(