Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication service fix #57

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8b4cc58
ChatQuickstart
lookinnovative Jun 25, 2022
3f1937e
AccessTokensQuickstart
lookinnovative Jun 25, 2022
6ceac4d
CommunicationsAccessTokensQuickstart
lookinnovative Jun 25, 2022
b750384
update
lookinnovative Jun 25, 2022
3b6f849
modified
lookinnovative Jun 26, 2022
286bb4f
modified
lookinnovative Jun 26, 2022
4ccb2bf
ADquickstart
lookinnovative Jun 28, 2022
9feb704
send-email
lookinnovative Jun 28, 2022
36d2419
add-chat
lookinnovative Aug 10, 2022
013f548
send-email
lookinnovative Aug 11, 2022
96d7144
Merge branch 'main' of https://github.com/lookinnovative/communicatio…
lookinnovative Aug 11, 2022
8f96956
send-email
lookinnovative Aug 11, 2022
85a94cb
send-email
lookinnovative Aug 11, 2022
2ed13b8
outbound-call
lookinnovative Aug 11, 2022
a17a14e
calling-quickstart
lookinnovative Aug 12, 2022
3f2ed42
calling-quickstart
lookinnovative Aug 12, 2022
da62889
programcs
lookinnovative Aug 12, 2022
0c4279c
commit
lookinnovative Aug 12, 2022
aeecf66
csproj
lookinnovative Aug 12, 2022
b2dd637
changes
lookinnovative Aug 12, 2022
b004847
calling-quickstart
lookinnovative Aug 12, 2022
8f1d668
accesstoken
lookinnovative Aug 12, 2022
7909ada
sms
lookinnovative Aug 12, 2022
af94384
sms-send
lookinnovative Aug 14, 2022
f1cb131
version10
lookinnovative Aug 14, 2022
e6d8893
debug
lookinnovative Aug 14, 2022
0ff45d8
debugext
lookinnovative Aug 14, 2022
03b2380
voice-calling
lookinnovative Aug 15, 2022
060d89f
calling-quickstart-app
lookinnovative Aug 15, 2022
011e722
video-call
lookinnovative Aug 15, 2022
92e1193
launch
lookinnovative Aug 16, 2022
2267b2d
integratedTerminal
lookinnovative Aug 16, 2022
aa47dbb
app-client-id
lookinnovative Aug 28, 2022
f302494
ChatQuickStart
lookinnovative Aug 28, 2022
0f71d10
SendEmail
lookinnovative Aug 28, 2022
63c7d9c
authenticate
lookinnovative Aug 28, 2022
8423551
Merge branch 'Azure-Samples:main' into main
lookinnovative Sep 22, 2022
2a380f6
Merge branch 'main' into Communication-service-fix
lookinnovative Oct 31, 2022
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
7 changes: 6 additions & 1 deletion AccessTokensQuickstart/AccessTokensQuickstart.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>


<PackageReference Include="Azure.Communication.Identity" Version="1.2.0" />
<PackageReference Include="Azure.Identity" Version="1.4.1" />

</ItemGroup>

</Project>
70 changes: 9 additions & 61 deletions AccessTokensQuickstart/Program.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,20 @@
using System;
using Azure.Identity;
using Azure.Communication.Identity;
using Azure.Core;
using Azure.Communication;
using Azure;
using Azure.Core;
using Azure.Communication.Identity;





