-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Vonage/add-messages-sandbox-snippets
Adding Messages Sandbox examples
- Loading branch information
Showing
6 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
DotNetCliCodeSnippets/Messages/Sandbox/Messenger/SendMessengerText.cs
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,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Messages.Messenger; | ||
using Vonage.Request; | ||
|
||
namespace DotnetCliCodeSnippets.Messages.Messenger; | ||
|
||
public class SendMessengerText : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var messagesSandboxAllowListedFbRecipientId = Environment.GetEnvironmentVariable("MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID") ?? "MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID"; | ||
var messagesSandboxFbId = Environment.GetEnvironmentVariable("MESSAGES_SANDBOX_FB_ID") ?? "MESSAGES_SANDBOX_FB_ID"; | ||
var appId = Environment.GetEnvironmentVariable("VONAGE_APP_ID") ?? "VONAGE_APP_ID"; | ||
var privateKeyPath = Environment.GetEnvironmentVariable("VONAGE_PRIVATE_KEY_PATH") ?? "VONAGE_PRIVATE_KEY_PATH"; | ||
|
||
// Set "Url.Api" to "https://messages-sandbox.nexmo.com" in appsettings.json | ||
var credentials = Credentials.FromAppIdAndPrivateKeyPath(appId, privateKeyPath); | ||
|
||
var vonageClient = new VonageClient(credentials); | ||
|
||
var request = new MessengerTextRequest | ||
{ | ||
To = messagesSandboxAllowListedFbRecipientId, | ||
From = messagesSandboxFbId, | ||
Text = "This is a Facebook Messenger Message sent from the Messages API via the Messages Sandbox" | ||
}; | ||
|
||
var response = await vonageClient.MessagesClient.SendAsync(request); | ||
Console.WriteLine($"Message UUID: {response.MessageUuid}"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
DotNetCliCodeSnippets/Messages/Sandbox/Viber/SendViberText.cs
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,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Messages.Viber; | ||
using Vonage.Request; | ||
|
||
namespace DotnetCliCodeSnippets.Messages.Sms; | ||
|
||
public class SendViberText : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var messagesSandboxAllowListedToNumber = Environment.GetEnvironmentVariable("MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER") ?? "MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER"; | ||
var messagesSandboxViberServiceId = Environment.GetEnvironmentVariable("MESSAGES_SANDBOX_VIBER_SERVICE_ID") ?? "MESSAGES_SANDBOX_VIBER_SERVICE_ID"; | ||
var appId = Environment.GetEnvironmentVariable("VONAGE_APP_ID") ?? "VONAGE_APP_ID"; | ||
var privateKeyPath = Environment.GetEnvironmentVariable("VONAGE_PRIVATE_KEY_PATH") ?? "VONAGE_PRIVATE_KEY_PATH"; | ||
|
||
// Set "Url.Api" to "https://messages-sandbox.nexmo.com" in appsettings.json | ||
var credentials = Credentials.FromAppIdAndPrivateKeyPath(appId, privateKeyPath); | ||
|
||
var vonageClient = new VonageClient(credentials); | ||
|
||
var request = new ViberTextRequest | ||
{ | ||
To = messagesSandboxAllowListedToNumber, | ||
From = messagesSandboxViberServiceId, | ||
Text = "An SMS sent using the Vonage Messages API via the Messages Sandbox" | ||
}; | ||
|
||
var response = await vonageClient.MessagesClient.SendAsync(request); | ||
Console.WriteLine($"Message UUID: {response.MessageUuid}"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
DotNetCliCodeSnippets/Messages/Sandbox/WhatsApp/SendWhatsAppText.cs
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,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Messages.WhatsApp; | ||
using Vonage.Request; | ||
|
||
namespace DotnetCliCodeSnippets.Messages.WhatsApp; | ||
|
||
public class SendWhatsAppText : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var messagesSandboxAllowListedToNumber = Environment.GetEnvironmentVariable("MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER") ?? "MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER"; | ||
var messagesSandboxWhatsAppNumber = Environment.GetEnvironmentVariable("MESSAGES_SANDBOX_WHATSAPP_NUMBER") ?? "MESSAGES_SANDBOX_WHATSAPP_NUMBER"; | ||
var appId = Environment.GetEnvironmentVariable("VONAGE_APP_ID") ?? "VONAGE_APP_ID"; | ||
var privateKeyPath = Environment.GetEnvironmentVariable("VONAGE_PRIVATE_KEY_PATH") ?? "VONAGE_PRIVATE_KEY_PATH"; | ||
|
||
// Set "Url.Api" to "https://messages-sandbox.nexmo.com" in appsettings.json | ||
var credentials = Credentials.FromAppIdAndPrivateKeyPath(appId, privateKeyPath); | ||
|
||
var vonageClient = new VonageClient(credentials); | ||
|
||
var request = new WhatsAppTextRequest | ||
{ | ||
To = messagesSandboxAllowListedToNumber, | ||
From = messagesSandboxWhatsAppNumber, | ||
Text = "A WhatsApp text message sent using the Vonage Messages API via the Messages Sandbox" | ||
}; | ||
|
||
var response = await vonageClient.MessagesClient.SendAsync(request); | ||
Console.WriteLine($"Message UUID: {response.MessageUuid}"); | ||
} | ||
} |
File renamed without changes.
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