From 752670803b854458b90405089e720514e1bb12cc Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Tue, 8 Jul 2025 23:54:47 -0300 Subject: [PATCH] Add missing Send extension methods for IMessage This complements the send non-replies feature. --- src/WhatsApp/MessageExtensions.cs | 20 ++++++++++++++++++-- src/WhatsApp/TextResponse.cs | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/WhatsApp/MessageExtensions.cs b/src/WhatsApp/MessageExtensions.cs index b888627..d025e8a 100644 --- a/src/WhatsApp/MessageExtensions.cs +++ b/src/WhatsApp/MessageExtensions.cs @@ -110,7 +110,7 @@ public static TypingResponse Typing(this UserMessage message) => new(message.Service, message.User.Number, message.Id, message.ConversationId); /// - /// Creates a text response for the message. + /// Creates a text reply for the message. /// public static TextResponse Reply(this IMessage message, string text) => message is UserMessage user @@ -118,13 +118,29 @@ public static TextResponse Reply(this IMessage message, string text) : new(message.ServiceId, message.UserNumber, message.Id, message.ConversationId, text); /// - /// Creates a text response with buttons for the message. + /// Creates a text reply with buttons for the message. /// public static TextResponse Reply(this IMessage message, string text, Button button1, Button? button2 = default, Button? button3 = default) => message is UserMessage user ? new(user.Service, message.UserNumber, message.Id, message.ConversationId, text, button1, button2, button3) : new(message.ServiceId, message.UserNumber, message.Id, message.ConversationId, text, button1, button2, button3); + /// + /// Creates a text response for the originating user, but not a message reply. + /// + public static TextResponse Send(this IMessage message, string text) + => message is UserMessage user + ? new(user.Service, message.UserNumber, null, message.ConversationId, text) + : new(message.ServiceId, message.UserNumber, null, message.ConversationId, text); + + /// + /// Creates a text response for the originating user, but not a message reply. + /// + public static TextResponse Send(this IMessage message, string text, Button button1, Button? button2 = default, Button? button3 = default) + => message is UserMessage user + ? new(user.Service, message.UserNumber, null, message.ConversationId, text, button1, button2, button3) + : new(message.ServiceId, message.UserNumber, null, message.ConversationId, text, button1, button2, button3); + /// /// Attempts to retrieve a single message from the specified collection. /// diff --git a/src/WhatsApp/TextResponse.cs b/src/WhatsApp/TextResponse.cs index 75ab692..8698303 100644 --- a/src/WhatsApp/TextResponse.cs +++ b/src/WhatsApp/TextResponse.cs @@ -38,7 +38,7 @@ public TextResponse(string serviceId, string userNumber, string? context, string public Button? Button2 { get; } public Button? Button3 { get; } - internal TextResponse(Service service, string userNumber, string context, string? conversationId, string text, Button? button1 = default, Button? button2 = default, Button? button3 = default) + internal TextResponse(Service service, string userNumber, string? context, string? conversationId, string text, Button? button1 = default, Button? button2 = default, Button? button3 = default) : this(service.Id, userNumber, context, conversationId, text, button1, button2, button3) => this.service = service as CompositeService;