```python:inference/core/workflows/core_steps/sinks/email_notification/v2.py
import re
from typing import Any, Dict, List

from inference.core.workflows.core_steps.common.query_language.entities.operations import AllOperationsType
from inference.core.workflows.core_steps.common.query_language.operations.core import build_operations_chain

PARAMETER_REGEX = re.compile(r"({{\s*\$parameters\.(\w+)\s*}})")


def apply_operations_to_message_parameters(
    message_parameters: Dict[str, Any],
    message_parameters_operations: Dict[str, List[AllOperationsType]],
) -> Dict[str, Any]:
    """
    Apply per-parameter operation chains to message parameter values.

    For each parameter in message_parameters, if operations are defined in
    message_parameters_operations for that parameter name, the operations are
    applied in order (e.g. ToString, StringToUpperCase, LookupTable).
    Parameters with no operations are returned unchanged.

    Supports all value types, including WorkflowImageData: image operations
    such as ExtractImageProperty, ConvertImageToBase64, and ConvertImageToJPEG
    can be used to transform image parameters before they are serialized or
    interpolated into the message.

    Returns:
        A dict with the same keys as message_parameters and values that are
        either the original value (no operations) or the result of the
        operations chain.
    """
    parameters_values = {}
    for parameter_name, parameter_value in message_parameters.items():

        operations = message_parameters_operations.get(parameter_name)
        if not operations:
            parameters_values[parameter_name] = parameter_value
            continue

        operations_chain = build_operations_chain(operations=operations)
        parameters_values[parameter_name] = operations_chain(
            parameter_value, global_parameters={}
        )

    return parameters_values


def format_email_message(
    message: str,
    message_parameters: Dict[str, Any],
    message_parameters_operations: Dict[str, List[AllOperationsType]],
) -> str:
    """Format email message by replacing parameter placeholders with actual values."""
    matching_parameters = PARAMETER_REGEX.findall(message)
    if not matching_parameters:
        return message

    parameters_values = apply_operations_to_message_parameters(
        message_parameters=message_parameters,
        message_parameters_operations=message_parameters_operations,
    )

    for placeholder, parameter_name in matching_parameters:
        if parameter_name in message_parameters:
            message = message.replace(
                placeholder, str(parameters_values[parameter_name])
            )
    return message
```