Skip to main content
Glama

notify_tenant

Send WhatsApp notifications to tenants about maintenance ticket updates using predefined templates or custom messages, with SMS fallback if needed.

Instructions

Sends a WhatsApp message to the tenant associated with a ticket. Supports five message templates: acknowledgement, scheduled, update, resolved, delay. Pass customMessage to override the template. Falls back to SMS if WhatsApp fails. Logs the notification to n8n and appends to ticket internal notes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ticketIdYesThe ID of the ticket whose tenant should be notified.
messageTypeYesTemplate to use: acknowledgement — ticket received, being reviewed scheduled — repair booked, include scheduledFor date update — general progress note resolved — work complete delay — work delayed, reason explained
customMessageNoOptional custom message body. When provided, overrides the built-in template. Useful for specific instructions or unusual situations.
scheduledForNoISO 8601 datetime — required when messageType is 'scheduled'. The template will format this into a human-readable date/time for the tenant.

Implementation Reference

  • The main handler function that executes the notify_tenant tool logic - retrieves ticket from store, validates input, builds message using template, sends via WhatsApp/SMS, logs to n8n webhook, and appends to ticket notes
    export async function handleNotifyTenant(
      input: NotifyTenantInput
    ): Promise<NotifyTenantOutput> {
      const ticket = ticketStore.getById(input.ticketId);
    
      if (!ticket) {
        throw new Error(`Ticket not found: ${input.ticketId}`);
      }
    
      if (input.messageType === "scheduled" && !input.scheduledFor && !ticket.scheduledFor) {
        throw new Error(
          'messageType "scheduled" requires a scheduledFor datetime. ' +
          "Provide it in the tool input or update the ticket status first with a scheduledFor value."
        );
      }
    
      const scheduledFor = input.scheduledFor ?? ticket.scheduledFor;
    
      const body = buildTenantMessage(
        input.messageType,
        ticket.tenant.name,
        ticket.title,
        input.customMessage,
        scheduledFor
      );
    
      const result = await sendWhatsApp(ticket.tenant.phone, body);
    
      // Log to n8n asynchronously
      triggerMaintenanceWebhook({
        eventType: "tenant_notified",
        ticketId: ticket.id,
        ticketTitle: ticket.title,
        tenantName: ticket.tenant.name,
        tenantPhone: ticket.tenant.phone,
        messageType: input.messageType,
        messageBody: body,
        channel: result.channel,
        messageSid: result.messageSid,
        timestamp: result.timestamp,
      }).catch((err) =>
        console.error("[notify_tenant] n8n webhook error:", err)
      );
    
      // Append to internal notes
      ticketStore.appendNote(
        input.ticketId,
        `[${result.timestamp}] Tenant notified (${input.messageType}) via ${result.channel}. ` +
        `SID: ${result.messageSid ?? "N/A"}`
      );
    
      return result;
    }
  • Input schema definition using Zod - defines ticketId, messageType enum (acknowledgement/scheduled/update/resolved/delay), optional customMessage, and optional scheduledFor datetime
    export const NotifyTenantSchema = z.object({
      ticketId: z.string().describe("The ID of the ticket whose tenant should be notified."),
      messageType: z
        .enum(["acknowledgement", "scheduled", "update", "resolved", "delay"])
        .describe(
          "Template to use:\n" +
          "  acknowledgement — ticket received, being reviewed\n" +
          "  scheduled — repair booked, include scheduledFor date\n" +
          "  update — general progress note\n" +
          "  resolved — work complete\n" +
          "  delay — work delayed, reason explained"
        ),
      customMessage: z
        .string()
        .optional()
        .describe(
          "Optional custom message body. When provided, overrides the built-in template. " +
          "Useful for specific instructions or unusual situations."
        ),
      scheduledFor: z
        .string()
        .optional()
        .describe(
          "ISO 8601 datetime — required when messageType is 'scheduled'. " +
          "The template will format this into a human-readable date/time for the tenant."
        ),
    });
    
    export type NotifyTenantInput = z.infer<typeof NotifyTenantSchema>;
  • MCP server tool registration - registers 'notify_tenant' tool with description, schema, and async handler that calls handleNotifyTenant and returns JSON result
    server.tool(
      "notify_tenant",
      "Sends a WhatsApp message to the tenant associated with a ticket. " +
      "Supports five message templates: acknowledgement, scheduled, update, resolved, delay. " +
      "Pass customMessage to override the template. Falls back to SMS if WhatsApp fails. " +
      "Logs the notification to n8n and appends to ticket internal notes.",
      NotifyTenantSchema.shape,
      async (input) => {
        const result = await handleNotifyTenant(input);
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      }
    );
  • Message template builder function - creates formatted WhatsApp messages based on message type (acknowledgement, scheduled, update, resolved, delay) with tenant name, ticket title, and scheduled time
    export function buildTenantMessage(
      messageType: string,
      tenantName: string,
      ticketTitle: string,
      customMessage?: string,
      scheduledFor?: string
    ): string {
      const firstName = tenantName.split(" ")[0];
    
      if (customMessage) return customMessage;
    
      const formattedTime = scheduledFor
        ? new Date(scheduledFor).toLocaleString("en-US", {
            weekday: "long",
            month: "short",
            day: "numeric",
            hour: "numeric",
            minute: "2-digit",
            hour12: true,
          })
        : "soon";
    
      const templates: Record<string, string> = {
        acknowledgement:
          `Hi ${firstName}! 👋 We've received your maintenance request: *"${ticketTitle}"*. ` +
          `Our team is reviewing it now and will be in touch shortly with next steps. ` +
          `Reply STOP to unsubscribe from updates.`,
    
        scheduled:
          `Hi ${firstName}! Great news — your maintenance request *"${ticketTitle}"* has been scheduled. ` +
          `A technician will visit on *${formattedTime}*. ` +
          `Please ensure someone is home to provide access. Reply if you need to reschedule.`,
    
        update:
          `Hi ${firstName}! Quick update on your request *"${ticketTitle}"*: ` +
          `our team is actively working on it. We'll notify you once it's resolved.`,
    
        resolved:
          `Hi ${firstName}! ✅ Your maintenance request *"${ticketTitle}"* has been resolved. ` +
          `Please let us know if the issue persists or if you have any concerns. ` +
          `Thank you for your patience!`,
    
        delay:
          `Hi ${firstName}, we want to keep you informed — there's been a short delay with ` +
          `your request *"${ticketTitle}"*. We're working to reschedule as soon as possible ` +
          `and will confirm the new time shortly. Apologies for the inconvenience.`,
      };
    
      return templates[messageType] ?? templates["update"];
    }
  • Output type definition - defines NotifyTenantOutput interface with success boolean, channel type (whatsapp/sms/simulated), messageSid, to, body, and timestamp fields
    export interface NotifyTenantOutput {
      success: boolean;
      channel: "whatsapp" | "sms" | "simulated";
      messageSid?: string;
      to: string;
      body: string;
      timestamp: string;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it specifies the five message templates, fallback to SMS, and side effects (logs to n8n and appends to ticket internal notes). However, it doesn't mention potential rate limits, authentication needs, or error handling details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in three sentences: the first states the core action and templates, the second explains parameter behavior, and the third covers fallback and side effects. Every sentence adds essential information with zero wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description provides strong context about behavior, parameters, and side effects. It could be more complete by detailing the exact format of logged messages or clarifying error responses, but it covers the essential operational aspects well given the complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing detailed parameter documentation. The description adds some value by explaining the purpose of customMessage ('overrides the built-in template') and listing the five template types, but doesn't significantly enhance the schema's already comprehensive parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Sends a WhatsApp message') and target resource ('to the tenant associated with a ticket'), distinguishing it from sibling tools like escalate_to_vendor or update_maintenance_status by focusing on tenant communication rather than vendor escalation or status updates.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (sending notifications to tenants about ticket updates) and mentions fallback behavior (SMS if WhatsApp fails), but does not explicitly state when not to use it or directly compare it to alternatives like escalate_to_vendor for vendor-related communications.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/utkarsh-portfolio/MCPPropTech'

If you have feedback or need assistance with the MCP directory API, please join our Discord server