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
servicesIServiceProviderThe work item's own scoped service provider.
accountPhoneNumberThe account the work was queued for.
conversationRecipientWhere replies go: the conversation the work was queued from.
cancellationTokenCancellationTokenCancelled when the host shuts down.
senderSenderWho 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
CancellationToken
Cancelled when the host shuts down.
public CancellationToken CancellationToken { get; }
Property Value
Conversation
Where replies go.
public Recipient Conversation { get; }
Property Value
Sender
Who triggered the work, if it was queued from a message.
public Sender? Sender { get; }
Property Value
Services
The work item's own scoped service provider.
public IServiceProvider Services { get; }
Property Value
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
questionstringThe question to send.
timeoutTimeSpan?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
questionstringThe question to send.
timeoutTimeSpan?How long to wait for each answer; defaults to
Signal:Background:PromptTimeout.attemptsintHow many answers to accept before giving up with Invalid.
Returns
- Task<PromptResult<T>>
The parsed answer, or why there is none.
Type Parameters
TThe requested type.
Exceptions
- InvalidOperationException
The work was not queued from a message, so there is no sender to ask.
- ArgumentOutOfRangeException
attemptsis less than 1.
ReplyAsync(OutgoingMessage)
Sends a prepared message from Account; its recipients are used as-is.
public Task<SendResult> ReplyAsync(OutgoingMessage message)
Parameters
messageOutgoingMessageThe message.
Returns
- Task<SendResult>
The send result.
ReplyAsync(string)
Sends a text into Conversation.
public Task<SendResult> ReplyAsync(string text)
Parameters
textstringThe text.
Returns
- Task<SendResult>
The send result.