-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add linking in README.md (#54)
* feat: add example of using sinch options * feat: add list active numbers example * chore: add HandlingExceptions.cs example * chore: replace code with permalink
- Loading branch information
Showing
5 changed files
with
88 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Sinch; | ||
using Sinch.SMS; | ||
using Sinch.SMS.Batches.Send; | ||
|
||
namespace Examples | ||
{ | ||
public class HandlingExceptions | ||
{ | ||
public async Task Example() | ||
{ | ||
// for the sake of example, no real logger is created. | ||
var logger = LoggerFactory.Create(x => { }).CreateLogger("example"); | ||
var sinch = new SinchClient(Environment.GetEnvironmentVariable("SINCH_PROJECT_ID")!, | ||
Environment.GetEnvironmentVariable("SINCH_KEY_ID")!, | ||
Environment.GetEnvironmentVariable("SINCH_KEY_SECRET")! | ||
); | ||
|
||
try | ||
{ | ||
var batch = await sinch.Sms.Batches.Send(new SendTextBatchRequest() | ||
{ | ||
Body = "Hello, World!", | ||
DeliveryReport = DeliveryReport.None, | ||
To = new List<string>() | ||
{ | ||
"+48000000" | ||
} | ||
}); | ||
} | ||
catch (SinchApiException e) | ||
{ | ||
logger.LogError("Api Exception. Status: {status}. Detailed message: {message}", e.Status, | ||
e.DetailedMessage); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Sinch; | ||
using Sinch.Numbers; | ||
using Sinch.Numbers.Active.List; | ||
|
||
namespace Examples; | ||
|
||
public class ListActiveNumbers | ||
{ | ||
public async Task Example() | ||
{ | ||
var sinch = new SinchClient(Environment.GetEnvironmentVariable("SINCH_PROJECT_ID")!, | ||
Environment.GetEnvironmentVariable("SINCH_KEY_ID")!, | ||
Environment.GetEnvironmentVariable("SINCH_KEY_SECRET")! | ||
); | ||
ListActiveNumbersResponse response = await sinch.Numbers.Active.List(new ListActiveNumbersRequest | ||
{ | ||
RegionCode = "US", | ||
Type = Types.Mobile | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Sinch; | ||
|
||
namespace Examples; | ||
|
||
public class UsingSinchOptions | ||
{ | ||
public void Example() | ||
{ | ||
var sinch = new SinchClient(Environment.GetEnvironmentVariable("SINCH_PROJECT_ID")!, | ||
Environment.GetEnvironmentVariable("SINCH_KEY_ID")!, | ||
Environment.GetEnvironmentVariable("SINCH_KEY_SECRET")!, | ||
options => | ||
{ | ||
options.SmsHostingRegion = Sinch.SMS.SmsHostingRegion.Eu; | ||
options.ConversationRegion = Sinch.Conversation.ConversationRegion.Eu; | ||
}); | ||
} | ||
} |