diff --git a/src/WhatsApp/MessageExtensions.cs b/src/WhatsApp/MessageExtensions.cs index 1378599..71f4391 100644 --- a/src/WhatsApp/MessageExtensions.cs +++ b/src/WhatsApp/MessageExtensions.cs @@ -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; } + + /// + /// Alternative text to send to the console, if the message is intended to reach the CLI. + /// + public string? ConsoleText + { + get => (message.AdditionalProperties ??= []).TryGetValue("ConsoleText", out var value) ? value as string : null; + set => (message.AdditionalProperties ??= [])["ConsoleText"] = value; + } + + /// + /// The message is intended for consumption only in the console and should not be sent to WhatsApp. + /// + public bool ConsoleOnly + { + get => (message.AdditionalProperties ??= []).TryGetValue("ConsoleOnly", out var value) ? value as bool? ?? default : default; + set => (message.AdditionalProperties ??= [])["ConsoleOnly"] = value; + } } /// diff --git a/src/WhatsApp/ReactionResponse.cs b/src/WhatsApp/ReactionResponse.cs index 105ec47..900b38d 100644 --- a/src/WhatsApp/ReactionResponse.cs +++ b/src/WhatsApp/ReactionResponse.cs @@ -21,9 +21,10 @@ internal ReactionResponse(Service service, string userNumber, string context, st protected override async Task 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(); } diff --git a/src/WhatsApp/TextResponse.cs b/src/WhatsApp/TextResponse.cs index 2d538e9..df5e182 100644 --- a/src/WhatsApp/TextResponse.cs +++ b/src/WhatsApp/TextResponse.cs @@ -22,24 +22,28 @@ internal TextResponse(Service service, string userNumber, string context, string /// protected override async Task 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 SendReplyAsync(IWhatsAppClient client, string serviceId, CancellationToken cancellation) + Task 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); } } } \ No newline at end of file