Table of Contents

Class BackgroundWork

Namespace
Signal.Application.Background
Assembly
Signal.Application.dll

The context of queued background work: its own DI scope, the conversation it was queued from and a shutdown token.

public sealed class BackgroundWork
Inheritance
BackgroundWork
Inherited Members

Remarks

The message that queued the work has already been handled and its DI scope disposed. Resolve services from Services, never capture scoped services from the message.

Constructors

BackgroundWork(IServiceProvider, PhoneNumber, Recipient, CancellationToken, Sender?)

The context of queued background work: its own DI scope, the conversation it was queued from and a shutdown token.

public BackgroundWork(IServiceProvider services, PhoneNumber account, Recipient conversation, CancellationToken cancellationToken, Sender? sender = null)

Parameters

services IServiceProvider

The work item's own scoped service provider.

account PhoneNumber

The account the work was queued for.

conversation Recipient

Where replies go: the conversation the work was queued from.

cancellationToken CancellationToken

Cancelled when the host shuts down.

sender Sender

Who triggered the work, if it was queued from a message; prompts wait for this sender.

Remarks

The message that queued the work has already been handled and its DI scope disposed. Resolve services from Services, never capture scoped services from the message.

Properties

Account

The account the work was queued for; replies are sent from it.

public PhoneNumber Account { get; }

Property Value

PhoneNumber

CancellationToken

Cancelled when the host shuts down.

public CancellationToken CancellationToken { get; }

Property Value

CancellationToken

Conversation

Where replies go.

public Recipient Conversation { get; }

Property Value

Recipient

Sender

Who triggered the work, if it was queued from a message.

public Sender? Sender { get; }

Property Value

Sender

Services

The work item's own scoped service provider.

public IServiceProvider Services { get; }

Property Value

IServiceProvider

Methods

PromptAsync(string, TimeSpan?)

Asks Sender a question and waits for their next text message in Conversation.

public Task<PromptResult<string>> PromptAsync(string question, TimeSpan? timeout = null)

Parameters

question string

The question to send.

timeout TimeSpan?

How long to wait; defaults to Signal:Background:PromptTimeout.

Returns

Task<PromptResult<string>>

The answer, or TimedOut.

Exceptions

InvalidOperationException

The work was not queued from a message, so there is no sender to ask.

PromptAsync<T>(string, TimeSpan?, int)

Asks Sender for a value of type T (any IParsable<TSelf>: numbers, dates, PhoneNumber, …, parsed with the invariant culture). Invalid answers are rejected with a hint and the question is asked again, up to attempts times.

public Task<PromptResult<T>> PromptAsync<T>(string question, TimeSpan? timeout = null, int attempts = 3) where T : IParsable<T>

Parameters

question string

The question to send.

timeout TimeSpan?

How long to wait for each answer; defaults to Signal:Background:PromptTimeout.

attempts int

How many answers to accept before giving up with Invalid.

Returns

Task<PromptResult<T>>

The parsed answer, or why there is none.

Type Parameters

T

The requested type.

Exceptions

InvalidOperationException

The work was not queued from a message, so there is no sender to ask.

ArgumentOutOfRangeException

attempts is less than 1.

ReplyAsync(OutgoingMessage)

Sends a prepared message from Account; its recipients are used as-is.

public Task<SendResult> ReplyAsync(OutgoingMessage message)

Parameters

message OutgoingMessage

The message.

Returns

Task<SendResult>

The send result.

ReplyAsync(string)

Sends a text into Conversation.

public Task<SendResult> ReplyAsync(string text)

Parameters

text string

The text.

Returns

Task<SendResult>

The send result.