Skip to content

Commit bcd60bf

Browse files
committed
Prepare v0.5.0 release
1 parent 8113e67 commit bcd60bf

3 files changed

Lines changed: 83 additions & 5 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,41 @@ export TERMII_API_KEY="your-termii-api-key"
411411
dotnet run --project examples/Termii.Examples
412412
```
413413

414+
Run the offline webhook signature example:
415+
416+
```bash
417+
export TERMII_EXAMPLE_ACTION="webhook-signature"
418+
dotnet run --project examples/Termii.Examples
419+
```
420+
414421
Run a live balance example:
415422

416423
```bash
424+
export TERMII_API_KEY="your-termii-api-key"
417425
export TERMII_EXAMPLE_ACTION="balance"
418426
dotnet run --project examples/Termii.Examples
419427
```
420428

429+
List phonebooks with a read-only live example:
430+
431+
```bash
432+
export TERMII_API_KEY="your-termii-api-key"
433+
export TERMII_EXAMPLE_ACTION="phonebooks-list"
434+
dotnet run --project examples/Termii.Examples
435+
```
436+
437+
List campaigns with a read-only live example:
438+
439+
```bash
440+
export TERMII_API_KEY="your-termii-api-key"
441+
export TERMII_EXAMPLE_ACTION="campaigns-list"
442+
dotnet run --project examples/Termii.Examples
443+
```
444+
421445
Send a live Number API example message:
422446

423447
```bash
448+
export TERMII_API_KEY="your-termii-api-key"
424449
export TERMII_EXAMPLE_ACTION="number-message"
425450
export TERMII_EXAMPLE_PHONE_NUMBER="2348012345678"
426451
dotnet run --project examples/Termii.Examples

examples/Termii.Examples/Program.cs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
using System.Security.Cryptography;
2+
using System.Text;
13
using Termii;
24

5+
var action = Environment.GetEnvironmentVariable("TERMII_EXAMPLE_ACTION");
6+
7+
if (string.Equals(action, "webhook-signature", StringComparison.OrdinalIgnoreCase))
8+
{
9+
const string payload = """{"type":"delivery_report","message_id":"msg-123","status":"delivered"}""";
10+
const string secretKey = "example-webhook-secret";
11+
var signature = CreateWebhookSignature(payload, secretKey);
12+
var verified = TermiiWebhookSignature.Verify(payload, signature, secretKey);
13+
14+
Console.WriteLine($"Webhook signature verified: {verified}");
15+
return;
16+
}
17+
318
var apiKey = Environment.GetEnvironmentVariable("TERMII_API_KEY");
419

520
if (string.IsNullOrWhiteSpace(apiKey))
621
{
7-
Console.WriteLine("Set TERMII_API_KEY to run the Termii examples.");
22+
Console.WriteLine("Set TERMII_API_KEY to run live Termii examples.");
23+
Console.WriteLine("Set TERMII_EXAMPLE_ACTION=webhook-signature to run the offline webhook signature example.");
824
return;
925
}
1026

@@ -15,7 +31,6 @@
1531

1632
Console.WriteLine($"Termii client configured for {client.Options.BaseUrl}.");
1733

18-
var action = Environment.GetEnvironmentVariable("TERMII_EXAMPLE_ACTION");
1934
var phoneNumber = Environment.GetEnvironmentVariable("TERMII_EXAMPLE_PHONE_NUMBER");
2035

2136
if (string.Equals(action, "balance", StringComparison.OrdinalIgnoreCase))
@@ -26,6 +41,30 @@
2641
return;
2742
}
2843

44+
if (string.Equals(action, "phonebooks-list", StringComparison.OrdinalIgnoreCase))
45+
{
46+
var phonebooks = await client.Campaigns.GetPhonebooksAsync(new GetPhonebooksRequest
47+
{
48+
Page = 0,
49+
Size = 10,
50+
});
51+
52+
Console.WriteLine($"Phonebooks returned: {phonebooks.Content.Count}");
53+
return;
54+
}
55+
56+
if (string.Equals(action, "campaigns-list", StringComparison.OrdinalIgnoreCase))
57+
{
58+
var campaigns = await client.Campaigns.GetCampaignsAsync(new GetCampaignsRequest
59+
{
60+
Page = 0,
61+
Size = 10,
62+
});
63+
64+
Console.WriteLine($"Campaigns returned: {campaigns.Content.Count}");
65+
return;
66+
}
67+
2968
if (string.Equals(action, "number-message", StringComparison.OrdinalIgnoreCase))
3069
{
3170
if (string.IsNullOrWhiteSpace(phoneNumber))
@@ -44,4 +83,18 @@
4483
return;
4584
}
4685

47-
Console.WriteLine("Set TERMII_EXAMPLE_ACTION=balance or TERMII_EXAMPLE_ACTION=number-message to run a live example.");
86+
Console.WriteLine("Set TERMII_EXAMPLE_ACTION to one of: balance, phonebooks-list, campaigns-list, number-message, webhook-signature.");
87+
88+
static string CreateWebhookSignature(string payload, string secretKey)
89+
{
90+
using var hmac = new HMACSHA512(Encoding.UTF8.GetBytes(secretKey));
91+
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(payload));
92+
var builder = new StringBuilder(hash.Length * 2);
93+
94+
foreach (var value in hash)
95+
{
96+
builder.Append(value.ToString("x2"));
97+
}
98+
99+
return builder.ToString();
100+
}

src/Termii/Termii.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<AssemblyName>Termii</AssemblyName>
55
<RootNamespace>Termii</RootNamespace>
66
<PackageId>Termii.SDK</PackageId>
7-
<VersionPrefix>0.4.0</VersionPrefix>
7+
<VersionPrefix>0.5.0</VersionPrefix>
88
<Description>A .NET SDK for the Termii messaging, token, and insights APIs, compatible with .NET Core 3.1 through .NET 10.</Description>
9-
<PackageReleaseNotes>Add Campaign phonebook APIs, product notification email API, and WhatsApp template message APIs.</PackageReleaseNotes>
9+
<PackageReleaseNotes>Add Contacts APIs, full Campaign APIs, webhook signature verification, and expanded examples.</PackageReleaseNotes>
1010
<PackageTags>termii;sms;otp;messaging;dotnet;sdk;netstandard2.0;netcoreapp3.1;net10</PackageTags>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1212
<NoWarn>$(NoWarn);1591</NoWarn>

0 commit comments

Comments
 (0)