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
20 changes: 18 additions & 2 deletions src/WhatsApp/MessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,37 @@ public static TypingResponse Typing(this UserMessage message)
=> new(message.Service, message.User.Number, message.Id, message.ConversationId);

/// <summary>
/// Creates a text response for the message.
/// Creates a text reply for the message.
/// </summary>
public static TextResponse Reply(this IMessage message, string text)
=> message is UserMessage user
? new(user.Service, message.UserNumber, message.Id, message.ConversationId, text)
: new(message.ServiceId, message.UserNumber, message.Id, message.ConversationId, text);

/// <summary>
/// Creates a text response with buttons for the message.
/// Creates a text reply with buttons for the message.
/// </summary>
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);

/// <summary>
/// Creates a text response for the originating user, but not a message reply.
/// </summary>
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);

/// <summary>
/// Creates a text response for the originating user, but not a message reply.
/// </summary>
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);

/// <summary>
/// Attempts to retrieve a single message from the specified collection.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/WhatsApp/TextResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down