Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/WhatsApp/MessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ public bool FromConsole
get => (message.AdditionalProperties ??= []).TryGetValue("FromConsole", out var value) ? value as bool? ?? default : default;
set => (message.AdditionalProperties ??= [])["FromConsole"] = value;
}

/// <summary>
/// Alternative text to send to the console, if the message is intended to reach the CLI.
/// </summary>
public string? ConsoleText
{
get => (message.AdditionalProperties ??= []).TryGetValue("ConsoleText", out var value) ? value as string : null;
set => (message.AdditionalProperties ??= [])["ConsoleText"] = value;
}

/// <summary>
/// The message is intended for consumption only in the console and should not be sent to WhatsApp.
/// </summary>
public bool ConsoleOnly
{
get => (message.AdditionalProperties ??= []).TryGetValue("ConsoleOnly", out var value) ? value as bool? ?? default : default;
set => (message.AdditionalProperties ??= [])["ConsoleOnly"] = value;
}
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/WhatsApp/ReactionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ internal ReactionResponse(Service service, string userNumber, string context, st
protected override async Task<string?> SendCoreAsync(IWhatsAppClient client, CancellationToken cancellationToken = default)
{
if (service != null)
await client.ReactAsync(service.Secondary.Id, UserNumber, Context, Emoji, cancellationToken);
await client.ReactAsync(service.Secondary.Id, UserNumber, Context, this.ConsoleText ?? Emoji, cancellationToken);

await client.ReactAsync(ServiceId, UserNumber, Context, Emoji);
if (service == null || this.ConsoleOnly != true)
await client.ReactAsync(ServiceId, UserNumber, Context, Emoji);

return Ulid.NewUlid().ToString();
}
Expand Down
16 changes: 10 additions & 6 deletions src/WhatsApp/TextResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@ internal TextResponse(Service service, string userNumber, string context, string
/// <inheritdoc/>
protected override async Task<string?> SendCoreAsync(IWhatsAppClient client, CancellationToken cancellation = default)
{
string? id = null;
if (service != null)
await SendReplyAsync(client, service.Secondary.Id, cancellation);
id = await SendReplyAsync(client, service.Secondary.Id, this.ConsoleText ?? Text, cancellation);

return await SendReplyAsync(client, ServiceId, cancellation);
if (service == null || this.ConsoleOnly != true)
return await SendReplyAsync(client, ServiceId, Text, cancellation);

return id;
}

Task<string?> SendReplyAsync(IWhatsAppClient client, string serviceId, CancellationToken cancellation)
Task<string?> SendReplyAsync(IWhatsAppClient client, string serviceId, string text, CancellationToken cancellation)
{
if (Button1 != null)
{
if (Button2 == null)
return client.ReplyAsync(serviceId, UserNumber, Context, Text, Button1, cancellation);
return client.ReplyAsync(serviceId, UserNumber, Context, text, Button1, cancellation);
else
return client.ReplyAsync(serviceId, UserNumber, Context, Text, Button1, Button2, cancellation);
return client.ReplyAsync(serviceId, UserNumber, Context, text, Button1, Button2, cancellation);
}
else
{
return client.ReplyAsync(serviceId, UserNumber, Context, Text, cancellation);
return client.ReplyAsync(serviceId, UserNumber, Context, text, cancellation);
}
}
}