Skip to content

How to monitor an inbox for support tickets

Most support ticket systems start the same way: an email arrives in a shared inbox, someone reads it, decides where it should go, and forwards it along. That manual step is the bottleneck. It delays response times, leads to misrouted tickets, and breaks down entirely outside of business hours.

You can eliminate that bottleneck by combining the Nylas Email API with webhooks. Instead of polling an inbox on a timer, Nylas pushes a notification to your server the moment a new message lands. Your code inspects the message, applies routing rules, and hands it off to whatever system handles tickets on your end. The same code works across Google, Microsoft, and IMAP accounts without any provider-specific logic.

This tutorial walks through building a webhook handler that:

  • Receives message.created notifications from Nylas in real time
  • Verifies the webhook signature to confirm the notification is authentic
  • Fetches the full message content from the Nylas API
  • Categorizes the message based on subject keywords, sender domain, and body content
  • Assigns a priority level (high, medium, or low)
  • Routes the categorized ticket to the appropriate handler

The examples use Node.js with Express and Python with Flask. The routing logic is intentionally simple so you can adapt it to your own ticketing system, whether that’s Jira, Zendesk, a database, or a Slack channel.

Make sure you have the following before starting this tutorial:

  • A Nylas account with an active application
  • A valid API key from your Nylas Dashboard
  • At least one connected grant (an authenticated user account) for the provider you want to work with
  • Node.js 18+ or Python 3.8+ installed (depending on which code samples you follow)

New to Nylas? Start with the quickstart guide to set up your app and connect a test account before continuing here.

You also need:

  • A publicly accessible HTTPS endpoint for Nylas to send webhook notifications to. During development, use VS Code port forwarding or Hookdeck to expose your local server.
  • Express (Node.js) or Flask (Python) installed in your project.

Nylas blocks requests to Ngrok URLs because of throughput limiting concerns. Use VS Code port forwarding or Hookdeck instead.

Create a webhook subscription that listens for the message.created trigger. This tells Nylas to send a POST request to your endpoint every time a new message arrives in any connected grant.

Replace <NYLAS_API_KEY> with your API key from the Nylas Dashboard and <YOUR_WEBHOOK_URL> with the public HTTPS URL where your server is listening.

Nylas returns the webhook object with a webhook_secret. Save this value. You need it to verify incoming notifications.

The moment you create the webhook (or reactivate one), Nylas sends a GET request to your endpoint with a challenge query parameter. Your server must return the exact value of that parameter in a 200 response within 10 seconds. If it doesn’t, the webhook stays inactive and Nylas won’t retry.

# Nylas sends something like this:
GET <YOUR_WEBHOOK_URL>?challenge=bc609b38-c81f-47fb-a275-1d9bd61a968b

Your server returns:

200 OK
bc609b38-c81f-47fb-a275-1d9bd61a968b

No JSON wrapping, no extra whitespace, no chunked encoding. Just the raw challenge string in the response body.

Once the webhook is active, Nylas sends a POST request to your endpoint for every new message. The payload includes the message object (or a truncated version if it exceeds 1 MB). Your handler needs to do three things: verify the signature, parse the notification, and fetch the full message if needed.

Respond with 200 before doing heavy processing. If your handler takes too long, Nylas considers the delivery failed and retries. Acknowledge the webhook immediately, then process the message asynchronously.

Now that you have the full message, you can inspect its content and decide where it should go. The processMessage function below checks the subject line and body for keywords, looks up the sender’s domain, and assigns a category and priority.

KeywordsCategoryDefault priority
urgent, down, outage, critical, brokenIncidentsHigh
bug, error, crash, not working, issueBugsMedium
billing, invoice, charge, refund, paymentBillingMedium
feature, request, suggestion, would be niceFeature requestsLow
cancel, unsubscribe, close accountChurn riskHigh

Not every incoming message is a real support request. Auto-replies, out-of-office messages, and delivery failure notifications should be filtered out before your routing logic runs.

A production-ready webhook handler needs to deal with several real-world scenarios that don’t show up during development.

Nylas guarantees at-least-once delivery. That means your endpoint might receive the same notification more than once, especially if your server was slow to respond the first time. Track processed message IDs and skip duplicates:

An in-memory Set works for development but won’t survive a server restart. In production, store processed message IDs in Redis with a TTL (24 hours is usually enough) or in your database.

When a message exceeds 1 MB (common with large attachments or rich HTML), Nylas sends a message.created.truncated notification with the body removed. The handler code above already covers this: check the trigger type for .truncated or check whether the body field is missing, then fetch the full message from the API.

You don’t need to subscribe to a separate message.created.truncated trigger. Nylas sends it automatically on the same webhook subscription.

If your inbox receives a burst of messages, your handler will fire multiple fetch calls to the Nylas API in quick succession. Respect the rate limits by adding a simple queue or delay:

Beyond auto-replies, consider filtering out:

  • Calendar invitations that generate email notifications
  • Messages from your own application (check if the sender matches your support address to avoid infinite loops)
  • Messages in Sent or Drafts folders that trigger message.created when synced

You can check the folder by looking at the folders array on the message object. If it contains SENT or DRAFTS, skip processing.

You have two options for testing without waiting for real email to arrive.

Option 1: Use the Nylas Send Test Event endpoint

Section titled “Option 1: Use the Nylas Send Test Event endpoint”

Nylas provides a Send Test Event endpoint that sends a mock message.created payload to your webhook URL. This confirms your endpoint is reachable and your signature verification works:

Send an email to the inbox connected to your Nylas grant with a subject like “Urgent: Production database is down” or “Billing question about last invoice.” Watch your server logs to confirm the webhook fires, the message gets categorized correctly, and the routing logic triggers.

Start with Option 1 to verify the plumbing works, then move to Option 2 to validate your categorization rules against real email content.

You now have a working support ticket monitor that listens for new messages, categorizes them, and routes them to the right team. From here, you can extend the system in several directions:

  • Review all webhook triggers. The webhook notification schemas reference covers every trigger type Nylas supports, including message.updated for tracking status changes.
  • Send auto-replies. Use the Send email endpoint to acknowledge support requests automatically, so customers know their ticket was received.
  • Organize processed messages. Use the Folders and labels API to move processed messages into dedicated folders like “Triaged” or “In Progress.”
  • Track support responses. Enable message tracking on outgoing replies to know when a customer reads your response.