telebot-ts API Documentation - v1.0.0
    Preparing search index...

    Class JobQueue

    Central scheduler for managing and executing background timers, intervals, and persistent jobs.

    Index
    bot: Bot

    The Bot client instance associated with this scheduler.

    errorHandler?: (error: Error, context: CallbackContext) => void | Promise<void>

    Optional centralized error handler callback delegate.

    isRunning: boolean = false

    Whether the job queue is currently active.

    • Internal

      Internal helper to remove a job from tracking and indexes.

      Parameters

      • job: Job

        Job instance to remove.

      Returns void

    • Finds all jobs associated with a specific chat ID in O(1) time complexity.

      Parameters

      • chat_id: string | number

        Telegram chat ID.

      Returns Job<unknown>[]

      Array of matching Job instances.

      const chatJobs = app.scheduler.getJobsByChatId(123456);
      
    • Finds all jobs matching a given name in O(1) time complexity.

      Parameters

      • name: string

        The job identifier name to filter by.

      Returns Job<unknown>[]

      Array of matching Job instances.

      const reminderJobs = app.scheduler.getJobsByName("daily_reminder");
      
    • Returns all active scheduled jobs currently managed by this queue.

      Returns Job<unknown>[]

      Array of active Job instances.

      const allJobs = app.scheduler.jobs();
      console.log(`Active jobs: ${allJobs.length}`);
    • Registers a named callback so persisted jobs can re-bind on application restart.

      Type Parameters

      • Data = unknown

      Parameters

      • name: string

        The job name.

      • callback: JobCallback<Data>

        The handler function.

      Returns void

    • Restores jobs from persistence using registered named callbacks.

      Parameters

      Returns void

    • Schedules a job to run daily at a specified time and optional days of the week.

      Type Parameters

      • Data = unknown

      Parameters

      • callback: JobCallback<Data>

        The async function to execute.

      • time: TimeOfDay

        Specific hour, minute, and second of execution.

      • days: number[] = ...

        Array of weekday numbers (0 = Sunday, 6 = Saturday) when the job runs.

      • Optionaldata: Data

        Optional custom data payload.

      • Optionalname: string

        Optional job name.

      • Optionalchat_id: string | number

        Optional associated chat ID.

      • Optionaluser_id: number

        Optional associated user ID.

      Returns Job<Data>

      The created daily recurring Job instance.

    • Schedules a one-off job to run after a specified duration or at a specific date.

      Type Parameters

      • Data = unknown

      Parameters

      • callback: JobCallback<Data>

        The async function to execute.

      • when: number | Date

        Number of seconds in the future or a Date object.

      • Optionaldata: Data

        Optional data payload passed to the job callback.

      • Optionalname: string

        Optional job name (defaults to anonymous identifier).

      • Optionalchat_id: string | number

        Optional associated chat ID.

      • Optionaluser_id: number

        Optional associated user ID.

      Returns Job<Data>

      The created Job instance.

    • Schedules a recurring job that executes repeatedly at a fixed interval.

      Type Parameters

      • Data = unknown

      Parameters

      • callback: JobCallback<Data>

        The async function to execute.

      • interval: number

        Interval in seconds between executions.

      • Optionalfirst: number | Date

        Optional delay (seconds) or Date before the first run.

      • Optionaldata: Data

        Optional custom data payload.

      • Optionalname: string

        Optional job name.

      • Optionalchat_id: string | number

        Optional associated chat ID.

      • Optionaluser_id: number

        Optional associated user ID.

      Returns Job<Data>

      The created recurring Job instance.

    • Schedules a job using an RFC 5545 Recurrence Rule (RRule) with full Timezone support.

      Type Parameters

      • Data = unknown

      Parameters

      Returns Job<Data> | null

      The created recurring Job instance, or null if the rule cannot generate future occurrences.

      // Run every Monday, Wednesday, Friday at 9:00 AM in Vietnam timezone:
      app.scheduler.runRRule(
      async (context) => {
      await context.bot.sendMessage({ chat_id: 123456, text: "Morning team update!" });
      },
      {
      rrule: "FREQ=WEEKLY;BYDAY=MO,WE,FR;BYHOUR=9;BYMINUTE=0",
      timezone: "Asia/Ho_Chi_Minh",
      }
      );
    • Starts the job queue and activates all scheduled jobs.

      Returns void

    • Stops the job queue and cancels all pending timeouts.

      Returns void