Skip to content

Commit 9cc8bc9

Browse files
committed
Normalize user's numbers automatically on every payload
This makes it easier to just Reply to a message or Send without having to normalize anything.
1 parent 4f45a1c commit 9cc8bc9

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/WhatsApp/User.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
/// <summary>
44
/// WhatsApp end user that either originated a message or is the target of a message.
55
/// </summary>
6-
/// <param name="Name">User's name</param>
7-
/// <param name="Number">User's phone number</param>
8-
public record User(string Name, string Number);
6+
public record User
7+
{
8+
/// <summary>
9+
/// User's name.
10+
/// </summary>
11+
public string Name { get; init; }
12+
13+
/// <summary>
14+
/// User's phone number (normalized).
15+
/// </summary>
16+
public string Number { get; init; }
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="User"/> class.
20+
/// </summary>
21+
/// <param name="name">User's name.</param>
22+
/// <param name="number">Users's number.</param>
23+
public User(string name, string number)
24+
{
25+
Name = name;
26+
Number = NormalizeNumber(number);
27+
}
28+
29+
static string NormalizeNumber(string number) =>
30+
// On the web, we don't get the 9 after 54 \o/
31+
// so for Argentina numbers, we need to remove the 9.
32+
number.StartsWith("549", StringComparison.Ordinal) ? "54" + number[3..] : number;
33+
}

0 commit comments

Comments
 (0)