Table of Contents

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

message MessageContext

The pipeline context of the triggering message.

parsed ParsedCommand

The parsed invocation.

command CommandDescriptor

The matched command.

Properties

Account

The receiving account.

public PhoneNumber Account { get; }

Property Value

PhoneNumber

Arguments

Positional arguments (naive split: every flag consumes the following token; for ICommand implementations).

public IReadOnlyList<string> Arguments { get; }

Property Value

IReadOnlyList<string>

CancellationToken

Cancelled when the host shuts down.

public CancellationToken CancellationToken { get; }

Property Value

CancellationToken

Command

The matched command.

public CommandDescriptor Command { get; }

Property Value

CommandDescriptor

Conversation

Where replies go: the group, or the sender for direct messages.

public Recipient Conversation { get; }

Property Value

Recipient

Data

The triggering data message.

public DataMessage Data { get; }

Property Value

DataMessage

Exceptions

InvalidOperationException

The envelope has no data message (never the case for parsed commands).

Envelope

The triggering envelope.

public IncomingEnvelope Envelope { get; }

Property Value

IncomingEnvelope

Flags

Options given as --name value, --name=value or --name (null value); names are case-insensitive.

public IReadOnlyDictionary<string, string?> Flags { get; }

Property Value

IReadOnlyDictionary<string, string>

Group

The group the command was sent in, or null.

public GroupId? Group { get; }

Property Value

GroupId?

IsGroup

Whether the command was sent in a group.

public bool IsGroup { get; }

Property Value

bool

Message

The pipeline context of the triggering message.

public MessageContext Message { get; }

Property Value

MessageContext

Parsed

The parsed invocation (prefix, name, raw arguments, tokens).

public ParsedCommand Parsed { get; }

Property Value

ParsedCommand

Sender

Who invoked the command.

public Sender Sender { get; }

Property Value

Sender

Services

The message's scoped service provider.

public IServiceProvider Services { get; }

Property Value

IServiceProvider

Methods

ReactAsync(string, CancellationToken)

Reacts to the triggering message.

public Task ReactAsync(string emoji, CancellationToken cancellationToken = default)

Parameters

emoji string

The reaction emoji.

cancellationToken CancellationToken

Cancels 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

message OutgoingMessage

The message; typically addressed to Conversation.

cancellationToken CancellationToken

Cancels 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

text string

The reply text.

quote bool?

Quote the triggering message; defaults to QuoteReplies.

cancellationToken CancellationToken

Cancels 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

text string

The styled reply text.

cancellationToken CancellationToken

Cancels the send; defaults to CancellationToken.

Returns

Task<SendResult>

The send result.