Sweep stale Zoho Desk tickets into Slack every weekday

By General Input

Every weekday morning, find the Zoho Desk tickets nobody has touched in three days, post them to Slack grouped by owner, and log each one to a spreadsheet.

Integrations

  • Zoho Desk
  • Slack Bot
  • Google Sheets

Type

Deterministic Code

Categories

  • Customer Support
  • Operations

Every weekday at 8am, sweep my Zoho Desk helpdesk for tickets that have gone stale and report them in one place so nothing sits forgotten. Run this on a cron schedule, Monday through Friday at 8am in my timezone.

Start by fetching open tickets from Zoho Desk using List Tickets. Two things about this API to handle properly. First, every Zoho Desk endpoint except the organizations lookup requires the orgId header, so resolve the organization id once at the start and send it on every call. Second, the list endpoints are offset paginated with a from parameter and a limit parameter, the limit maxes out at 50 on most list endpoints, and an empty result comes back as HTTP 204 with no body rather than an empty array. So page through with from and limit and keep going until a page returns fewer records than the limit or returns a 204. Do not assume one page is the whole queue.

Filter those tickets down to the stale ones: keep only tickets whose most recent modified time is three or more days before the moment the sweep runs. For each survivor, compute the age as a whole number of days since that last update, because I want that number shown in both outputs.

Resolve the owners. Call List Agents once, page it the same way, and build a lookup from agent id to agent name. Then map each stale ticket's assignee id to a readable agent name through that lookup. Do not make a separate agent call per ticket. Any ticket with no assignee id is treated as unassigned.

Group the stale tickets by assigned agent and send one Slack message with Send a Message to the support channel. The message leads with the total count of stale tickets across the whole sweep. Then the unassigned tickets come first under their own clear heading, since tickets with no owner are usually the worst offenders, followed by one section per agent under that agent's name. Under each heading, list that group's tickets with the ticket number, the subject, the age in days since the last update, and a link to the ticket using the ticket's web URL from the Zoho Desk record. Slack uses mrkdwn rather than standard Markdown, so links are formatted as <url|text> and bold is single asterisks. Keep it one message, not one per agent. If no tickets are stale, send a short all clear message instead so the team knows the sweep ran.

Then append the same findings to a Google Sheets tracker using Append Values, one row per stale ticket, capturing the run date, the ticket number, the subject, the assignee name or Unassigned, the days since last update, and the ticket status. Append rather than overwrite so the sheet accumulates a running history the team can look back over to spot patterns in what goes stale. On an all clear day, skip the append entirely rather than writing an empty row.

Two things I will want to tune, so make them obvious named constants near the top of the code rather than values buried in the logic: the three day staleness threshold, and the 8am weekday schedule.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentLocal listing health board for every location you manageLet support send one-off Loops emails without an engineerA brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensStop cold emails to anyone with a live deal in PipedriveLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasoniMessage campaign console with pre-flight checks and delivery board