Request leave through AI chat

Workflow purpose

This guide demonstrates how to use Proto's AI agent to let staff request leave in a short chat – choosing the type of leave, seeing their balance, picking dates and arranging cover – instead of filling in a form or emailing their manager.

The workflow checks the balance and the dates against your HR system before anything is submitted, asks for a medical certificate when sick leave needs one, and sends the request to the HR system's own approval flow. Where there is no approval flow, it opens a ticket for the manager's team instead. Staff can also cancel or change a request they've already made.

It is part of the same employee AI agent as HR policy questions, so a person can ask how much leave they're entitled to and book it in the same chat.

Who can benefit from this guide:

  • HR teams in ministries, agencies and public bodies
  • Banks and digital finance providers with branch and call centre staff
  • Telecom operators with shop and field teams working shifts
  • Hospitals and health services planning leave around rotas
  • Managers who approve leave and want fewer emails

Request leave

This workflow checks a person's balance, validates their dates and submits a leave request for approval 24/7. See how to build a leave request workflow.

Just starting with the platform?
For initial setup of your AI agent – including workspace setup, agent training, and channel deployment – please start here. This workflow guide assumes your AI agent is set up and ready for more advanced configurations.

1. Create a trigger

Start the flow when a staff member wants to book, cancel or change leave.

  • Navigate to the Workflows tab in the AI agent settings.
  • Click New workflow and select Message received as the Workflow type.
  • Name the trigger (e.g. “Leave Request”) and add a short description (e.g. “Triggers if a member of staff wants to book, apply for, request, cancel or change annual leave, sick leave or any other time off. Not for general questions about leave policy.”).
  • Add training phrases (e.g. “I want to book leave”, “Can I take next Friday off?”, “Apply for sick leave”, “I need two weeks off in December”).

Questions such as “How many days of leave do I get?” belong to the HR policy workflow – the two descriptions should rule each other out.

Deploy the AI agent on your signed-in intranet Webchat, where staff are already identified by {_customer.email}, and on WhatsApp for staff away from a desk.

2. Identify the staff member and fetch their balances

Know who is asking before showing any balance.

Verify the staff member exactly as in Step 5 of the HR policy guide – from {_customer.email} on signed-in Webchat, or a staff ID check on WhatsApp – so the staff variable is set. If this workflow runs after an HR policy question in the same chat, add a Branch that skips straight past this step when staff is already set.

Add a Send API action:

  • HTTP method: GET
  • URL endpoint: your HR system’s leave balance endpoint, passing {staff["id"]}
  • Headers: the authorisation key your system requires
  • Resulting variable: balances

Ask your HR system to return each leave type the person is entitled to, with its remaining days and whether it has an approval flow.

3. Choose the type of leave

Offer only the leave types the person can actually take.

Add a Send message action:

“Which type of leave would you like to request?”

with quick replies Annual leave | Sick leave | Family responsibility leave | Study leave | Unpaid leave. Remove any your organisation doesn’t offer, and name them exactly as your HR system does. Under each quick reply, add a Message received sub-trigger and a Set variable action for leave_type.

Then add a Send message that shows the balance for that type:

“You have {balances[leave_type][“remaining”]} days of {leave_type} left this year.“

If the balance is 0 and the type isn’t unpaid leave, add a Branch that says so and offers Request unpaid leave | Ask HR, where Ask HR uses a Jump action to the HR policy workflow’s ticket step.

4. Collect the dates and cover

Ask for everything the manager will need to say yes.

Add an Ask survey action. Action title: Leave dates

Field Variable Type Invalid reply
First day of leave (DD/MM/YYYY) start_date Text Please enter the date as DD/MM/YYYY
Last day of leave (DD/MM/YYYY) end_date Text Please enter the date as DD/MM/YYYY
Full or half days? day_type Text, with quick replies Full days | Half day at the start | Half day at the end Please choose one of the options
Who will cover your work? cover Text Please name a colleague, or say “not needed”

Turn on Enable skip for the cover field only – some roles don’t need it. For a single half day, the person enters the same date twice and picks a half-day option.

5. Validate the dates

Let the HR system do the date arithmetic, not the AI agent.

Add a Send API action:

  • HTTP method: POST
  • URL endpoint: your HR system’s leave validation endpoint
  • Body: {staff["id"]}, {leave_type}, {start_date}, {end_date} and {day_type}
  • Resulting variable: check

Ask the endpoint to return the number of working days, any problem found and the balance afterwards. It should handle weekends, public holidays and shift patterns, which differ by location. Then add a Branch:

