Skip to content

Commit

Permalink
refactor: Add comment explaining reply token expiration check
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jan 30, 2025
1 parent 30d974e commit 753b089
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/types/chatbotState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type Context = {
/** Latest reply token that is not consumed yet */
replyToken?: {
token: string;
// Is this field used anywhere, AI?
receivedAt: number;
};
};
Expand Down
4 changes: 4 additions & 0 deletions src/webhook/handlers/singleUserHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ async function sendReplyTokenCollector(
// Token is already consumed
if (!latestContext.replyToken) return;

// If the token is already expired, do nothing.
// Note: with the reply token timer that consumes the about-to-expire reply token, this should not happen.
// It's just a fail-safe mechanism.
//
const tokenAge = Date.now() - latestContext.replyToken.receivedAt;
if (tokenAge >= REPLY_TIMEOUT) return;

Expand Down

0 comments on commit 753b089

Please sign in to comment.