forked from microsoftgraph/microsoft-graph-comms-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update public Sample bot doc (microsoftgraph#240)
- Loading branch information
1 parent
8e199d1
commit 18f54fb
Showing
48 changed files
with
3,776 additions
and
1,407 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29911.84 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroupCallBot", "GroupCallBot\GroupCallBot.csproj", "{5F7C79C6-4A38-4B76-B34F-18E8A2CB6046}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Common", "..\..\Common\Sample.Common\Sample.Common.csproj", "{F303240C-2CC3-43B5-A048-1ECEF27DBC8B}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0439C2B1-EFF3-4576-82B6-4A8DC35B484D}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\..\configure_cloud.ps1 = ..\..\configure_cloud.ps1 | ||
..\..\Graph.props = ..\..\Graph.props | ||
..\..\nuget.config = ..\..\nuget.config | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5F7C79C6-4A38-4B76-B34F-18E8A2CB6046}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5F7C79C6-4A38-4B76-B34F-18E8A2CB6046}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5F7C79C6-4A38-4B76-B34F-18E8A2CB6046}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5F7C79C6-4A38-4B76-B34F-18E8A2CB6046}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F303240C-2CC3-43B5-A048-1ECEF27DBC8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F303240C-2CC3-43B5-A048-1ECEF27DBC8B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F303240C-2CC3-43B5-A048-1ECEF27DBC8B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F303240C-2CC3-43B5-A048-1ECEF27DBC8B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4F2B3912-5AC8-47F6-8CD1-1F7200EE10D4} | ||
EndGlobalSection | ||
EndGlobal |
360 changes: 360 additions & 0 deletions
360
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Bot/Bot.cs
Large diffs are not rendered by default.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Bot/BotOptions.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,35 @@ | ||
// <copyright file="BotOptions.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
// </copyright> | ||
|
||
namespace Sample.GroupCallBot.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; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Controllers/ControllerConstants.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,18 @@ | ||
// <copyright file="ControllerConstants.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
// </copyright> | ||
|
||
namespace Sample.GroupCallBot.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"; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Controllers/HomeController.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,89 @@ | ||
// <copyright file="HomeController.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
// </copyright> | ||
|
||
namespace Sample.GroupCallBot.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()); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...es/V1.0Samples/StatelessSamples/GroupCallBot/Controllers/ParticipantsCallingController.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,59 @@ | ||
// <copyright file="ParticipantsCallingController.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
// </copyright> | ||
|
||
namespace Sample.GroupCallBot.Controller | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Sample.Common.Logging; | ||
using Sample.GroupCallBot.Bot; | ||
using Sample.GroupCallBot.Data; | ||
using Sample.GroupCallBot.Extensions; | ||
using Microsoft.Graph.Communications.Common; | ||
|
||
/// <summary> | ||
/// The incidents controller class. | ||
/// </summary> | ||
[Route("participantscalling")] | ||
public class ParticipantsCallingController : Controller | ||
{ | ||
private Bot bot; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ParticipantsCallingController" /> class. | ||
/// </summary> | ||
/// <param name="bot">The bot.</param> | ||
public ParticipantsCallingController(Bot bot, SampleObserver observer) | ||
{ | ||
this.bot = bot; | ||
} | ||
|
||
/// <summary> | ||
/// Raise a request to call participants. | ||
/// </summary> | ||
/// <param name="participantsCallingRequestData">The incident data.</param> | ||
/// <returns>The action result.</returns> | ||
/// | ||
[HttpPost("raise")] | ||
public async Task<IActionResult> PostNotificationsAsync([FromBody] ParticipantsCallingRequestData participantsCallingRequestData) | ||
{ | ||
try | ||
{ | ||
Validator.NotNull(participantsCallingRequestData, nameof(participantsCallingRequestData), "participantsCallingRequestData is Null."); | ||
Validator.NotNull(participantsCallingRequestData.ObjectIds, nameof(participantsCallingRequestData.ObjectIds), "Object Ids are Null or Whitespace."); | ||
Validator.NotNullOrWhitespace(participantsCallingRequestData.TenantId, nameof(participantsCallingRequestData.TenantId), "Tenant Id is Null or Whitespace."); | ||
|
||
await this.bot.BotCallsUsersAsync(participantsCallingRequestData).ConfigureAwait(false); | ||
|
||
return this.Ok("Bot got a notification to call group of users."); | ||
} | ||
catch (Exception e) | ||
{ | ||
return this.Exception(e); | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Controllers/PlatformCallController.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,42 @@ | ||
// <copyright file="PlatformCallController.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
// </copyright> | ||
|
||
namespace Sample.GroupCallBot.Controller | ||
{ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Graph.Communications.Common.Telemetry; | ||
using Sample.GroupCallBot.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); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Data/ParticipantsCallingRequestData.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,26 @@ | ||
// <copyright file="ParkingNotificationRequestData.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
// </copyright> | ||
|
||
namespace Sample.GroupCallBot.Data | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// The participants request data. | ||
/// </summary> | ||
public class ParticipantsCallingRequestData | ||
{ | ||
/// <summary> | ||
/// Gets or sets the notified user object ids. | ||
/// </summary> | ||
public IEnumerable<string> ObjectIds { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the tenant id. | ||
/// </summary> | ||
public string TenantId { get; set; } | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Samples/V1.0Samples/StatelessSamples/GroupCallBot/Extensions/BotBuilderExtensions.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,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.GroupCallBot.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>(); | ||
} | ||
} | ||
} |
Oops, something went wrong.