Condition Send message
check["problem"] == "invalid_date" “I couldn’t read one of those dates, or the last day is before the first. Let’s try again.” – then Jump to Step 4
check["problem"] == "overlap" “You already have leave booked on some of these days. Would you like to change that request instead?” – quick replies Change it | Pick other dates
check["problem"] == "over_balance" “This request is {check[“working_days”]} working days, but you have {balances[leave_type][“remaining”]} left. You could shorten it, or take the rest as unpaid leave.“
Else Continue to Step 6

Count failed attempts with a Set variable action and, after two, offer Ask HR rather than another loop. Under Error and Timed out, tell the person the HR system isn’t available and suggest trying again later – never submit dates that haven’t been checked.

6. Ask for a medical certificate

Sick leave over your policy limit needs evidence, and staff can send a photo of it in the chat.

Add a Branch: if leave_type == "Sick leave" and check["needs_certificate"] == true – for example, more than two consecutive working days – add an Ask survey action. Action title: Medical certificate

Field Variable Type Invalid reply
Photo or scan of your medical certificate certificate Attachment Please upload the certificate as a photo or PDF

Turn on Enable skip and say in the question that it can be sent later – someone who is ill shouldn’t be blocked. A medical certificate is health information, so the ticket or HR record it goes to should only be visible to HR and the manager.

7. Confirm and submit the request

Play the request back, then send it to whoever approves it.

Add a Send message:

“Here’s your request: {leave_type}, {start_date} to {end_date} ({check[“working_days”]} working days), cover: {cover}. Shall I submit it?“

with quick replies Submit | Change dates | Cancel. Change dates jumps to Step 4.

Under Submit, add a Branch on whether the leave type has an approval flow in your HR system:

  • HR system approval: add a Send API action (HTTP method: POST) to the HR system’s leave request endpoint with the details and the certificate’s file link, resulting variable leave_request. The HR system notifies the manager the way it already does. Then send: “Your request {leave_request[“id”]} has been sent to your manager. You’ll be notified in the HR system when they decide.“

  • No approval flow: add a Create ticket action:

    • Assignee: the manager’s team. If your HR system returns it, set the assignee from a variable, e.g. {staff["team_id"]}. If it returns only a department name, add an Auto team match action on {staff["department"]} first – it compares the text with team names and Alternative names in Settings › Teams – and use its result under Match found, with your HR team as the assignee under No match.
    • Subject: Leave request – {staff[“name”]} – {start_date} to {end_date}
    • Description: leave type, working days, half days, cover and the balance afterwards
    • Full name and Email: from the staff record
    • Attachment(s): certificate, where one was uploaded
    • Auto-apply tags: leave-request and the leave type

    Then send: “Your request has been sent to your manager’s team – your reference is {_new_ticket.short_id}.”

Under the Send API action’s Error and Timed out branches, fall back to the ticket, so a request is never lost.

8. Approve or reject the request

Decisions happen where managers already work.

Where the HR system has an approval flow, the manager approves or rejects there and the HR system updates the balance and tells the staff member.

Where a ticket was created, the manager opens it in the Inbox, checks the dates and cover, and replies to the staff member from the ticket with the decision. They add an approved or rejected tag and set the ticket to Resolved. Changing a ticket’s status doesn’t message the staff member on its own – the reply does. HR records approved leave in the HR system, so the balance stays right. The teamspace’s overdue rule in Settings › Tickets › Overdue rules applies to every ticket, including these.

9. Cancel or change a request

Plans change – let staff undo a request without emailing HR.

Add a second workflow with the Message received trigger (e.g. “Cancel Leave”, with phrases like “Cancel my leave” and “Change my leave dates”). Verify the person as in Step 2, then add a Send API action (HTTP method: GET) for their upcoming requests, resulting variable upcoming. Add a Send message with up to three requests as quick replies, e.g. {upcoming[0]["label"]} – empty ones are dropped.

Then ask Cancel it | Change the dates:

  • Cancel it: a Send API action (HTTP method: DELETE, or PATCH with a cancelled status) to the HR system, then a confirmation message.
  • Change the dates: cancel the old request in the same way and Jump to the leave request workflow’s Step 4.

For requests approved through a ticket, add a Create ticket for the same team with the subject Leave cancellation, so the manager knows the cover is no longer needed.

10. Test the flow

Validate every path before going live using the AI agent tester side panel.

  • Request two days of annual leave and confirm the balance shown and the working days returned by the HR system.
  • Enter dates that overlap an existing request, and an end date before the start date, and check each message.
  • Request four days of sick leave, skip the certificate and confirm the request is still submitted.
  • Make the HR system return an error and confirm a ticket is created for the manager’s team instead.
  • Build and test in an undeployed version – Duplicate the live version on the Workflows tab – then Deploy when every path passes.

Finalise the AI agent deployment by configuring your preferred channels and languages.