# IInteractionService Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [IInteractionService](/reference/api/csharp/aspire.hosting/iinteractionservice.md)
- Kind: `Methods`
- Members: `8`

A service to interact with the current development environment.

<a id="promptconfirmationasync"></a>
<a id="promptconfirmationasync-string-string-messageboxinteractionoptions-cancellationtoken"></a>

## PromptConfirmationAsync(string, string, MessageBoxInteractionOptions?, CancellationToken)

- Name: `PromptConfirmationAsync(string, string, MessageBoxInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<bool>>`

Prompts the user for confirmation with a dialog.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<bool>> PromptConfirmationAsync(
        string title,
        string message,
        MessageBoxInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `title` (`string`)
  The title of the dialog.
- `message` (`string`)
  The message to display in the dialog.
- `options` ([MessageBoxInteractionOptions?](/reference/api/csharp/aspire.hosting/messageboxinteractionoptions.md)) `optional`
  Optional configuration for the message box interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation.

## Returns

`Task<InteractionResult<bool>>` -- An `Hosting.InteractionResult`1` containing `true` if the user confirmed, `false` otherwise.

<a id="promptinputasync"></a>
<a id="promptinputasync-string-string-string-string-inputsdialoginteractionoptions-cancellationtoken"></a>

## PromptInputAsync(string, string?, string, string, InputsDialogInteractionOptions?, CancellationToken)

- Name: `PromptInputAsync(string, string?, string, string, InputsDialogInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<InteractionInput>>`

Prompts the user for a single text input.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<InteractionInput>> PromptInputAsync(
        string title,
        string? message,
        string inputLabel,
        string placeHolder,
        InputsDialogInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `title` (`string`)
  The title of the input dialog.
- `message` (`string?`)
  The message to display in the dialog.
- `inputLabel` (`string`)
  The label for the input field.
- `placeHolder` (`string`)
  The placeholder text for the input field.
- `options` ([InputsDialogInteractionOptions?](/reference/api/csharp/aspire.hosting/inputsdialoginteractionoptions.md)) `optional`
  Optional configuration for the input dialog interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation.

## Returns

`Task<InteractionResult<InteractionInput>>` -- An `Hosting.InteractionResult`1` containing the user's input.

<a id="promptinputasync-string-string-interactioninput-inputsdialoginteractionoptions-cancellationtoken"></a>

## PromptInputAsync(string, string?, InteractionInput, InputsDialogInteractionOptions?, CancellationToken)

- Name: `PromptInputAsync(string, string?, InteractionInput, InputsDialogInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<InteractionInput>>`

Prompts the user for a single input using a specified [InteractionInput](/reference/api/csharp/aspire.hosting/interactioninput.md).

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<InteractionInput>> PromptInputAsync(
        string title,
        string? message,
        InteractionInput input,
        InputsDialogInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `title` (`string`)
  The title of the input dialog.
- `message` (`string?`)
  The message to display in the dialog.
- `input` ([InteractionInput](/reference/api/csharp/aspire.hosting/interactioninput.md))
  The input configuration.
- `options` ([InputsDialogInteractionOptions?](/reference/api/csharp/aspire.hosting/inputsdialoginteractionoptions.md)) `optional`
  Optional configuration for the input dialog interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation.

## Returns

`Task<InteractionResult<InteractionInput>>` -- An `Hosting.InteractionResult`1` containing the user's input.

<a id="promptinputsasync"></a>
<a id="promptinputsasync-string-string-ireadonlylist-interactioninput-inputsdialoginteractionoptions-cancellationtoken"></a>

## PromptInputsAsync(string, string?, IReadOnlyList<InteractionInput>, InputsDialogInteractionOptions?, CancellationToken)

- Name: `PromptInputsAsync(string, string?, IReadOnlyList<InteractionInput>, InputsDialogInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<InteractionInputCollection>>`

Prompts the user for multiple inputs.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<InteractionInputCollection>> PromptInputsAsync(
        string title,
        string? message,
        IReadOnlyList<InteractionInput> inputs,
        InputsDialogInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `title` (`string`)
  The title of the input dialog.
- `message` (`string?`)
  The message to display in the dialog.
- `inputs` ([IReadOnlyList<InteractionInput>](/reference/api/csharp/aspire.hosting/interactioninput.md))
  A collection of [InteractionInput](/reference/api/csharp/aspire.hosting/interactioninput.md) to prompt for.
- `options` ([InputsDialogInteractionOptions?](/reference/api/csharp/aspire.hosting/inputsdialoginteractionoptions.md)) `optional`
  Optional configuration for the input dialog interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation.

## Returns

`Task<InteractionResult<InteractionInputCollection>>` -- An `Hosting.InteractionResult`1` containing the user's inputs as an [InteractionInputCollection](/reference/api/csharp/aspire.hosting/interactioninputcollection.md).

<a id="promptmessageboxasync"></a>
<a id="promptmessageboxasync-string-string-messageboxinteractionoptions-cancellationtoken"></a>

## PromptMessageBoxAsync(string, string, MessageBoxInteractionOptions?, CancellationToken)

- Name: `PromptMessageBoxAsync(string, string, MessageBoxInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<bool>>`

Prompts the user with a message box dialog.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<bool>> PromptMessageBoxAsync(
        string title,
        string message,
        MessageBoxInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `title` (`string`)
  The title of the message box.
- `message` (`string`)
  The message to display in the message box.
- `options` ([MessageBoxInteractionOptions?](/reference/api/csharp/aspire.hosting/messageboxinteractionoptions.md)) `optional`
  Optional configuration for the message box interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation.

## Returns

`Task<InteractionResult<bool>>` -- An `Hosting.InteractionResult`1` containing `true` if the user accepted, `false` otherwise.

<a id="promptnotificationasync"></a>
<a id="promptnotificationasync-string-string-notificationinteractionoptions-cancellationtoken"></a>

## PromptNotificationAsync(string, string, NotificationInteractionOptions?, CancellationToken)

- Name: `PromptNotificationAsync(string, string, NotificationInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<bool>>`

Prompts the user with a notification.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<bool>> PromptNotificationAsync(
        string title,
        string message,
        NotificationInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `title` (`string`)
  The title of the notification.
- `message` (`string`)
  The message to display in the notification.
- `options` ([NotificationInteractionOptions?](/reference/api/csharp/aspire.hosting/notificationinteractionoptions.md)) `optional`
  Optional configuration for the notification interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation.

## Returns

`Task<InteractionResult<bool>>` -- An `Hosting.InteractionResult`1` containing `true` if the user accepted, `false` otherwise.

<a id="promptprogressasync"></a>
<a id="promptprogressasync-string-progressinteractionoptions-cancellationtoken"></a>

## PromptProgressAsync(string, ProgressInteractionOptions?, CancellationToken)

> **Experimental:** ASPIREINTERACTION001 - [Learn more](/diagnostics/aspireinteraction001/)

- Name: `PromptProgressAsync(string, ProgressInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<bool>>`

Displays a progress dialog with an indeterminate progress indicator.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<bool>> PromptProgressAsync(
        string message,
        ProgressInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `message` (`string`)
  The message to display in the progress dialog.
- `options` ([ProgressInteractionOptions?](/reference/api/csharp/aspire.hosting/progressinteractionoptions.md)) `optional`
  Optional configuration for the progress interaction.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the operation and close the dialog.

## Returns

`Task<InteractionResult<bool>>` -- An `Hosting.InteractionResult`1` containing `true` if the operation completed successfully, or a canceled result if the user clicked the cancel button.

## Remarks

The dialog displays a spinning progress wheel and can optionally include a title, message, and a cancel button.

If [ProgressInteractionOptions.Work](/reference/api/csharp/aspire.hosting/progressinteractionoptions/properties.md#work) is provided, the dialog remains open while the callback executes and closes automatically when it completes. If no callback is provided, the dialog remains open until `cancellationToken` is canceled.

When a button is shown (via [InteractionOptions.PrimaryButtonText](/reference/api/csharp/aspire.hosting/interactionoptions/properties.md#primarybuttontext)), clicking it signals cancellation through the [ProgressContext.CancellationToken](/reference/api/csharp/aspire.hosting/progresscontext/properties.md#cancellationtoken) provided to the work callback.

<a id="promptterminalasync"></a>
<a id="promptterminalasync-string-aspireterminal-terminalinteractionoptions-cancellationtoken"></a>

## PromptTerminalAsync(string, AspireTerminal, TerminalInteractionOptions?, CancellationToken)

> **Experimental:** ASPIRETERMINAL001 - [Learn more](/diagnostics/aspireterminal001/)

- Name: `PromptTerminalAsync(string, AspireTerminal, TerminalInteractionOptions?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<InteractionResult<bool>>`

Displays a caller-owned terminal in a dialog while optional work runs.

```csharp
public interface IInteractionService
{
    public abstract Task<InteractionResult<bool>> PromptTerminalAsync(
        string message,
        AspireTerminal terminal,
        TerminalInteractionOptions? options = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `message` (`string`)
  The message to display above the terminal.
- `terminal` ([AspireTerminal](/reference/api/csharp/aspire.hosting/aspireterminal.md))
  The exact terminal instance registered with this AppHost, with [TerminalPlacement.Dialog](/reference/api/csharp/aspire.hosting/terminalplacement/fields.md) placement.
- `options` ([TerminalInteractionOptions?](/reference/api/csharp/aspire.hosting/terminalinteractionoptions.md)) `optional`
  Optional title, cancel button text, message formatting, and work callback.
- `cancellationToken` (`CancellationToken`) `optional`
  A token to cancel the interaction and signal cancellation to the work callback.

## Returns

`Task<InteractionResult<bool>>` -- An `Hosting.InteractionResult`1` containing `true` when work or an explicit completion succeeds, or a canceled result when the user or caller cancels the interaction.

## Exceptions

- `ArgumentNullException` -- `message` or `terminal` is `null`.
- `InvalidOperationException` -- The interaction service is unavailable, the terminal is not registered with this AppHost, or its placement is not [TerminalPlacement.Dialog](/reference/api/csharp/aspire.hosting/terminalplacement/fields.md).
- `OperationCanceledException` -- `cancellationToken` was canceled before the interaction began.

## Remarks

Create and start the terminal before prompting, and dispose it when the caller is finished with it. The interaction borrows the terminal: completion, cancellation, and viewer disconnection do not stop or dispose it. The same terminal can be reused across prompts. The terminal process exiting does not close the dialog.

When [TerminalInteractionOptions.Work](/reference/api/csharp/aspire.hosting/terminalinteractionoptions/properties.md#work) is supplied, successful completion closes the dialog. The optional [InteractionOptions.PrimaryButtonText](/reference/api/csharp/aspire.hosting/interactionoptions/properties.md#primarybuttontext) labels a cancel button, not a submit button. User or external cancellation closes the dialog and signals [TerminalContext.CancellationToken](/reference/api/csharp/aspire.hosting/terminalcontext/properties.md#cancellationtoken); this method waits for the callback to finish before returning. Non-cancellation callback exceptions are propagated after the interaction is removed. Without a callback, the dialog waits for explicit completion, the cancel button, or `cancellationToken`.

Secondary and dismiss buttons are not shown. Disconnecting a viewer does not complete the interaction; reconnecting can display the pending dialog again.

## Examples

```csharp
await using var terminal = terminalService.CreateTerminal(new TerminalLaunchOptions
{
    Title = "Setup",
    Executable = "./setup.sh",
    Placement = TerminalPlacement.Dialog
});
terminal.Start();
var result = await interactionService.PromptTerminalAsync("Running setup.", terminal,
    new TerminalInteractionOptions
    {
        Title = "Setup",
        PrimaryButtonText = "Cancel",
        Work = async context =>
        {
            await terminal.WaitForTextAsync("Continue? ", cancellationToken: context.CancellationToken);
            await terminal.SendTextAsync("y\r", context.CancellationToken);
            await terminal.WaitForTextAsync("Setup complete", cancellationToken: context.CancellationToken);
        }
    }, cancellationToken);
```
