Skip to content

Commit

Permalink
Update Sample docs to most recent version (microsoftgraph#180)
Browse files Browse the repository at this point in the history
* update sample docs

* update docs
  • Loading branch information
mathowar authored Feb 26, 2020
1 parent 5ec6202 commit a06becf
Show file tree
Hide file tree
Showing 37 changed files with 2,441 additions and 1,274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About

The Compliance Recording bot sample guides you through building, deploying and testing a bot. This sample demonstrates how a bot can receive media streams for recording.
The Compliance Recording bot sample guides you through building, deploying and testing a bot. This sample demonstrates how a bot can receive media streams for recording. Please note that the sample does not actually record. This logic is left up to the developer.

## Getting Started

Expand All @@ -11,6 +11,8 @@ This section walks you through the process of deploying and testing the sample b
### Bot Registration

1. Follow the steps in [Register Calling Bot](https://microsoftgraph.github.io/microsoft-graph-comms-samples/docs/articles/calls/register-calling-bot.html). Save the bot name, bot app id and bot secret for configuration.
* For the calling webhook, by default the notification will go to https://{your domain}/api/calling. This is configured with the `CallSignalingRoutePrefix` in [HttpRouteConstants.cs](https://github.com/microsoftgraph/microsoft-graph-comms-samples/blob/master/Samples/BetaSamples/LocalMediaSamples/ComplianceRecordingBot/FrontEnd/Http/Controllers/HttpRouteConstants.cs).
* Ignore the "Register bot in Microsoft Teams" section as the Compliance Recording bot won't be called directly. These bots are related to the policies discussed below, and are "attached" to users, and will be automatically invited to the call.

1. Add the following Application Permissions to the bot:

Expand All @@ -31,15 +33,15 @@ Open powershell (in admin mode) and run the following commands. When prompted fo

### Create a Compliance Recording Policy
Requires the application instance ID created above. Continue your powershell session and run the following commands.
* `> New-CsTeamsComplianceRecordingPolicy -Tenant <tenantId> -Enabled $true -Description "Test policy created by <yourName>" <policyIdentity>`
* ```> Set-CsTeamsComplianceRecordingPolicy -Tenant <tenantId> -Identity <policyIdentity> -ComplianceRecordingApplications ` @(New-CsTeamsComplianceRecordingApplication -Tenant <tenantId> -Parent <policyIdentity> -Id <objectId>)```
* `> New-CsTeamsComplianceRecordingPolicy -Enabled $true -Description "Test policy created by <yourName>" <policyIdentity>`
* ```> Set-CsTeamsComplianceRecordingPolicy -Identity <policyIdentity> -ComplianceRecordingApplications ` @(New-CsTeamsComplianceRecordingApplication -Parent <policyIdentity> -Id <objectId>)```

After 30-60 seconds, the policy should show up. To verify your policy was created correctly:
* `> Get-CsTeamsComplianceRecordingPolicy <policyIdentity>`

### Assign the Compliance Recording Policy
Requries the policy identity created above. Contine your powershell session and run the following commands.
* `> Grant-CsTeamsComplianceRecordingPolicy -Identity <[email protected]> -PolicyName <policyIdentity> -Tenant <tenantId>`
* `> Grant-CsTeamsComplianceRecordingPolicy -Identity <[email protected]> -PolicyName <policyIdentity>`

To verify your policy was assigned correctly:
* `> Get-CsOnlineUser <[email protected]> | ft sipaddress, tenantid, TeamsComplianceRecordingPolicy`
Expand Down
464 changes: 464 additions & 0 deletions Samples/V1.0Samples/StatelessSamples/SimpleIvrBot/Bot/Bot.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <copyright file="BotOptions.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Sample.SimpleIvrBot.Bot
{
using System;

/// <summary>
/// The bot options class.
/// </summary>
public class BotOptions
{
/// <summary>
/// Gets or sets the application id.
/// </summary>
public string AppId { get; set; }

/// <summary>
/// Gets or sets the application secret.
/// </summary>
public string AppSecret { get; set; }

/// <summary>
/// Gets or sets the calls uri of the application.
/// </summary>
public Uri BotBaseUrl { get; set; }

/// <summary>
/// Gets or sets the comms platform endpoint uri.
/// </summary>
public Uri PlaceCallEndpointUrl { get; set; }

/// <summary>
/// Gets or sets cosmosDB Configuraiton account uri.
/// </summary>
public string CosmosDBAccountUri { get; set; }

/// <summary>
/// Gets or sets cosmosDB Configuraiton account key.
/// </summary>
public string CosmosDBAccountKey { get; set; }

/// <summary>
/// Gets or sets cosmosDB Configuraiton database name.
/// </summary>
public string CosmosDBDatabaseName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// <copyright file="ControllerConstants.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Sample.SimpleIvrBot.Controller
{
/// <summary>
/// Http route constants for routing requests.
/// </summary>
public class ControllerConstants
{
/// <summary>
/// Route prefix for all incoming requests.
/// </summary>
public const string CallbackPrefix = "/callback";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// <copyright file="HomeController.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Sample.SimpleIvrBot.Controller
{
using Microsoft.AspNetCore.Mvc;
using Sample.Common.Logging;

/// <summary>
/// The home controller class.
/// </summary>
public class HomeController : Controller
{
private readonly SampleObserver observer;

/// <summary>
/// Initializes a new instance of the <see cref="HomeController"/> class.
/// </summary>
/// <param name="observer">The observer.</param>
public HomeController(SampleObserver observer)
{
this.observer = observer;
}

/// <summary>
/// Get the default content of home page.
/// </summary>
/// <returns>Default content.</returns>
[HttpGet("/")]
public string Get()
{
return "Home Page";
}

/// <summary>
/// Get the service logs.
/// </summary>
/// <param name="skip">Skip specified lines.</param>
/// <param name="take">Take specified lines.</param>
/// <returns>The logs.</returns>
[HttpGet]
[Route("/logs")]
public IActionResult GetLogs(
[FromQuery] int skip = 0,
[FromQuery] int take = 1000)
{
this.AddRefreshHeader(3);
return this.Content(
this.observer.GetLogs(skip, take),
System.Net.Mime.MediaTypeNames.Text.Plain,
System.Text.Encoding.UTF8);
}

/// <summary>
/// Get the service logs.
/// </summary>
/// <param name="filter">The filter.</param>
/// <param name="skip">Skip specified lines.</param>
/// <param name="take">Take specified lines.</param>
/// <returns>
/// The logs.
/// </returns>
[HttpGet]
[Route("/logs/{filter}")]
public IActionResult GetLogs(
string filter,
[FromQuery] int skip = 0,
[FromQuery] int take = 1000)
{
this.AddRefreshHeader(3);
return this.Content(
this.observer.GetLogs(filter, skip, take),
System.Net.Mime.MediaTypeNames.Text.Plain,
System.Text.Encoding.UTF8);
}

/// <summary>
/// Add refresh headers for browsers to download content.
/// </summary>
/// <param name="seconds">Refresh rate.</param>
private void AddRefreshHeader(int seconds)
{
this.Response.Headers.Add("Cache-Control", "private,must-revalidate,post-check=1,pre-check=2,no-cache");
this.Response.Headers.Add("Refresh", seconds.ToString());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <copyright file="PlatformCallController.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Sample.SimpleIvrBot.Controller
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Graph.Communications.Common.Telemetry;
using Sample.SimpleIvrBot.Bot;

/// <summary>
/// Entry point for handling call-related web hook requests.
/// </summary>
public class PlatformCallController : Controller
{
private readonly IGraphLogger graphLogger;
private readonly Bot bot;

/// <summary>
/// Initializes a new instance of the <see cref="PlatformCallController"/> class.
/// </summary>
/// <param name="bot">The bot.</param>
public PlatformCallController(Bot bot)
{
this.bot = bot;
this.graphLogger = bot.GraphLogger.CreateShim(nameof(PlatformCallController));
}

/// <summary>
/// Handle call back for bot calls user case.
/// </summary>
/// <returns>returns when task is done.</returns>
[HttpPost]
[Route(ControllerConstants.CallbackPrefix)]
public async Task OnIncomingBotCallUserRequestAsync()
{
await this.bot.ProcessNotificationAsync(this.Request, this.Response).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// <copyright file="ConfigurationManager.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Sample.SimpleIvrBot.Data
{
using System.IO;
using Microsoft.Extensions.Configuration;

/// <summary>
/// The incident request data.
/// </summary>
public static class ConfigurationManager
{
/// <summary>
/// Gets the AppSetting data.
/// </summary>
public static IConfiguration AppSetting { get; }

#pragma warning disable SA1201 // Elements should appear in the correct order
/// <summary>
/// Initializes static members of the <see cref="ConfigurationManager"/> class.
/// </summary>
static ConfigurationManager()
#pragma warning restore SA1201 // Elements should appear in the correct order
{
AppSetting = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <copyright file="BotBuilderExtensions.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Microsoft.Extensions.DependencyInjection
{
using System;
using Sample.SimpleIvrBot.Bot;

/// <summary>
/// The bot builder extensions class.
/// </summary>
public static class BotBuilderExtensions
{
/// <summary>
/// Add bot feature.
/// </summary>
/// <param name="services">The service collection.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddBot(this IServiceCollection services)
=> services.AddBot(_ => { });

/// <summary>
/// Add bot feature.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="botOptionsAction">The action for bot options.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddBot(this IServiceCollection services, Action<BotOptions> botOptionsAction)
{
var options = new BotOptions();
botOptionsAction(options);
services.AddSingleton(options);

return services.AddSingleton<Bot>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <copyright file="ControllerExtentions.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// </copyright>

namespace Sample.SimpleIvrBot.Extensions
{
using System;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.Graph;

/// <summary>
/// The controller exceptions.
/// </summary>
public static class ControllerExtentions
{
/// <summary>
/// Convert exception to action result.
/// </summary>
/// <param name="controller">The controller.</param>
/// <param name="exception">The exception.</param>
/// <returns>The action result.</returns>
public static IActionResult Exception(this Controller controller, Exception exception)
{
IActionResult result;

if (exception is ServiceException e)
{
controller.HttpContext.Response.CopyHeaders(e.ResponseHeaders);

int statusCode = (int)e.StatusCode;

result = statusCode >= 300
? controller.StatusCode(statusCode, e.ToString())
: controller.StatusCode((int)HttpStatusCode.InternalServerError, e.ToString());
}
else
{
result = controller.StatusCode((int)HttpStatusCode.InternalServerError, exception.ToString());
}

return result;
}

/// <summary>
/// Copy the response headers to controller.HttpContext.Response.
/// </summary>
/// <param name="response">The controller.</param>
/// <param name="headers">The headers.</param>
private static void CopyHeaders(this HttpResponse response, HttpHeaders headers)
{
if (headers == null)
{
// do nothing as the source headers are null.
return;
}

foreach (var header in headers)
{
var values = header.Value?.ToArray();
if (values?.Any() == true)
{
response.Headers.Add(header.Key, new StringValues(values));
}
}
}
}
}
Loading

0 comments on commit a06becf

Please sign in to comment.