Class CommandContext
- Namespace
- Signal.Application.Commands
- Assembly
- Signal.Application.dll
Everything a command needs: the message, parsed arguments, the scoped services and reply helpers.
public sealed class CommandContext
- Inheritance
-
CommandContext
- Inherited Members
Constructors
CommandContext(MessageContext, ParsedCommand, CommandDescriptor)
Everything a command needs: the message, parsed arguments, the scoped services and reply helpers.
public CommandContext(MessageContext message, ParsedCommand parsed, CommandDescriptor command)
Parameters
messageMessageContextThe pipeline context of the triggering message.
parsedParsedCommandThe parsed invocation.
commandCommandDescriptorThe matched command.
Properties
Account
The receiving account.
public PhoneNumber Account { get; }
Property Value
Arguments
Positional arguments (naive split: every flag consumes the following token; for ICommand implementations).
public IReadOnlyList<string> Arguments { get; }
Property Value
CancellationToken
Cancelled when the host shuts down.
public CancellationToken CancellationToken { get; }
Property Value
Command
The matched command.
public CommandDescriptor Command { get; }
Property Value
Conversation
Where replies go: the group, or the sender for direct messages.
public Recipient Conversation { get; }
Property Value
Data
The triggering data message.
public DataMessage Data { get; }
Property Value
Exceptions
- InvalidOperationException
The envelope has no data message (never the case for parsed commands).
Envelope
The triggering envelope.
public IncomingEnvelope Envelope { get; }
Property Value
Flags
Options given as --name value, --name=value or --name (null value); names are case-insensitive.
public IReadOnlyDictionary<string, string?> Flags { get; }
Property Value
Group
The group the command was sent in, or null.
public GroupId? Group { get; }
Property Value
IsGroup
Whether the command was sent in a group.
public bool IsGroup { get; }
Property Value
Message
The pipeline context of the triggering message.
public MessageContext Message { get; }
Property Value
Parsed
The parsed invocation (prefix, name, raw arguments, tokens).
public ParsedCommand Parsed { get; }
Property Value
Sender
Who invoked the command.
public Sender Sender { get; }
Property Value
Services
The message's scoped service provider.
public IServiceProvider Services { get; }
Property Value
Methods
ReactAsync(string, CancellationToken)
Reacts to the triggering message.
public Task ReactAsync(string emoji, CancellationToken cancellationToken = default)
Parameters
emojistringThe reaction emoji.
cancellationTokenCancellationTokenCancels the request; defaults to CancellationToken.
Returns
- Task
A task that completes when the reaction was sent.
ReplyAsync(OutgoingMessage, CancellationToken)
Sends a prepared message (e.g. with attachments) from the receiving account.
public Task<SendResult> ReplyAsync(OutgoingMessage message, CancellationToken cancellationToken = default)
Parameters
messageOutgoingMessageThe message; typically addressed to Conversation.
cancellationTokenCancellationTokenCancels the send; defaults to CancellationToken.
Returns
- Task<SendResult>
The send result.
ReplyAsync(string, bool?, CancellationToken)
Replies into the conversation.
public Task<SendResult> ReplyAsync(string text, bool? quote = null, CancellationToken cancellationToken = default)
Parameters
textstringThe reply text.
quotebool?Quote the triggering message; defaults to QuoteReplies.
cancellationTokenCancellationTokenCancels the send; defaults to CancellationToken.
Returns
- Task<SendResult>
The send result.
ReplyStyledAsync(string, CancellationToken)
Replies using Signal's text styling (bold, italic, …).
public Task<SendResult> ReplyStyledAsync(string text, CancellationToken cancellationToken = default)
Parameters
textstringThe styled reply text.
cancellationTokenCancellationTokenCancels the send; defaults to CancellationToken.
Returns
- Task<SendResult>
The send result.