namespace AccessTokensQuickstart
{
class Program
{
static async System.Threading.Tasks.Task Main(string[] args)
{
Console.WriteLine("Azure Communication Services - Access Tokens Quickstart");

// Authenticate the client
// This code demonstrates how to fetch your connection string
// from an environment variable.
string connectionString = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_CONNECTION_STRING");
var client = new CommunicationIdentityClient(connectionString);

// This code demonstrates how to fetch your endpoint and access key
// from an environment variable.
/*string endpoint = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_ENDPOINT");
string accessKey = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_ACCESSKEY");
var client = new CommunicationIdentityClient(new Uri(endpoint), new AzureKeyCredential(accessKey));*/

// Update documentation with URI details
/*TokenCredential tokenCredential = new DefaultAzureCredential();
string endPoint = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_ENDPOINT");
var client = new CommunicationIdentityClient(new Uri(endPoint), tokenCredential);*/

// Create an identity
var identityResponse = await client.CreateUserAsync();
var identity = identityResponse.Value;
Console.WriteLine($"\nCreated an identity with ID: {identity.Id}");

// Issue an access token with a validity of 24 hours and the "voip" scope for an identity
var tokenResponse = await client.GetTokenAsync(identity, scopes: new[] { CommunicationTokenScope.VoIP });
var token = tokenResponse.Value.Token;
var expiresOn = tokenResponse.Value.ExpiresOn;
Console.WriteLine($"\nIssued an access token with 'voip' scope that expires at {expiresOn}:");
Console.WriteLine(token);

// Issue an access token with a validity of an hour and the "voip" scope for an identity
TimeSpan tokenExpiresIn = TimeSpan.FromHours(1);
CommunicationTokenScope[] scopes = new[] { CommunicationTokenScope.VoIP };
tokenResponse = await client.GetTokenAsync(identity, scopes, tokenExpiresIn);

// Issue an identity and an access token with a validity of 24 hours and the "voip" scope for the new identity
var identityAndTokenResponse = await client.CreateUserAndTokenAsync(scopes: new[] { CommunicationTokenScope.VoIP });
identity = identityAndTokenResponse.Value.User;
token = identityAndTokenResponse.Value.AccessToken.Token;
expiresOn = identityAndTokenResponse.Value.AccessToken.ExpiresOn;
Console.WriteLine($"\nCreated an identity with ID: {identity.Id}");
Console.WriteLine($"\nIssued an access token with 'voip' scope that expires at {expiresOn}:");
Console.WriteLine(token);

// Refresh access tokens
var identityToRefresh = new CommunicationUserIdentifier(identity.Id);
var refreshTokenResponse = await client.GetTokenAsync(identityToRefresh, scopes: new[] { CommunicationTokenScope.VoIP });

// Revoke access tokens
await client.RevokeTokensAsync(identity);
Console.WriteLine($"\nSuccessfully revoked all access tokens for identity with ID: {identity.Id}");

Console.WriteLine("Azure Communication Services - Access Tokens Quickstart"); // This code demonstrates how to retrieve your connection string // from an environment variable. //string connectionString = Environment.GetEnvironmentVariable("https://verizann-media.communication.azure.com/;accesskey=EQHWAYFO9E0NNcj8OZEFHcVtFWUa1EBEV4tsgX1ej53kJjv4v9ZgBLVotnwhKRtjTxdIf2UEq4xoJ5n/on5IYA=="); string connectionString = "endpoint=https://verizann-media.communication.azure.com/;accesskey=EQHWAYFO9E0NNcj8OZEFHcVtFWUa1EBEV4tsgX1ej53kJjv4v9ZgBLVotnwhKRtjTxdIf2UEq4xoJ5n/on5IYA=="; var client = new CommunicationIdentityClient(connectionString); var identityResponse = await client.CreateUserAsync(); var identity = identityResponse.Value; Console.WriteLine($"\nCreated an identity with ID: {​​​​​​identity.Id}​​​​​​"); // Issue an access token with the "voip" scope for an identity var tokenResponse = await client.GetTokenAsync(identity, scopes: new[] {​​​​​​ CommunicationTokenScope.VoIP }​​​​​​); // Get the token from the response var token = tokenResponse.Value.Token; var expiresOn = tokenResponse.Value.ExpiresOn; // Write the token details to the screen Console.WriteLine($"\nIssued an access token with 'voip' scope that expires at {​​​​​​expiresOn}​​​​​​:"); Console.WriteLine(token);

// Delete an identity
await client.DeleteUserAsync(identity);
Console.WriteLine($"\nDeleted the identity with ID: {identity.Id}");
}
}
}
}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Communication.Identity" Version="1.0.1" />
<PackageReference Include="Azure.Communication.Sms" Version="1.0.1" />
<PackageReference Include="Azure.Identity" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.2.0" />
</ItemGroup>

</Project>
53 changes: 53 additions & 0 deletions ActiveDirectoryAuthenticationQuickstart/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Azure.Identity;
using Azure.Communication.Identity;
using Azure.Communication.Sms;
using Azure.Core;
using Azure;

class Program
{
private DefaultAzureCredential credential = new DefaultAzureCredential();
static void Main(string[] args)
{
// You can find your endpoint and access key from your resource in the Azure portal
// e.g. "https://<RESOURCE_NAME>.communication.azure.com";
Uri endpoint = new("https://verizann-media.communication.azure.com/");

// We need an instance of the program class to use within this method.
Program instance = new();

Console.WriteLine("Retrieving new Access Token, using Service Principals");
Response<AccessToken> response = instance.CreateIdentityAndGetTokenAsync(endpoint);
Console.WriteLine($"Retrieved Access Token: {response.Value.Token}");

Console.WriteLine("Sending SMS using Service Principals");

// You will need a phone number from your resource to send an SMS.
SmsSendResult result = instance.SendSms(endpoint, "<Your Azure Communication Services Phone Number>", "<The Phone Number you'd like to send the SMS to.>", "Hello from Service Principals");
Console.WriteLine($"Sms id: {result.MessageId}");
Console.WriteLine($"Send Result Successful: {result.Successful}");
}
public Response<AccessToken> CreateIdentityAndGetTokenAsync(Uri resourceEndpoint)
{
var client = new CommunicationIdentityClient(resourceEndpoint, this.credential);
var identityResponse = client.CreateUser();
var identity = identityResponse.Value;

var tokenResponse = client.GetToken(identity, scopes: new[] { CommunicationTokenScope.VoIP });

return tokenResponse;
}
public SmsSendResult SendSms(Uri resourceEndpoint, string from, string to, string message)
{
SmsClient smsClient = new SmsClient(resourceEndpoint, this.credential);
SmsSendResult sendResult = smsClient.Send(
from: from,
to: to,
message: message,
new SmsSendOptions(enableDeliveryReport: true) // optional
);

return sendResult;
}

}
14 changes: 14 additions & 0 deletions ChatQuickstart/ChatQuickstart.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Communication.Chat" Version="1.1.0" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions ChatQuickstart/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Azure;
using Azure.Communication;
using Azure.Communication.Chat;
using System;

namespace ChatQuickstart
{
class Program
{
static async System.Threading.Tasks.Task Main(string[] args)
{
// Your unique Azure Communication service endpoint
Uri endpoint = new Uri(https://verizann-media.communication.azure.com);

CommunicationTokenCredential communicationTokenCredential = new CommunicationTokenCredential(<Access_Token>);
ChatClient chatClient = new ChatClient(endpoint, communicationTokenCredential);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Communication.Identity" Version="1.1.0-beta.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.36.2" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions CommunicationAccessTokensQuickstart/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Communication.Identity;
using Microsoft.Identity.Client;

string appId = "<contoso_application_id>";
string tenantId = "<contoso_tenant_id>";
string authority = $"https://login.microsoftonline.com/{tenantId}";
string redirectUri = "http://localhost";

var aadClient = PublicClientApplicationBuilder
.Create(appId)
.WithAuthority(authority)
.WithRedirectUri(redirectUri)
.Build();

string scope = "https://auth.msft.communication.azure.com/Teams.ManageCalls";

var teamsUserAadToken = await aadClient
.AcquireTokenInteractive(new List<string> { scope })
.ExecuteAsync();

// This code demonstrates how to fetch your connection string
// from an environment variable.
string connectionString = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_CONNECTION_STRING");
var client = new CommunicationIdentityClient(connectionString);

var accessToken = await client.GetTokenForTeamsUserAsync(teamsUserAadToken.AccessToken);
Console.WriteLine($"Token: {accessToken.Value.Token}");



namespace CommunicationAccessTokensQuickstart
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Azure Communication Services - Teams Access Tokens Quickstart");

// Quickstart code goes here
}
}
}

15 changes: 15 additions & 0 deletions EmailQuickstart/EmailQuickstart.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Communication.Email" Version="1.0.0-beta.1" />
<PackageReference Include="Azure.Identity" Version="1.6.1" />
</ItemGroup>

</Project>
60 changes: 60 additions & 0 deletions EmailQuickstart/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Azure;
using Azure.Communication.Email;
using Azure.Communication.Email.Models;

namespace SendEmail
{
internal class Program
{
static async Task Main(string[] args)
{

}
}
}

// This code demonstrates how to fetch your connection string
// from an environment variable.
string connectionString = Environment.GetEnvironmentVariable("endpoint=https://verizann-media.communication.azure.com/;accesskey=EQHWAYFO9E0NNcj8OZEFHcVtFWUa1EBEV4tsgX1ej53kJjv4v9ZgBLVotnwhKRtjTxdIf2UEq4xoJ5n/on5IYA==
");
EmailClient emailClient = new EmailClient(connectionString);

// This code demonstrates how to authenticate to your Communication Service resource using
// DefaultAzureCredential and the environment variables AZURE_CLIENT_ID, AZURE_TENANT_ID,
// and AZURE_CLIENT_SECRET.
string resourceEndpoint = "https://verizann-media.communication.azure.com/";
EmailClient emailClient = new EmailClient(new Uri(resourceEndpoint), new DefaultAzureCredential());

//Replace with your domain and modify the content, recipient details as required

EmailContent emailContent = new EmailContent("Welcome to Azure Communication Service Email APIs.");
emailContent.PlainText = "This email message is sent from Azure Communication Service Email using .NET SDK.";
List<EmailAddress> emailAddresses = new List<EmailAddress> { new EmailAddress("[email protected]") { DisplayName = "Anthony Robinson" }};
EmailRecipients emailRecipients = new EmailRecipients(emailAddresses);
EmailMessage emailMessage = new EmailMessage("[email protected]", emailContent, emailRecipients);
SendEmailResult emailResult = emailClient.Send(emailMessage,CancellationToken.None);

Console.WriteLine($"MessageId = {emailResult.MessageId}");

Response<SendStatusResult> messageStatus = null;
messageStatus = emailClient.GetSendStatus(emailResult.MessageId);
Console.WriteLine($"MessageStatus = {messageStatus.Value.Status}");
TimeSpan duration = TimeSpan.FromMinutes(3);
long start = DateTime.Now.Ticks;
do
{
messageStatus = emailClient.GetSendStatus(emailResult.MessageId);
if (messageStatus.Value.Status != SendStatus.Queued)
{
Console.WriteLine($"MessageStatus = {messageStatus.Value.Status}");
break;
}
Thread.Sleep(10000);
Console.WriteLine($"...");

} while (DateTime.Now.Ticks - start < duration.Ticks);
15 changes: 15 additions & 0 deletions SendSMS/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}

]
}
Loading