waitForPattern method

Future<Context?> waitForPattern({
  1. required ID chatId,
  2. required Pattern pattern,
  3. Duration? timeout,
  4. bool clearUnfulfilled = true,
})

Wait for pattern from the user.

Possibly returns null if the listener has been cancelled before it completes. Otherwise, returns a Context object with the incoming update.

Implementation

Future<Context?> waitForPattern({
  required ID chatId,
  required Pattern pattern,
  Duration? timeout,
  bool clearUnfulfilled = true,
}) async {
  return await waitFor(
    chatId: chatId,
    timeout: timeout,
    clearUnfulfilled: clearUnfulfilled,
    filter: (up) {
      if (pattern is String) {
        return up.msg?.text?.contains(pattern) == true;
      } else if (pattern is RegExp) {
        return pattern.hasMatch(up.msg?.text ?? "");
      } else {
        return false;
      }
    },
  );
}