Skip to content
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

Handle long requests gracefully #395

Open
MrOrz opened this issue Jul 6, 2024 · 0 comments · May be fixed by #401
Open

Handle long requests gracefully #395

MrOrz opened this issue Jul 6, 2024 · 0 comments · May be fixed by #401
Assignees

Comments

@MrOrz
Copy link
Member

MrOrz commented Jul 6, 2024

From 20240701 meeting note

As-is

LINE reply token is not guaranteed to work beyond 1 minute after the webhook event is received (Official doc).

Currently when a query takes more than 58 seconds to finish, the bot will reply with "Line bot is busy, or we cannot handle this message." error.

This timeout mechanism is implemented in singleUserHandler. When a webhook event takes more than REPLY_TIMEOUT to finish, it will consume the reply token to send the reply above and flip a toggle isRepliedDueToTimeout to stop future send() calls to send reply again. This is

However, as we starts to support multiple multimedia messages, it is easy for a query to be minutes long, due to the fact that we need to transcribe it first.

To-be

We would like to support a new reply token management mechanism that would tell the user about the current status, and use quick reply to collect new reply tokens.

The UX would be something like this (Figma):

image

  • UX#1: Set expectation of waiting
  • UX#2: Timeout management
  • UX#3: Progress report

Technical-wise, we will modify singleUserHandler to remove the existing isRepliedDueToTimeout flag. Instead, we will do the following for UX#2 timeout management:

  1. Store latest reply token and its received time in context
  2. Just before the 1 minute timeout, we send the message with quick reply to collect reply token. This "message with token-collecting quick reply" can be wrapped as a utility function sendReplyTokenCollector(ctx: Context, message: string). It consumes the current reply token (which will be outdated very soon) and hope that the user would click the quick reply, which provides us a new reply token.
    • If the token has already been outdated (maybe because the user did not click the last quick reply), this method does nothing. User may still click the latest quick reply in this case.
  3. In send() we consume reply token in context if the reply token does not timeout.
    • Otherwise, we use push message to push the reply to the user.
      image

Then for UX#1 and UX#3, we pass sendReplyTokenCollector to handler function so that they can call the method before a long query call (UX#1). sendReplyTokenCollector can be called multiple times as a method to report current status to the user (UX#3).

@MrOrz MrOrz self-assigned this Jan 28, 2025
@MrOrz MrOrz linked a pull request Jan 30, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant