> ## Documentation Index
> Fetch the complete documentation index at: https://openops-ecb4f397-ops-3865.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Human-in-the-Loop

> How to request human approval and intervention in your workflows

export const NarrowImage = ({src, alt, widthPercent}) => {
  const className = `narrow-image-${useId().replace(/:/g, '-')}`;
  const widthRule = widthPercent ? `width: ${widthPercent}%;` : '';
  return <>
      <style>{`
        .${className} {
          max-width: 75%;
          ${widthRule}
        }
        @media (max-width: 768px) {
          .${className} {
            max-width: 100%;
            width: auto;
          }
        }
      `}</style>

      <img className={className} src={src} alt={alt} />
    </>;
};

Some workflows can run safely in unattended mode. Others, such as resource deletions, are more impactful and may require review by stakeholders before proceeding. To address this, OpenOps offers two Human-in-the-Loop mechanisms: [approvals](#requesting-approvals) and [notifications](#sending-notifications).

For example, you can create a workflow that flags idle RDS instances for review, prompting human approval before any scaling down or termination actions are taken.

## Requesting approvals

You can automate sending your stakeholders messages with actionable links or buttons and make your workflow stop executing until the receiver clicks one of these links or buttons. Depending on their choice, you can split the subsequent steps of your workflow into conditional branches.

OpenOps offers dedicated approval request features for Slack and Microsoft Teams, as well as a more generic approval mechanism that you can use with other communication channels such as email.

### On Slack

OpenOps provides several Slack-related actions:

<NarrowImage src="/images/hitl-slack-actions.png" alt="Slack actions" />

#### With "Request Action"

One of Slack-related actions, **Request Action**, is the most straightforward way to request approval. It lets you build a Slack message with standard action buttons, send it to a chat or a public channel, and wait until the recipient clicks one of these buttons, signifying their decision:

<NarrowImage src="/images/cloudhealth/slack-request-action-properties-1.png" alt="Request action via Slack" />

When this action fires, the Slack user receives a message that you've defined in the action's properties. The message may look like this:

<NarrowImage src="/images/cloudhealth/slack-notification.png" alt="Slack message with an action request" />

As soon as the user clicks one of the buttons, your **Request Action** step receives this as the output. You can then create a [conditional branch](/workflow-management/conditional-branching/) with the **Split** action and implement distinct steps depending on which button the user clicked:

<img src="https://mintcdn.com/openops-ecb4f397-ops-3865/VKS8haM5H7drDOHi/images/cloudhealth/slack-split-added.png?fit=max&auto=format&n=VKS8haM5H7drDOHi&q=85&s=1906dd0fcead6b3aba2f916bbfb7b8a6" alt="Splitting based on a user action" width="3172" height="1216" data-path="images/cloudhealth/slack-split-added.png" />

#### With "Send Message" and "Wait For User Action"

If you want to build approval requests with more customization options, you can use the **Send Message** action in the **Slack** block instead of **Request Action**.

The upside of **Send Message** is that it enables you to create approval requests using Slack's rich [Block Kit](https://api.slack.com/block-kit) UI framework.

However, **Send Message** doesn't wait for a reply from the recipient. Instead, use the **Wait For User Action** action and pass the output of **Send Message** to it. This allows the workflow to capture button clicks in the approval request. Once a button click associated with a decision is captured, you can then use the **Split** action to add workflow steps depending on the decision.

### On Microsoft Teams

OpenOps provides the following actions in its Microsoft Teams block:

<NarrowImage src="/images/hitl-teams-actions.png" alt="Microsoft Teams actions" />

**Request Action** is the action you can use to request approval. It lets you build a Teams message with action buttons, send it to a chat or a channel, and wait until the recipient clicks a button to convey a decision:

<NarrowImage src="/images/hitl-teams-request-action-properties.png" alt="Request action via Microsoft Teams" />

When this action runs, the Microsoft Teams user or channel receives a message that you've defined in the action's properties. The message may look like this:

<NarrowImage src="/images/hitl-teams-message.png" alt="MS Teams message with an action request" />

When the user clicks one of the buttons, your **Request Action** step receives the selection as its output. You can then create a [conditional branch](/workflow-management/conditional-branching/) with the **Split** action and implement different steps depending on which button the user clicked:

<img src="https://mintcdn.com/openops-ecb4f397-ops-3865/VKS8haM5H7drDOHi/images/hitl-teams-split.png?fit=max&auto=format&n=VKS8haM5H7drDOHi&q=85&s=6200b2bb3c710195c12786817b0f19d6" alt="Splitting based on a user action" width="3335" height="1857" data-path="images/hitl-teams-split.png" />

### By email

To request approvals through other communication channels, such as email, use the **Approval** block of actions:

<NarrowImage src="/images/hitl-approval-actions.png" alt="Approval actions" />

In this case, you can create the approval part of your workflow as follows:

1. Add the **Create Approval Links** action from the **Approval** block. This action generates two links: one for approval and one for disapproval.
2. Add an action to send the two links to a stakeholder. For example, you can use **Send Email** from the **SMTP** block or **Send Email** from the **Microsoft Outlook** block.
3. Add the **Wait For Approval** action from the **Approval** block. Once the stakeholder clicks a link, this action updates the approval status accordingly.
4. Add the **Condition** action to define steps for approval and disapproval.

Here's a sample workflow that uses **Create Approval Links**, delivers an email notification using **Send Email** from the **SMTP** block, and then proceeds based on the output of the **Wait For Approval** action:

<img src="https://mintcdn.com/openops-ecb4f397-ops-3865/VKS8haM5H7drDOHi/images/hitl-email-approval-links.png?fit=max&auto=format&n=VKS8haM5H7drDOHi&q=85&s=20a628cb147a52431e5b30d3be41cc0f" alt="Sending approval links via email" width="2609" height="1840" data-path="images/hitl-email-approval-links.png" />

The email with approval links may look like this:

<img src="https://mintcdn.com/openops-ecb4f397-ops-3865/VKS8haM5H7drDOHi/images/hitl-email.png?fit=max&auto=format&n=VKS8haM5H7drDOHi&q=85&s=89ee6b01155422dfa6b41b9ddec435ff" alt="Email with approval links" width="2348" height="660" data-path="images/hitl-email.png" />

## Sending notifications

Besides approvals, you can also send notifications about completed workflows or steps. Some of the actions that enable sending notifications include:

* Actions in the **Slack** block:
  * **Send Message** to send a direct message or a message to a public Slack channel.
  * **Update Message** to update a message previously sent to a public Slack channel.
* **Send Channel Message** and **Send Chat Message** under **Microsoft Teams**.
* Actions in the **Jira Cloud** block, such as **Change Issue Status** and **Add Issue Comment**.
* Actions to send emails under **SMTP** and **Microsoft Outlook**.
