{
  "version": "4.0.0",
  "form": {
    "name": "Phone OTP verification with Auth0 Phone Provider",
    "languages": {
      "primary": "en"
    },
    "nodes": [
      {
        "id": "step_4iwC",
        "type": "STEP",
        "coordinates": {
          "x": 70,
          "y": -133
        },
        "alias": "Phone details",
        "config": {
          "components": [
            {
              "id": "rich_text_hPsU",
              "category": "BLOCK",
              "type": "RICH_TEXT",
              "config": {
                "content": "<h2>Enter your phone</h2><p>A verification code will be sent to the phone number you provide.</p>"
              }
            },
            {
              "id": "phone_number",
              "category": "FIELD",
              "type": "TEL",
              "label": "Phone number",
              "required": true,
              "sensitive": false,
              "config": {
                "country_picker": true
              }
            },
            {
              "id": "message_type",
              "category": "FIELD",
              "type": "BOOLEAN",
              "label": "How do you want to receive the message?",
              "required": true,
              "sensitive": false,
              "config": {
                "default_value": false,
                "options": {
                  "true": "Voice",
                  "false": "SMS"
                }
              }
            },
            {
              "id": "next_button_YKS2",
              "category": "BLOCK",
              "type": "NEXT_BUTTON",
              "config": {
                "text": "Continue"
              }
            }
          ],
          "next_node": "flow_3Qle"
        }
      },
      {
        "id": "step_qJEB",
        "type": "STEP",
        "coordinates": {
          "x": 991,
          "y": -120
        },
        "alias": "Phone details",
        "config": {
          "components": [
            {
              "id": "rich_text_Cqas",
              "category": "BLOCK",
              "type": "RICH_TEXT",
              "config": {
                "content": "<h2>Check your phone</h2><p>Please enter the 6-digit verification code that was sent to <strong>{{fields.phone_number.international_format}}</strong>. The code is valid for 5 minutes.</p>"
              }
            },
            {
              "id": "verification_code",
              "category": "FIELD",
              "type": "NUMBER",
              "label": "Verification code",
              "required": true,
              "sensitive": false
            },
            {
              "id": "next_button_BtEe",
              "category": "BLOCK",
              "type": "NEXT_BUTTON",
              "config": {
                "text": "Continue"
              }
            },
            {
              "id": "resend_button_fG99",
              "category": "BLOCK",
              "type": "RESEND_BUTTON",
              "config": {
                "active_text": "Didn't receive the code?",
                "button_text": "Resend",
                "waiting_text": "Resend in {{remaining_seconds}} seconds",
                "text_alignment": "CENTER",
                "flow_id": "#FLOW-1#",
                "max_attempts": 3,
                "waiting_time": 60
              }
            }
          ],
          "next_node": "flow_hq3b"
        }
      },
      {
        "id": "flow_hq3b",
        "type": "FLOW",
        "coordinates": {
          "x": 1542,
          "y": 46
        },
        "config": {
          "flow_id": "#FLOW-2#",
          "next_node": "$ending"
        }
      },
      {
        "id": "flow_3Qle",
        "type": "FLOW",
        "coordinates": {
          "x": 625,
          "y": 50
        },
        "config": {
          "flow_id": "#FLOW-1#",
          "next_node": "step_qJEB"
        }
      }
    ],
    "start": {
      "next_node": "step_4iwC",
      "coordinates": {
        "x": -191,
        "y": 32
      }
    },
    "ending": {
      "resume_flow": true,
      "coordinates": {
        "x": 1917,
        "y": 21
      }
    }
  },
  "flows": {
    "#FLOW-1#": {
      "name": "Generate OTP & Send message",
      "actions": [
        {
          "id": "generate_otp",
          "type": "OTP",
          "action": "GENERATE_CODE",
          "allow_failure": false,
          "mask_output": false,
          "params": {
            "reference": "{{fields.phone_number.international_number}}",
            "length": 6
          }
        },
        {
          "id": "if_then_condition_cfSA",
          "type": "FLOW",
          "action": "BOOLEAN_CONDITION",
          "allow_failure": false,
          "mask_output": false,
          "params": {
            "if": {
              "operands": [
                {
                  "operands": [
                    "{{fields.message_type}}",
                    true
                  ],
                  "operator": "EQ"
                }
              ],
              "operator": "AND"
            },
            "then": [
              {
                "id": "send_sms_kcd6",
                "type": "AUTH0",
                "action": "MAKE_CALL",
                "allow_failure": false,
                "mask_output": false,
                "params": {
                  "to": "{{fields.phone_number.international_number}}",
                  "message": "{{custom_vars.otp}} is your verification code",
                  "from": "",
                  "custom_vars": {
                    "otp": "{{actions.generate_otp.code}}"
                  }
                }
              }
            ],
            "else": [
              {
                "id": "send_sms_hcd6",
                "type": "AUTH0",
                "action": "SEND_SMS",
                "allow_failure": false,
                "mask_output": false,
                "params": {
                  "to": "{{fields.phone_number.international_number}}",
                  "message": "{{custom_vars.otp}} is your verification code",
                  "from": "",
                  "custom_vars": {
                    "otp": "{{actions.generate_otp.code}}"
                  }
                }
              }
            ]
          }
        }
      ]
    },
    "#FLOW-2#": {
      "name": "Verify phone OTP & Update user",
      "actions": [
        {
          "id": "verify_otp",
          "type": "OTP",
          "action": "VERIFY_CODE",
          "allow_failure": false,
          "mask_output": false,
          "params": {
            "reference": "{{fields.phone_number.international_number}}",
            "code": "{{fields.verification_code}}"
          }
        },
        {
          "id": "if_then_condition_mnXT",
          "alias": "Is it valid?",
          "type": "FLOW",
          "action": "BOOLEAN_CONDITION",
          "allow_failure": false,
          "mask_output": false,
          "params": {
            "if": {
              "operands": [
                {
                  "operands": [
                    "{{actions.verify_otp.valid}}",
                    true
                  ],
                  "operator": "EQ"
                }
              ],
              "operator": "AND"
            },
            "then": [
              {
                "id": "update_user_HlyR",
                "type": "AUTH0",
                "action": "UPDATE_USER",
                "allow_failure": false,
                "mask_output": false,
                "params": {
                  "connection_id": "#CONN-1#",
                  "user_id": "{{context.user.user_id}}",
                  "changes": {
                    "phone_number": "{{fields.phone_number.international_number}}",
                    "phone_verified": true
                  }
                }
              }
            ],
            "else": [
              {
                "id": "showErrorMessage_Whan",
                "type": "FLOW",
                "action": "ERROR_MESSAGE",
                "allow_failure": false,
                "mask_output": false,
                "params": {
                  "message": "We're sorry, your verification code is not valid. Please, review it and try it again."
                }
              }
            ]
          }
        }
      ]
    }
  },
  "connections": {
    "#CONN-1#": {
      "id": "ac_7sDGLTjYzQoLAKNUam1WMv",
      "app_id": "AUTH0",
      "name": "REPLACE_WITH_M2M_CONNECTION"
    }
  }
}
