├── .gitignore
├── LICENSE
├── README.md
├── SECURITY.md
├── Samples
├── Csharp
│ ├── CognitiveServices-Knowledge
│ │ └── QnA
│ │ │ ├── .gitignore
│ │ │ ├── Qna_Bot.sln
│ │ │ ├── Qna_Bot
│ │ │ ├── AppSettings.cs
│ │ │ ├── App_Start
│ │ │ │ └── WebApiConfig.cs
│ │ │ ├── Controllers
│ │ │ │ └── MessagesController.cs
│ │ │ ├── Dialogs
│ │ │ │ └── RootDialog.cs
│ │ │ ├── Global.asax
│ │ │ ├── Global.asax.cs
│ │ │ ├── Properties
│ │ │ │ ├── AssemblyInfo.cs
│ │ │ │ ├── Resources.Designer.cs
│ │ │ │ └── Resources.resx
│ │ │ ├── QnAService
│ │ │ │ ├── Answer.cs
│ │ │ │ ├── Client.cs
│ │ │ │ └── RootResponse.cs
│ │ │ ├── Qna_Bot.csproj
│ │ │ ├── Utils
│ │ │ │ └── WelcomeCard.cs
│ │ │ ├── Web.config
│ │ │ ├── default.htm
│ │ │ └── packages.config
│ │ │ ├── README.md
│ │ │ ├── assets
│ │ │ ├── create-kb.png
│ │ │ ├── generate-answer.png
│ │ │ ├── kb-keys.png
│ │ │ ├── no-match.png
│ │ │ └── publish-kb.png
│ │ │ └── azuredeploy.json
│ ├── CognitiveServices-Language
│ │ └── Fridge
│ │ │ ├── .gitignore
│ │ │ ├── FridgeBot.sln
│ │ │ ├── FridgeBot
│ │ │ ├── App_Start
│ │ │ │ └── WebApiConfig.cs
│ │ │ ├── Controllers
│ │ │ │ └── MessagesController.cs
│ │ │ ├── Dialogs
│ │ │ │ └── IntentDialog.cs
│ │ │ ├── FridgeBot.csproj
│ │ │ ├── Global.asax
│ │ │ ├── Global.asax.cs
│ │ │ ├── Properties
│ │ │ │ ├── AssemblyInfo.cs
│ │ │ │ ├── Resources.Designer.cs
│ │ │ │ └── Resources.resx
│ │ │ ├── Utils
│ │ │ │ └── Util.cs
│ │ │ ├── Web.config
│ │ │ ├── default.htm
│ │ │ └── packages.config
│ │ │ ├── README.md
│ │ │ └── images
│ │ │ ├── LUIS_add_entity.png
│ │ │ ├── LUIS_add_intent.png
│ │ │ ├── LUIS_add_utterances.png
│ │ │ ├── LUIS_create_a_new_app.png
│ │ │ ├── LUIS_label_entity.png
│ │ │ └── LUIS_train_and_test.png
│ ├── Fundamentals
│ │ └── DoctorCode
│ │ │ ├── .gitignore
│ │ │ ├── DrCodeBot.sln
│ │ │ ├── DrCodeBot
│ │ │ ├── App_Start
│ │ │ │ └── WebApiConfig.cs
│ │ │ ├── Controllers
│ │ │ │ └── MessagesController.cs
│ │ │ ├── Dialogs
│ │ │ │ ├── GreetButtonClickDialog.cs
│ │ │ │ ├── HelpButtonClickDialog.cs
│ │ │ │ ├── HelpDialog.cs
│ │ │ │ ├── HelpScorable.cs
│ │ │ │ ├── RootDialog.cs
│ │ │ │ └── TypingButtonClickDialog.cs
│ │ │ ├── DrCodeBot.csproj
│ │ │ ├── Global.asax
│ │ │ ├── Global.asax.cs
│ │ │ ├── HelpMessageHandlerModule.cs
│ │ │ ├── Properties
│ │ │ │ ├── AssemblyInfo.cs
│ │ │ │ ├── Resources.Designer.cs
│ │ │ │ └── Resources.resx
│ │ │ ├── Utils
│ │ │ │ └── CardFactory.cs
│ │ │ ├── Web.config
│ │ │ ├── default.htm
│ │ │ └── packages.config
│ │ │ ├── README.md
│ │ │ └── azuredeploy.json
│ ├── RealtimeMedia
│ │ ├── TextToSpeech
│ │ │ ├── .gitignore
│ │ │ ├── FrontEnd
│ │ │ │ ├── CallLogic
│ │ │ │ │ ├── MediaSession.cs
│ │ │ │ │ └── RealTimeMediaCall.cs
│ │ │ │ ├── FrontEnd.csproj
│ │ │ │ ├── Http
│ │ │ │ │ ├── CallController.cs
│ │ │ │ │ ├── CallEndpointStartup.cs
│ │ │ │ │ ├── CognitiveServicesAuthentication.cs
│ │ │ │ │ ├── ExceptionLogger.cs
│ │ │ │ │ ├── HttpRouteConstants.cs
│ │ │ │ │ ├── LoggingMessageHandler.cs
│ │ │ │ │ ├── MessagesController.cs
│ │ │ │ │ └── RealTimeMediaCallingBotServiceSettings.cs
│ │ │ │ ├── IConfiguration.cs
│ │ │ │ ├── Logging
│ │ │ │ │ ├── CallerInfo.cs
│ │ │ │ │ ├── CorrelationId.cs
│ │ │ │ │ └── Log.cs
│ │ │ │ ├── MediaLogic
│ │ │ │ │ ├── AudioSendBuffer.cs
│ │ │ │ │ └── VideoSendBuffer.cs
│ │ │ │ ├── Properties
│ │ │ │ │ └── AssemblyInfo.cs
│ │ │ │ ├── Service.cs
│ │ │ │ ├── Tts
│ │ │ │ │ ├── TtsEngine.cs
│ │ │ │ │ ├── TtsEngineLocal.cs
│ │ │ │ │ └── TtsEngineService.cs
│ │ │ │ ├── Utilities.cs
│ │ │ │ ├── app.config
│ │ │ │ └── packages.config
│ │ │ ├── README.md
│ │ │ ├── ServiceConfiguration.Cloud.cscfg
│ │ │ ├── ServiceDefinition.csdef
│ │ │ ├── TextToSpeech.ccproj
│ │ │ ├── TextToSpeech.sln
│ │ │ ├── WorkerRole
│ │ │ │ ├── AzureConfiguration.cs
│ │ │ │ ├── InstallMediaFoundation.ps1
│ │ │ │ ├── InstallNETFX.cmd
│ │ │ │ ├── NDP461-KB3102438-Web.exe
│ │ │ │ ├── Properties
│ │ │ │ │ └── AssemblyInfo.cs
│ │ │ │ ├── SetupMediaFoundation.cmd
│ │ │ │ ├── WorkerRole.cs
│ │ │ │ ├── WorkerRole.csproj
│ │ │ │ ├── app.config
│ │ │ │ ├── packages.config
│ │ │ │ └── startup.cmd
│ │ │ └── WorkerRoleContent
│ │ │ │ └── diagnostics.wadcfgx
│ │ ├── TextToVideoSpeech
│ │ │ ├── .gitignore
│ │ │ ├── FrontEnd
│ │ │ │ ├── CallLogic
│ │ │ │ │ ├── MediaSession.cs
│ │ │ │ │ └── RealTimeMediaCall.cs
│ │ │ │ ├── FrontEnd.csproj
│ │ │ │ ├── Http
│ │ │ │ │ ├── CallController.cs
│ │ │ │ │ ├── CallEndpointStartup.cs
│ │ │ │ │ ├── ExceptionLogger.cs
│ │ │ │ │ ├── HttpRouteConstants.cs
│ │ │ │ │ ├── LoggingMessageHandler.cs
│ │ │ │ │ ├── MessagesController.cs
│ │ │ │ │ └── RealTimeMediaCallingBotServiceSettings.cs
│ │ │ │ ├── IConfiguration.cs
│ │ │ │ ├── Logging
│ │ │ │ │ ├── CallerInfo.cs
│ │ │ │ │ ├── CorrelationId.cs
│ │ │ │ │ └── Log.cs
│ │ │ │ ├── MediaLogic
│ │ │ │ │ ├── AudioSendBuffer.cs
│ │ │ │ │ └── VideoSendBuffer.cs
│ │ │ │ ├── Properties
│ │ │ │ │ ├── AssemblyInfo.cs
│ │ │ │ │ ├── Resources.Designer.cs
│ │ │ │ │ └── Resources.resx
│ │ │ │ ├── Resources
│ │ │ │ │ ├── avatar_AH.png
│ │ │ │ │ ├── avatar_EH.png
│ │ │ │ │ ├── avatar_FV.png
│ │ │ │ │ ├── avatar_L_TH.png
│ │ │ │ │ ├── avatar_MM.png
│ │ │ │ │ ├── avatar_OH.png
│ │ │ │ │ ├── avatar_OOH.png
│ │ │ │ │ ├── avatar_S_D_H_Z.png
│ │ │ │ │ ├── avatar_U.png
│ │ │ │ │ └── avatar_neutral.png
│ │ │ │ ├── Service.cs
│ │ │ │ ├── Ttvs
│ │ │ │ │ ├── TtvsEngine.cs
│ │ │ │ │ └── VisemesTimeline.cs
│ │ │ │ ├── Utilities.cs
│ │ │ │ ├── app.config
│ │ │ │ └── packages.config
│ │ │ ├── README.md
│ │ │ ├── ServiceConfiguration.Cloud.cscfg
│ │ │ ├── ServiceDefinition.csdef
│ │ │ ├── TextToVideoSpeech.ccproj
│ │ │ ├── TextToVideoSpeech.sln
│ │ │ ├── WorkerRole
│ │ │ │ ├── AzureConfiguration.cs
│ │ │ │ ├── InstallMediaFoundation.ps1
│ │ │ │ ├── InstallNETFX.cmd
│ │ │ │ ├── NDP461-KB3102438-Web.exe
│ │ │ │ ├── Properties
│ │ │ │ │ └── AssemblyInfo.cs
│ │ │ │ ├── SetupMediaFoundation.cmd
│ │ │ │ ├── WorkerRole.cs
│ │ │ │ ├── WorkerRole.csproj
│ │ │ │ ├── app.config
│ │ │ │ ├── packages.config
│ │ │ │ └── startup.cmd
│ │ │ └── WorkerRoleContent
│ │ │ │ └── diagnostics.wadcfgx
│ │ └── VideoPlayer
│ │ │ ├── .gitignore
│ │ │ ├── FrontEnd
│ │ │ ├── BlobDownloader.cs
│ │ │ ├── CallLogic
│ │ │ │ ├── MediaSession.cs
│ │ │ │ └── RealTimeMediaCall.cs
│ │ │ ├── FrontEnd.csproj
│ │ │ ├── Http
│ │ │ │ ├── CallController.cs
│ │ │ │ ├── CallEndpointStartup.cs
│ │ │ │ ├── ExceptionLogger.cs
│ │ │ │ ├── HttpRouteConstants.cs
│ │ │ │ ├── LoggingMessageHandler.cs
│ │ │ │ └── RealTimeMediaCallingBotServiceSettings.cs
│ │ │ ├── IConfiguration.cs
│ │ │ ├── Logging
│ │ │ │ ├── CallerInfo.cs
│ │ │ │ ├── CorrelationId.cs
│ │ │ │ └── Log.cs
│ │ │ ├── MediaLogic
│ │ │ │ ├── AudioSendBuffer.cs
│ │ │ │ └── VideoSendBuffer.cs
│ │ │ ├── Properties
│ │ │ │ └── AssemblyInfo.cs
│ │ │ ├── Service.cs
│ │ │ ├── Utilities.cs
│ │ │ ├── app.config
│ │ │ └── packages.config
│ │ │ ├── README.md
│ │ │ ├── ServiceConfiguration.Cloud.cscfg
│ │ │ ├── ServiceConfiguration.Local.cscfg
│ │ │ ├── ServiceDefinition.csdef
│ │ │ ├── VideoPlayer.ccproj
│ │ │ ├── VideoPlayer.sln
│ │ │ ├── WorkerRole
│ │ │ ├── AzureConfiguration.cs
│ │ │ ├── InstallMediaFoundation.ps1
│ │ │ ├── InstallNETFX.cmd
│ │ │ ├── NDP461-KB3102438-Web.exe
│ │ │ ├── Properties
│ │ │ │ └── AssemblyInfo.cs
│ │ │ ├── SetupMediaFoundation.cmd
│ │ │ ├── WorkerRole.cs
│ │ │ ├── WorkerRole.csproj
│ │ │ ├── app.config
│ │ │ ├── packages.config
│ │ │ └── startup.cmd
│ │ │ └── WorkerRoleContent
│ │ │ └── diagnostics.wadcfgx
│ └── Storage-MongoDB
│ │ └── Notes
│ │ ├── Bot
│ │ ├── AppSettings.cs
│ │ ├── App_Start
│ │ │ └── WebApiConfig.cs
│ │ ├── Controllers
│ │ │ └── MessagesController.cs
│ │ ├── Dialogs
│ │ │ ├── DeleteDialog.cs
│ │ │ ├── DeleteForceDialog.cs
│ │ │ ├── HelpDialog.cs
│ │ │ ├── NoteDialog.cs
│ │ │ ├── RootDialog.cs
│ │ │ └── ShowDialog.cs
│ │ ├── Global.asax
│ │ ├── Global.asax.cs
│ │ ├── Helpers
│ │ │ └── DbSingleton.cs
│ │ ├── Models
│ │ │ └── Note.cs
│ │ ├── NotesBot.csproj
│ │ ├── Properties
│ │ │ ├── AssemblyInfo.cs
│ │ │ ├── Resources.Designer.cs
│ │ │ └── Resources.resx
│ │ ├── Resources
│ │ │ └── welcome_card.png
│ │ ├── Web.config
│ │ ├── default.htm
│ │ └── packages.config
│ │ ├── NotesBot.sln
│ │ ├── README.md
│ │ └── azuredeploy.json
└── Node
│ ├── .gitignore
│ ├── CognitiveServices-Knowledge
│ └── QnA
│ │ ├── .env
│ │ ├── README.md
│ │ ├── app.js
│ │ ├── assets
│ │ ├── create-kb.png
│ │ ├── generate-answer.png
│ │ ├── kb-keys.png
│ │ ├── no-match.png
│ │ └── publish-kb.png
│ │ ├── azuredeploy.json
│ │ ├── package.json
│ │ └── src
│ │ ├── Strings.js
│ │ ├── bot
│ │ └── qnamaker.js
│ │ ├── controller
│ │ ├── faqFetcher.js
│ │ └── qnaQueryService.js
│ │ ├── dialogs
│ │ ├── answersCarousel.js
│ │ ├── askQuestion.js
│ │ ├── help.js
│ │ ├── intro.js
│ │ └── proposeQuestionsCard.js
│ │ ├── models
│ │ └── faqModel.js
│ │ └── utils
│ │ └── buildCardUtils.js
│ ├── CognitiveServices-Language
│ └── Fridge
│ │ ├── .env
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── app.js
│ │ ├── azuredeploy.json
│ │ ├── images
│ │ ├── LUIS_add_entity.png
│ │ ├── LUIS_add_intent.png
│ │ ├── LUIS_add_utterances.png
│ │ ├── LUIS_create_a_new_app.png
│ │ ├── LUIS_label_entity.png
│ │ └── LUIS_train_and_test.png
│ │ ├── package.json
│ │ ├── strings.js
│ │ └── util.js
│ ├── Fundamentals
│ └── DoctorCode
│ │ ├── .env
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── app.js
│ │ ├── azuredeploy.json
│ │ ├── package.json
│ │ └── strings.js
│ └── Storage-MongoDB
│ └── Notes
│ ├── .env
│ ├── README.md
│ ├── azuredeploy.json
│ ├── package-lock.json
│ ├── package.json
│ └── src
│ ├── App.js
│ ├── Strings.js
│ ├── bot
│ └── NoteBot.js
│ ├── models
│ └── Note.js
│ ├── store
│ ├── Database.js
│ ├── DbHelper.js
│ └── index.js
│ └── util
│ └── NoteUtil.js
└── certification
└── CHECKLIST.md
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.16
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Qna_Bot", "Qna_Bot\Qna_Bot.csproj", "{DA6B0ABD-EE3C-4CF9-BA21-BA6CA08471B7}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {DA6B0ABD-EE3C-4CF9-BA21-BA6CA08471B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {DA6B0ABD-EE3C-4CF9-BA21-BA6CA08471B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {DA6B0ABD-EE3C-4CF9-BA21-BA6CA08471B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {DA6B0ABD-EE3C-4CF9-BA21-BA6CA08471B7}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/AppSettings.cs:
--------------------------------------------------------------------------------
1 | namespace QnaBot
2 | {
3 | using System;
4 | using System.Configuration;
5 |
6 | public class AppSettings
7 | {
8 | private static Lazy _qnaBaseUrl = new Lazy(() => ConfigurationManager.AppSettings["QnABaseUrl"].ToString());
9 | private static Lazy _qnaKnowledgeBase = new Lazy(() => ConfigurationManager.AppSettings["QnAKnowledgeBaseId"].ToString());
10 | private static Lazy _qnaSubscriptionKey = new Lazy(() => ConfigurationManager.AppSettings["QnASubscriptionKey"].ToString());
11 |
12 | public static string QnABaseUrl => _qnaBaseUrl.Value;
13 | public static string QnAKnowledgebaseId => _qnaKnowledgeBase.Value;
14 | public static string QnASubscriptionKey => _qnaSubscriptionKey.Value;
15 |
16 | public const int Max_Answers = 3;
17 | public const string DirectFaqUrl = "https://azure.microsoft.com/en-us/support/faq/";
18 | }
19 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/App_Start/WebApiConfig.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Serialization;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Web.Http;
7 |
8 | namespace QnaBot
9 | {
10 | public static class WebApiConfig
11 | {
12 | public static void Register(HttpConfiguration config)
13 | {
14 | // Json settings
15 | config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
16 | config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
17 | config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
18 | JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
19 | {
20 | ContractResolver = new CamelCasePropertyNamesContractResolver(),
21 | Formatting = Newtonsoft.Json.Formatting.Indented,
22 | NullValueHandling = NullValueHandling.Ignore,
23 | };
24 |
25 | // Web API configuration and services
26 |
27 | // Web API routes
28 | config.MapHttpAttributeRoutes();
29 |
30 | config.Routes.MapHttpRoute(
31 | name: "DefaultApi",
32 | routeTemplate: "api/{controller}/{id}",
33 | defaults: new { id = RouteParameter.Optional }
34 | );
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/Controllers/MessagesController.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Net.Http;
3 | using System.Threading.Tasks;
4 | using System.Web.Http;
5 | using Microsoft.Bot.Builder.Dialogs;
6 | using Microsoft.Bot.Connector;
7 | using System.Collections.Generic;
8 | using System;
9 |
10 | namespace QnaBot
11 | {
12 | [BotAuthentication]
13 | public class MessagesController : ApiController
14 | {
15 | private static IConnectorClient connectorClient;
16 |
17 | public async Task Post([FromBody]Activity activity)
18 | {
19 | var responseMessage = string.Empty;
20 | if (activity.Type == ActivityTypes.Message)
21 | {
22 | await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
23 | }
24 | else
25 | {
26 | responseMessage = await HandleSystemMessage(activity);
27 | }
28 |
29 | var response = Request.CreateResponse(HttpStatusCode.OK, responseMessage);
30 | return response;
31 | }
32 |
33 | private static async Task HandleSystemMessage(Activity activity)
34 | {
35 | switch (activity.Type)
36 | {
37 | case ActivityTypes.ContactRelationUpdate:
38 | return await OnContactRelationUpdate(activity);
39 | }
40 |
41 | return string.Empty;
42 | }
43 |
44 | private static async Task OnContactRelationUpdate(Activity activity)
45 | {
46 | switch (activity.Action)
47 | {
48 | case ContactRelationUpdateActionTypes.Add:
49 | var welcomeCard = Utils.WelcomeCard.get(activity);
50 | return await SendMessageWithAttachments(activity, new List { welcomeCard.ToAttachment() });
51 | case ContactRelationUpdateActionTypes.Remove:
52 | // No action.
53 | break;
54 | }
55 |
56 | return null;
57 | }
58 |
59 | private static async Task SendMessageWithAttachments(Activity activity,
60 | IList attachments)
61 | {
62 | var reply = activity.CreateReply();
63 | reply.Attachments = attachments;
64 | if (connectorClient == null)
65 | {
66 | connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));
67 | }
68 |
69 | var resourceResponse = await connectorClient.Conversations.SendToConversationAsync(reply);
70 | return resourceResponse.Id;
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="QnaBot.WebApiApplication" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 | using System.Web.Http;
6 | using System.Web.Routing;
7 |
8 | namespace QnaBot
9 | {
10 | public class WebApiApplication : System.Web.HttpApplication
11 | {
12 | protected void Application_Start()
13 | {
14 | GlobalConfiguration.Configure(WebApiConfig.Register);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Qna_Bot")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Qna_Bot")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("da6b0abd-ee3c-4cf9-ba21-ba6ca08471b7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/QnAService/Answer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 |
6 | namespace QnaBot.QnAService
7 | {
8 | public class Answer
9 | {
10 | public string answer { get; set; }
11 | public List questions { get; set; }
12 | public double score { get; set; }
13 | }
14 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/QnAService/RootResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace QnaBot.QnAService
4 | {
5 | public class RootResponse
6 | {
7 | public List answers { get; set; }
8 |
9 | public bool IsValid()
10 | {
11 | var response = this;
12 | return response.answers != null &&
13 | response.answers.Count >= 1 && response.answers[0].score > 0;
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/Utils/WelcomeCard.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Bot.Connector;
2 | using QnaBot.Properties;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Web;
7 |
8 | namespace QnaBot.Utils
9 | {
10 | public class WelcomeCard
11 | {
12 | public static HeroCard get(IActivity activity)
13 | {
14 | string username = GetUsernameFromContext(activity);
15 | return GetWelcomeCard(username);
16 | }
17 |
18 | private static HeroCard GetWelcomeCard(string username)
19 | {
20 | return new HeroCard
21 | {
22 | Title = string.Format(Resources.WELCOME_TITLE, username),
23 | Text = string.Format(Resources.WELCOME_SUBTITLE, AppSettings.DirectFaqUrl),
24 | Buttons = new List
25 | {
26 | new CardAction(ActionTypes.ImBack, Resources.HELP_TEXT, value: Resources.HELP_TEXT),
27 | }
28 | };
29 | }
30 |
31 | private static string GetUsernameFromContext(IActivity context)
32 | {
33 | return !string.IsNullOrEmpty(context.From.Name) ? context.From.Name : context.From.Id;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/default.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Qna_Bot
9 | Describe your bot here and your terms of use etc.
10 | Visit Bot Framework to register your bot. When you register it, remember to set your bot's endpoint to
https://your_bots_hostname /api/messages
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/Qna_Bot/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/create-kb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/create-kb.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/generate-answer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/generate-answer.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/kb-keys.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/kb-keys.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/no-match.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/no-match.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/publish-kb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Knowledge/QnA/assets/publish-kb.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | /.vs/FridgeBot/v15/.suo
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 | .vs/
16 |
17 | # Build results
18 | [Dd]ebug/
19 | [Dd]ebugPublic/
20 | [Rr]elease/
21 | [Rr]eleases/
22 | [Xx]64/
23 | [Xx]86/
24 | [Bb]uild/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | /packages
29 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.16
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FridgeBot", "FridgeBot\FridgeBot.csproj", "{51C24E24-E90B-486C-B3C9-EE992F56672B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {51C24E24-E90B-486C-B3C9-EE992F56672B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {51C24E24-E90B-486C-B3C9-EE992F56672B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {51C24E24-E90B-486C-B3C9-EE992F56672B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {51C24E24-E90B-486C-B3C9-EE992F56672B}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/App_Start/WebApiConfig.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Serialization;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Web.Http;
7 |
8 | namespace FridgeBot
9 | {
10 | public static class WebApiConfig
11 | {
12 | public static void Register(HttpConfiguration config)
13 | {
14 | // Json settings
15 | config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
16 | config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
17 | config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
18 | JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
19 | {
20 | ContractResolver = new CamelCasePropertyNamesContractResolver(),
21 | Formatting = Newtonsoft.Json.Formatting.Indented,
22 | NullValueHandling = NullValueHandling.Ignore,
23 | };
24 |
25 | // Web API configuration and services
26 |
27 | // Web API routes
28 | config.MapHttpAttributeRoutes();
29 |
30 | config.Routes.MapHttpRoute(
31 | name: "DefaultApi",
32 | routeTemplate: "api/{controller}/{id}",
33 | defaults: new { id = RouteParameter.Optional }
34 | );
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/Controllers/MessagesController.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Net.Http;
3 | using System.Threading.Tasks;
4 | using System.Web.Http;
5 | using Microsoft.Bot.Builder.Dialogs;
6 | using Microsoft.Bot.Connector;
7 | using System;
8 | using FridgeBot.Properties;
9 |
10 | namespace FridgeBot
11 | {
12 | [BotAuthentication]
13 | public class MessagesController : ApiController
14 | {
15 | ///
16 | /// POST: api/Messages
17 | /// Receive a message from a user and reply to it
18 | ///
19 | public async Task Post([FromBody]Activity activity)
20 | {
21 | var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));
22 |
23 | if (activity.Type == ActivityTypes.Message)
24 | {
25 | await Conversation.SendAsync(activity, () => new Dialogs.IntentDialog());
26 | }
27 | else
28 | {
29 | HandleSystemMessage(activity, connectorClient);
30 | }
31 | var response = Request.CreateResponse(HttpStatusCode.OK);
32 | return response;
33 | }
34 |
35 | private Activity HandleSystemMessage(Activity message, ConnectorClient connectorClient)
36 | {
37 | if (message.Type == ActivityTypes.ContactRelationUpdate)
38 | {
39 | // send a greeting message when added
40 | if (message.Action == ContactRelationUpdateActionTypes.Add)
41 | {
42 | Activity greet = message.CreateReply(Resources.GREET);
43 | connectorClient.Conversations.ReplyToActivity(greet);
44 | }
45 | // clear up the user data when removed
46 | else if (message.Action == ContactRelationUpdateActionTypes.Remove)
47 | {
48 | BotStateExtensions.DeleteStateForUser(message.GetStateClient().BotState, message.ChannelId, message.From.Id);
49 | }
50 | }
51 |
52 | return null;
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="FridgeBot.WebApiApplication" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 | using System.Web.Http;
6 | using System.Web.Routing;
7 |
8 | namespace FridgeBot
9 | {
10 | public class WebApiApplication : System.Web.HttpApplication
11 | {
12 | protected void Application_Start()
13 | {
14 | GlobalConfiguration.Configure(WebApiConfig.Register);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FridgeBot")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FridgeBot")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("51c24e24-e90b-486c-b3c9-ee992f56672b")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/Utils/Util.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Microsoft.Bot.Builder.Dialogs;
5 |
6 | namespace FridgeBot.Utils
7 | {
8 | // helper functions
9 | public static class Util
10 | {
11 | private static void InitFridge(IDialogContext context)
12 | {
13 | List ingredients;
14 | bool isFirstTime = !context.UserData.TryGetValue>("ingredients", out ingredients);
15 | if (isFirstTime)
16 | {
17 | context.UserData.SetValue>("ingredients", new List());
18 | }
19 | }
20 |
21 | public static bool IsInFridge(IDialogContext context, string item)
22 | {
23 | InitFridge(context);
24 |
25 | return context.UserData.GetValue>("ingredients").Contains(item);
26 | }
27 |
28 | public static void AddToFridge(IDialogContext context, string item)
29 | {
30 | InitFridge(context);
31 |
32 | List ingredients = context.UserData.GetValue>("ingredients");
33 | if (ingredients == null)
34 | {
35 | ingredients = new List { item };
36 | }
37 | else
38 | {
39 | ingredients.Add(item);
40 | }
41 | context.UserData.SetValue>("ingredients", ingredients);
42 | }
43 |
44 | public static bool RemoveFromFridge(IDialogContext context, string item)
45 | {
46 | InitFridge(context);
47 |
48 | List ingredients = context.UserData.GetValue>("ingredients");
49 | if (ingredients == null || ingredients.Count == 0 || !ingredients.Remove(item))
50 | {
51 | return false;
52 | }
53 |
54 | context.UserData.SetValue>("ingredients", ingredients);
55 | return true;
56 | }
57 |
58 | public static void RemoveAllFromFridge(IDialogContext context)
59 | {
60 | context.UserData.SetValue>("ingredients", new List());
61 | }
62 |
63 | public static List GetAllFromFridge(IDialogContext context)
64 | {
65 | InitFridge(context);
66 |
67 | return context.UserData.GetValue>("ingredients");
68 | }
69 |
70 | public static string GetAllFromFridgeToString(IDialogContext context)
71 | {
72 | List ingredients = GetAllFromFridge(context);
73 | return (ingredients == null || ingredients.Count == 0) ? "nothing" : String.Join(", ", ingredients);
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/default.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Fridge
9 | Fridge Bot is a bot that helps you to manage refrigerator inventory. You can add or delete an item or see or clear the inventory of your fridge. The bot uses LUIS (Language Understanding Intelligent Service) Cognitive Service to recognize your intents so that you can talk to the bot as if you are talking to a person. This sample bot will serve as a good example of incorporating natural language processing service to Skype bots.
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/FridgeBot/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_add_entity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_add_entity.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_add_intent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_add_intent.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_add_utterances.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_add_utterances.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_create_a_new_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_create_a_new_app.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_label_entity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_label_entity.png
--------------------------------------------------------------------------------
/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_train_and_test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/CognitiveServices-Language/Fridge/images/LUIS_train_and_test.png
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.16
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrCodeBot", "DrCodeBot\DrCodeBot.csproj", "{21EB362A-F2CE-48B5-A174-0A89BE4B68D2}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4D25E57E-9297-451A-B1CD-36C7F185DE60}"
9 | ProjectSection(SolutionItems) = preProject
10 | .gitignore = .gitignore
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {21EB362A-F2CE-48B5-A174-0A89BE4B68D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {21EB362A-F2CE-48B5-A174-0A89BE4B68D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {21EB362A-F2CE-48B5-A174-0A89BE4B68D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {21EB362A-F2CE-48B5-A174-0A89BE4B68D2}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | EndGlobal
28 |
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/App_Start/WebApiConfig.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Serialization;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Web.Http;
7 |
8 | namespace DrCodeBot
9 | {
10 | public static class WebApiConfig
11 | {
12 | public static void Register(HttpConfiguration config)
13 | {
14 | // Json settings
15 | config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
16 | config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
17 | config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
18 | JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
19 | {
20 | ContractResolver = new CamelCasePropertyNamesContractResolver(),
21 | Formatting = Newtonsoft.Json.Formatting.Indented,
22 | NullValueHandling = NullValueHandling.Ignore,
23 | };
24 |
25 | // Web API configuration and services
26 |
27 | // Web API routes
28 | config.MapHttpAttributeRoutes();
29 |
30 | config.Routes.MapHttpRoute(
31 | name: "DefaultApi",
32 | routeTemplate: "api/{controller}/{id}",
33 | defaults: new { id = RouteParameter.Optional }
34 | );
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Controllers/MessagesController.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Net.Http;
3 | using System.Threading.Tasks;
4 | using System.Web.Http;
5 | using Microsoft.Bot.Builder.Dialogs;
6 | using Microsoft.Bot.Connector;
7 | using System;
8 | using DrCodeBot.Utils;
9 |
10 | namespace DrCodeBot
11 | {
12 | [BotAuthentication]
13 | public class MessagesController : ApiController
14 | {
15 | public async Task Post([FromBody]Activity activity)
16 | {
17 | var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));
18 |
19 | if (activity.Type == ActivityTypes.Message)
20 | {
21 | await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
22 | }
23 | else
24 | {
25 | HandleSystemMessage(activity, connectorClient);
26 | }
27 | var response = Request.CreateResponse(HttpStatusCode.OK);
28 | return response;
29 | }
30 |
31 | private void HandleSystemMessage(Activity message, ConnectorClient connectorClient)
32 | {
33 | if (message.Type == ActivityTypes.ContactRelationUpdate)
34 | {
35 | // send a welcome message when the user adds the bot
36 | if (message.Action == ContactRelationUpdateActionTypes.Add)
37 | {
38 | Activity welcome = message.CreateReply();
39 | welcome.Attachments.Add(CardFactory.getWelcomeCard().ToAttachment());
40 | connectorClient.Conversations.ReplyToActivity(welcome);
41 | }
42 | }
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Dialogs/GreetButtonClickDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Connector;
5 | using DrCodeBot.Utils;
6 | using DrCodeBot.Properties;
7 |
8 | namespace DrCodeBot.Dialogs
9 | {
10 | [Serializable]
11 | public class GreetButtonClickDialog : IDialog
12 | {
13 | public async Task StartAsync(IDialogContext context)
14 | {
15 | await context.PostAsync(Resources.GREET_INTRO);
16 |
17 | // send the welcome message again
18 | IMessageActivity welcomeMessage = context.MakeMessage();
19 | welcomeMessage.Attachments.Add(CardFactory.getWelcomeCard().ToAttachment());
20 | await context.PostAsync(welcomeMessage);
21 |
22 | await context.PostAsync(Resources.GREET_TRY_MSG);
23 |
24 | // code formatting
25 | IMessageActivity codeMessage = context.MakeMessage();
26 | codeMessage.Text = Resources.GREET_CODE;
27 | codeMessage.TextFormat = "xml";
28 | await context.PostAsync(codeMessage);
29 |
30 | await context.PostAsync(Resources.GREET_EXPLAIN);
31 | await context.PostAsync(Resources.GREET_MORE);
32 |
33 | context.Done(null);
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Dialogs/HelpButtonClickDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Connector;
5 | using DrCodeBot.Utils;
6 | using DrCodeBot.Properties;
7 |
8 | namespace DrCodeBot.Dialogs
9 | {
10 | [Serializable]
11 | public class HelpButtonClickDialog : IDialog
12 | {
13 | public async Task StartAsync(IDialogContext context)
14 | {
15 | await context.PostAsync(Resources.HELP_INTRO);
16 |
17 | // send the welcome message again
18 | IMessageActivity helpMessage = context.MakeMessage();
19 | helpMessage.Attachments.Add(CardFactory.getHelpCard().ToAttachment());
20 | await context.PostAsync(helpMessage);
21 |
22 | await context.PostAsync(Resources.HELP_TRY_MSG);
23 |
24 | // code formatting
25 | IMessageActivity codeMessage = context.MakeMessage();
26 | codeMessage.Text = Resources.HELP_CODE;
27 | codeMessage.TextFormat = "xml";
28 | await context.PostAsync(codeMessage);
29 |
30 | await context.PostAsync(Resources.HELP_EXPLAIN);
31 | await context.PostAsync(Resources.HELP_MORE);
32 |
33 | context.Done(null);
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Dialogs/HelpDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Connector;
5 | using DrCodeBot.Utils;
6 |
7 | using System.Diagnostics;
8 |
9 | namespace DrCodeBot.Dialogs
10 | {
11 | [Serializable]
12 | public class HelpDialog : IDialog
13 | {
14 | public async Task StartAsync(IDialogContext context)
15 | {
16 | // send the help hero card
17 | IMessageActivity helpMessage = context.MakeMessage();
18 | helpMessage.Attachments.Add(CardFactory.getHelpCard().ToAttachment());
19 | await context.PostAsync(helpMessage);
20 |
21 | context.Done(null);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Dialogs/HelpScorable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Microsoft.Bot.Builder.Dialogs.Internals;
5 | using Microsoft.Bot.Builder.Internals.Fibers;
6 | using Microsoft.Bot.Builder.Scorables.Internals;
7 | using Microsoft.Bot.Connector;
8 | using Microsoft.Bot.Builder.Dialogs;
9 | using DrCodeBot.Properties;
10 |
11 | namespace DrCodeBot.Dialogs
12 | {
13 | public class HelpScorable : ScorableBase
14 | {
15 | private readonly IDialogTask task;
16 |
17 | public HelpScorable(IDialogTask task)
18 | {
19 | SetField.NotNull(out this.task, nameof(task), task);
20 |
21 | }
22 |
23 | protected override Task DoneAsync(IActivity item, string state, CancellationToken token)
24 | {
25 | return Task.CompletedTask;
26 | }
27 |
28 | protected override double GetScore(IActivity item, string state)
29 | {
30 | return 1.0;
31 | }
32 |
33 | protected override bool HasScore(IActivity item, string state)
34 | {
35 | return state != null;
36 | }
37 | protected override async Task PrepareAsync(IActivity item, CancellationToken token)
38 | {
39 | var message = item as IMessageActivity;
40 |
41 | if (message != null && !string.IsNullOrWhiteSpace(message.Text))
42 | {
43 | if (message.Text.Equals(Resources.HELP_TRIGGER_TEXT, StringComparison.InvariantCultureIgnoreCase))
44 | {
45 | return message.Text;
46 | }
47 | }
48 | return null;
49 | }
50 |
51 | protected override async Task PostAsync(IActivity item, string state, CancellationToken token)
52 | {
53 | var message = item as IMessageActivity;
54 | if (message != null)
55 | {
56 | var helpDialog = new HelpDialog();
57 | var interruption = helpDialog.Void();
58 | this.task.Call(interruption, null);
59 |
60 | await this.task.PollAsync(token);
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Dialogs/RootDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Connector;
5 | using DrCodeBot.Utils;
6 | using DrCodeBot.Properties;
7 |
8 | namespace DrCodeBot.Dialogs
9 | {
10 | [Serializable]
11 | public class RootDialog : IDialog
12 | {
13 | #pragma warning disable 1998
14 | public async Task StartAsync(IDialogContext context)
15 | {
16 | context.Wait(MessageReceivedAsync);
17 | }
18 |
19 | private async Task StartAsync(IDialogContext context, IAwaitable result)
20 | {
21 | context.Wait(MessageReceivedAsync);
22 | }
23 | #pragma warning restore 1998
24 |
25 | private async Task MessageReceivedAsync(IDialogContext context, IAwaitable result)
26 | {
27 | // get the message received
28 | var activity = await result as Activity;
29 | var userResponse = activity.Text == null ? "" : activity.Text;
30 |
31 | if (userResponse.Equals(Resources.CHOICE_GREET, StringComparison.CurrentCultureIgnoreCase))
32 | {
33 | context.Call(new GreetButtonClickDialog(), this.StartAsync);
34 | }
35 | else if (userResponse.Equals(Resources.CHOICE_HELP, StringComparison.CurrentCultureIgnoreCase))
36 | {
37 | context.Call(new HelpButtonClickDialog(), this.StartAsync);
38 | }
39 | else if (userResponse.Equals(Resources.CHOICE_TYPING, StringComparison.CurrentCultureIgnoreCase))
40 | {
41 | context.Call(new TypingButtonClickDialog(), this.StartAsync);
42 | }
43 | else
44 | {
45 | IMessageActivity welcomeMessage = context.MakeMessage();
46 | welcomeMessage.Attachments.Add(CardFactory.getWelcomeCard().ToAttachment());
47 | await context.PostAsync(welcomeMessage);
48 | context.Wait(MessageReceivedAsync);
49 | }
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Dialogs/TypingButtonClickDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Connector;
5 | using DrCodeBot.Properties;
6 |
7 | namespace DrCodeBot.Dialogs
8 | {
9 | [Serializable]
10 | public class TypingButtonClickDialog : IDialog
11 | {
12 | public async Task StartAsync(IDialogContext context)
13 | {
14 | await context.PostAsync(Resources.TYPING_INTRO);
15 | await context.PostAsync(Resources.TYPING_TRY_MSG_1);
16 |
17 | // Send the typing indicator for few seconds (10 sec)
18 | IMessageActivity typingIndicatorMessage = context.MakeMessage();
19 | typingIndicatorMessage.Type = ActivityTypes.Typing;
20 | typingIndicatorMessage.Text = null;
21 | await context.PostAsync(typingIndicatorMessage);
22 | await Task.Delay(10000);
23 |
24 | await context.PostAsync(Resources.TYPING_TRY_MSG_2);
25 |
26 | // code formatting
27 | IMessageActivity codeMessage = context.MakeMessage();
28 | codeMessage.Text = Resources.TYPING_CODE;
29 | codeMessage.TextFormat = "xml";
30 | await context.PostAsync(codeMessage);
31 |
32 | await context.PostAsync(Resources.TYPING_EXPLAIN);
33 | await context.PostAsync(Resources.TYPING_MORE);
34 |
35 | context.Done(null);
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="DrCodeBot.WebApiApplication" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Http;
2 | using Autofac;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Builder.Internals.Fibers;
5 |
6 | namespace DrCodeBot
7 | {
8 | public class WebApiApplication : System.Web.HttpApplication
9 | {
10 | protected void Application_Start()
11 | {
12 | this.RegisterBotModules();
13 |
14 | GlobalConfiguration.Configure(WebApiConfig.Register);
15 | }
16 |
17 | private void RegisterBotModules()
18 | {
19 | var builder = new ContainerBuilder();
20 | builder.RegisterModule(new ReflectionSurrogateModule());
21 | builder.RegisterModule();
22 | builder.Update(Conversation.Container);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/HelpMessageHandlerModule.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using DrCodeBot.Dialogs;
3 | using Microsoft.Bot.Builder.Dialogs.Internals;
4 | using Microsoft.Bot.Builder.Scorables;
5 | using Microsoft.Bot.Connector;
6 |
7 | using System.Diagnostics;
8 |
9 | namespace DrCodeBot
10 | {
11 | public class HelpMessageHandlerModule : Module
12 | {
13 | protected override void Load(ContainerBuilder builder)
14 | {
15 | Trace.WriteLine("Load - HelpMessageHandlerModule");
16 | base.Load(builder);
17 |
18 | builder
19 | .Register(c => new HelpScorable(c.Resolve()))
20 | .As>()
21 | .InstancePerLifetimeScope();
22 |
23 | Trace.WriteLine("Load - HelpMessageHandlerModule2");
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DrCodeBot")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DrCodeBot")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("21eb362a-f2ce-48b5-a174-0a89be4b68d2")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/Utils/CardFactory.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Bot.Connector;
2 | using System.Collections.Generic;
3 | using DrCodeBot.Properties;
4 |
5 | namespace DrCodeBot.Utils
6 | {
7 | public static class CardFactory
8 | {
9 | public static HeroCard getWelcomeCard()
10 | {
11 | return new HeroCard
12 | {
13 | Text = Resources.GREET,
14 | Images = new List
15 | {
16 | new CardImage(url: Resources.FACE_IMAGE_URL)
17 | },
18 | Buttons = new List
19 | {
20 | new CardAction(ActionTypes.ImBack, Resources.CHOICE_GREET, value: Resources.CHOICE_GREET),
21 | new CardAction(ActionTypes.ImBack, Resources.CHOICE_HELP, value: Resources.CHOICE_HELP),
22 | new CardAction(ActionTypes.ImBack, Resources.CHOICE_TYPING, value: Resources.CHOICE_TYPING)
23 | }
24 | };
25 | }
26 |
27 | public static HeroCard getHelpCard()
28 | {
29 | return new HeroCard
30 | {
31 | Title = Resources.HELP_TITLE,
32 | Text = Resources.HELP,
33 | Buttons = new List
34 | {
35 | new CardAction(ActionTypes.ImBack, Resources.CHOICE_GREET, value: Resources.CHOICE_GREET),
36 | new CardAction(ActionTypes.ImBack, Resources.CHOICE_HELP, value: Resources.CHOICE_HELP),
37 | new CardAction(ActionTypes.ImBack, Resources.CHOICE_TYPING, value: Resources.CHOICE_TYPING)
38 | }
39 | };
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/default.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | DrCodeBot
9 | Describe your bot here and your terms of use etc.
10 | Visit Bot Framework to register your bot. When you register it, remember to set your bot's endpoint to
https://your_bots_hostname /api/messages
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Samples/Csharp/Fundamentals/DoctorCode/DrCodeBot/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | # User-specific files
6 | *.suo
7 | *.user
8 | *.userosscache
9 | *.sln.docstates
10 |
11 | # User-specific files (MonoDevelop/Xamarin Studio)
12 | *.userprefs
13 | .vs/
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | [Xx]64/
21 | [Xx]86/
22 | [Bb]uild/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | /packages
27 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Http/CallEndpointStartup.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Web.Http;
7 | using System.Web.Http.ExceptionHandling;
8 | using FrontEnd.Logging;
9 | using Owin;
10 | using Microsoft.Bot.Builder.RealTimeMediaCalling.ObjectModel.Misc;
11 |
12 | namespace FrontEnd.Http
13 | {
14 | ///
15 | /// Initialize the httpConfiguration for OWIN
16 | ///
17 | public class CallEndpointStartup
18 | {
19 | ///
20 | /// Configuration settings like Auth, Routes for OWIN
21 | ///
22 | ///
23 |
24 | public void Configuration(IAppBuilder app)
25 | {
26 | HttpConfiguration httpConfig = new HttpConfiguration();
27 | httpConfig.MapHttpAttributeRoutes();
28 | httpConfig.MessageHandlers.Add(new LoggingMessageHandler(isIncomingMessageHandler: true, logContext: LogContext.FrontEnd));
29 |
30 | httpConfig.Services.Add(typeof(IExceptionLogger), new ExceptionLogger());
31 | httpConfig.Formatters.JsonFormatter.SerializerSettings = RealTimeMediaSerializer.GetSerializerSettings();
32 | httpConfig.EnsureInitialized();
33 |
34 | app.UseWebApi(httpConfig);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Http/ExceptionLogger.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using System.Web.Http.ExceptionHandling;
9 | using FrontEnd.Logging;
10 |
11 | namespace FrontEnd.Http
12 | {
13 | internal class ExceptionLogger : IExceptionLogger
14 | {
15 | public ExceptionLogger()
16 | {
17 | }
18 |
19 | public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
20 | {
21 | Log.Error(new CallerInfo(), LogContext.FrontEnd, "Exception processing HTTP request. {0}", context.Exception.ToString());
22 | return Task.FromResult(null);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Http/HttpRouteConstants.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | namespace FrontEnd.Http
7 | {
8 | ///
9 | /// HTTP route constants for routing requests to CallController methods.
10 | ///
11 | public static class HttpRouteConstants
12 | {
13 | ///
14 | /// Route prefix for all incoming requests.
15 | ///
16 | public const string CallSignalingRoutePrefix = "api/calling";
17 |
18 | ///
19 | /// Route prefix for incoming requests
20 | ///
21 | public const string OnIncomingMessageRoute = "api/messages";
22 |
23 | ///
24 | /// Route for incoming calls.
25 | ///
26 | public const string OnIncomingCallRoute = "call";
27 |
28 | ///
29 | /// Route for existing call callbacks.
30 | ///
31 | public const string OnCallbackRoute = "callback";
32 |
33 | ///
34 | /// Route for existing call notifications.
35 | ///
36 | public const string OnNotificationRoute = "notification";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Http/MessagesController.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Net.Http;
7 | using System.Threading.Tasks;
8 | using System.Web.Http;
9 | using FrontEnd.Call;
10 | using FrontEnd.Logging;
11 | using Microsoft.Bot.Builder.RealTimeMediaCalling;
12 | using Microsoft.Bot.Connector;
13 |
14 | namespace FrontEnd.Http
15 | {
16 | ///
17 | /// MessagesController handles the incoming messages for this bot.
18 | ///
19 | public class MessagesController : ApiController
20 | {
21 | ///
22 | /// Handle an incoming message.
23 | ///
24 | ///
25 | /// HttpResponseMessage with StatusCode as Accepted
26 | [HttpPost]
27 | [Route(HttpRouteConstants.OnIncomingMessageRoute)]
28 | [BotAuthentication]
29 | public HttpResponseMessage Post(HttpRequestMessage request)
30 | {
31 | Log.Info(new CallerInfo(), LogContext.FrontEnd, $"Received HTTP {request.Method}, {request.RequestUri}");
32 |
33 | return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Http/RealTimeMediaCallingBotServiceSettings.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using Microsoft.Bot.Builder.RealTimeMediaCalling;
8 |
9 | namespace FrontEnd.Http
10 | {
11 | ///
12 | /// Service settings to configure the RealTimeMediaCalling
13 | ///
14 | public class RealTimeMediaCallingBotServiceSettings : IRealTimeMediaCallServiceSettings
15 | {
16 | ///
17 | /// The url where the callbacks for the calls to this bot needs to be sent.
18 | /// For example "https://testservice.azurewebsites.net/api/calling/callback"
19 | ///
20 | public Uri CallbackUrl { get; private set; }
21 |
22 | ///
23 | /// The url where the notifications for the calls to this bot needs to be sent.
24 | /// For example "https://testservice.azurewebsites.net/api/calling/notification"
25 | ///
26 | public Uri NotificationUrl { get; private set; }
27 |
28 | public RealTimeMediaCallingBotServiceSettings()
29 | {
30 | CallbackUrl = Service.Instance.Configuration.CallControlCallbackUrl;
31 | NotificationUrl = Service.Instance.Configuration.NotificationCallbackUrl;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/IConfiguration.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using Microsoft.Skype.Bots.Media;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Linq;
10 | using System.Text;
11 | using System.Threading.Tasks;
12 |
13 | namespace FrontEnd
14 | {
15 | ///
16 | /// IConfiguration contains the static configuration information the application needs
17 | /// to run such as the urls it needs to listen on, credentials to communicate with
18 | /// Bing translator, settings for media.platform, etc.
19 | ///
20 | /// The concrete implementation AzureConfiguration gets the configuration from Azure. However,
21 | /// other concrete classes could be created to allow the application to run outside of Azure
22 | /// for testing.
23 | ///
24 | public interface IConfiguration : IDisposable
25 | {
26 | ///
27 | /// List of HTTP urls the app should listen on for incoming call
28 | /// signaling requests from Skype Platform.
29 | ///
30 | IEnumerable CallControlListeningUrls { get; }
31 |
32 | ///
33 | /// The base callback URL for this instance. To ensure that all requests
34 | /// for a given call go to the same instance, this Url is unique to each
35 | /// instance by way of its instance input endpoint port.
36 | ///
37 | Uri CallControlCallbackUrl { get; }
38 |
39 | ///
40 | /// The template for call notifications like call state change notifications.
41 | /// To ensure that all requests for a given call go to the same instance, this Url
42 | /// is unique to each instance by way of its instance input endpoint port.
43 | ///
44 | Uri NotificationCallbackUrl { get; }
45 |
46 | ///
47 | /// Speech subscription credentials
48 | ///
49 | string SpeechSubscription { get; }
50 |
51 | ///
52 | /// MicrosoftAppId generated at the time of registration of the bot
53 | ///
54 | string MicrosoftAppId { get; }
55 |
56 | ///
57 | /// Settings for the bot media platform
58 | ///
59 | MediaPlatformSettings MediaPlatformSettings { get; }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Logging/CallerInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Collections.Concurrent;
8 | using System.IO;
9 | using System.Runtime.CompilerServices;
10 |
11 | namespace FrontEnd.Logging
12 | {
13 | ///
14 | /// Class that encapsulates the caller's (creator's) information. This is helpful to provide more context in log statements.
15 | ///
16 | public class CallerInfo
17 | {
18 | private static ConcurrentDictionary toStringCache = new ConcurrentDictionary();
19 |
20 | ///
21 | /// The name of the method or property of the caller
22 | ///
23 | public string MemberName { get; protected set; }
24 |
25 | ///
26 | /// The full path of the source file of the caller
27 | ///
28 | public string FilePath { get; protected set; }
29 |
30 | ///
31 | /// The line number of the source file of the caller
32 | ///
33 | public int LineNumber { get; protected set; }
34 |
35 | ///
36 | /// Creates a new instance of the CallerInfo class
37 | ///
38 | public CallerInfo(
39 | [CallerMemberName] string memberName = "",
40 | [CallerFilePath] string filePath = "",
41 | [CallerLineNumber] int lineNumber = 0
42 | )
43 | {
44 | this.MemberName = memberName;
45 | this.FilePath = filePath;
46 | this.LineNumber = lineNumber;
47 | }
48 |
49 | ///
50 | /// Get the hashcode for this instance
51 | ///
52 | ///
53 | public override int GetHashCode()
54 | {
55 | return MemberName.GetHashCode() ^ FilePath.GetHashCode() ^ LineNumber;
56 | }
57 |
58 | ///
59 | /// String representation of the caller's info
60 | ///
61 | ///
62 | public override string ToString()
63 | {
64 | return toStringCache.GetOrAdd(this.GetHashCode(), hc => String.Format(
65 | "{0},{1}({2})",
66 | this.MemberName,
67 | Path.GetFileName(this.FilePath),
68 | this.LineNumber
69 | ));
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Logging/CorrelationId.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.Remoting.Messaging;
8 |
9 | namespace FrontEnd.Logging
10 | {
11 | internal class CorrelationId
12 | {
13 | private class Holder : MarshalByRefObject
14 | {
15 | public string Id;
16 | }
17 |
18 | internal const string LogicalDataName = "FrontEnd.Logging.CorrelationId";
19 |
20 | ///
21 | /// Sets the current correlation ID. This is necessary to call in event handler callbacks because the event producer
22 | /// may not be aware of the call id.
23 | ///
24 | ///
25 | public static void SetCurrentId(string value)
26 | {
27 | if (string.IsNullOrEmpty(value))
28 | {
29 | return;
30 | }
31 |
32 | Holder holder = CallContext.LogicalGetData(LogicalDataName) as Holder;
33 | if (holder == null)
34 | {
35 | CallContext.LogicalSetData(LogicalDataName, new Holder { Id = value });
36 | }
37 | else
38 | {
39 | try
40 | {
41 | holder.Id = value;
42 | }
43 | catch (AppDomainUnloadedException)
44 | {
45 | CallContext.LogicalSetData(LogicalDataName, new Holder { Id = value });
46 | }
47 | }
48 | }
49 |
50 | ///
51 | /// Gets the current correlation id.
52 | ///
53 | ///
54 | public static string GetCurrentId()
55 | {
56 | Holder holder = CallContext.LogicalGetData(LogicalDataName) as Holder;
57 | if (holder != null)
58 | {
59 | try
60 | {
61 | return holder.Id;
62 | }
63 | catch (AppDomainUnloadedException)
64 | {
65 | CallContext.FreeNamedDataSlot(LogicalDataName);
66 | return null;
67 | }
68 | }
69 |
70 | return null;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/MediaLogic/AudioSendBuffer.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.InteropServices;
8 | using FrontEnd.Logging;
9 | using Microsoft.Skype.Bots.Media;
10 |
11 |
12 | namespace FrontEnd.Media
13 | {
14 | ///
15 | /// Creates an Audio Buffer for Send and also implements Dispose
16 | ///
17 | class AudioSendBuffer : AudioMediaBuffer
18 | {
19 | private bool _disposed;
20 |
21 | [DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
22 | public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
23 |
24 | public AudioSendBuffer(IntPtr mediaBuffer, long length, AudioFormat format, long timeStamp)
25 | {
26 | Data = mediaBuffer;
27 | Length = length;
28 | AudioFormat = format;
29 | Timestamp = timeStamp;
30 | }
31 |
32 | protected override void Dispose(bool disposing)
33 | {
34 | if (!_disposed)
35 | {
36 | Marshal.FreeHGlobal(Data);
37 | }
38 |
39 | _disposed = true;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/MediaLogic/VideoSendBuffer.cs:
--------------------------------------------------------------------------------
1 | /**************************************************
2 | * *
3 | * © Microsoft Corporation. All rights reserved. *
4 | * *
5 | **************************************************/
6 |
7 | using System;
8 | using System.Runtime.InteropServices;
9 | using FrontEnd.Logging;
10 | using Microsoft.Skype.Bots.Media;
11 |
12 | namespace FrontEnd.Media
13 | {
14 | ///
15 | /// Creates a Video Buffer for Send and also implements Dispose
16 | ///
17 | class VideoSendBuffer : VideoMediaBuffer
18 | {
19 | private bool _disposed;
20 |
21 | public VideoSendBuffer(byte[] buffer, uint length, VideoFormat format)
22 | {
23 | IntPtr ptrToBuffer = Marshal.AllocHGlobal(buffer.Length);
24 | Marshal.Copy(buffer, 0, ptrToBuffer, buffer.Length);
25 |
26 | Data = ptrToBuffer;
27 | Length = length;
28 | VideoFormat = format;
29 | Timestamp = DateTime.Now.Ticks;
30 | }
31 |
32 | protected override void Dispose(bool disposing)
33 | {
34 | if (!_disposed)
35 | {
36 | Marshal.FreeHGlobal(Data);
37 | Data = IntPtr.Zero;
38 | }
39 |
40 | _disposed = true;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Reflection;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | [assembly: AssemblyTitle("FrontEnd")]
14 | [assembly: AssemblyDescription("")]
15 | [assembly: AssemblyConfiguration("")]
16 | [assembly: AssemblyCompany("")]
17 | [assembly: AssemblyProduct("FrontEnd")]
18 | [assembly: AssemblyCopyright("Copyright © 2016")]
19 | [assembly: AssemblyTrademark("")]
20 | [assembly: AssemblyCulture("")]
21 |
22 | // Setting ComVisible to false makes the types in this assembly not visible
23 | // to COM components. If you need to access a type in this assembly from
24 | // COM, set the ComVisible attribute to true on that type.
25 | [assembly: ComVisible(false)]
26 |
27 | // The following GUID is for the ID of the typelib if this project is exposed to COM
28 | [assembly: Guid("bd841814-05f3-498d-834d-cc7afe2a8f1a")]
29 |
30 | // Version information for an assembly consists of the following four values:
31 | //
32 | // Major Version
33 | // Minor Version
34 | // Build Number
35 | // Revision
36 | //
37 | // You can specify all the values or you can default the Build and Revision Numbers
38 | // by using the '*' as shown below:
39 | // [assembly: AssemblyVersion("1.0.*")]
40 | [assembly: AssemblyVersion("1.0.0.0")]
41 | [assembly: AssemblyFileVersion("1.0.0.0")]
42 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Tts/TtsEngine.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.IO;
7 |
8 | namespace FrontEnd.Tts
9 | {
10 | ///
11 | /// Interface for the TTS engine support
12 | ///
13 | internal interface ITtsEngine
14 | {
15 | ///
16 | /// Synthetize the text
17 | ///
18 | /// The string to synthetize
19 | /// The stream containing the synthetized audio
20 | MemoryStream SynthesizeText(string text);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Tts/TtsEngineLocal.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.IO;
7 | using System.Speech.AudioFormat;
8 | using System.Speech.Synthesis;
9 |
10 | namespace FrontEnd.Tts
11 | {
12 | ///
13 | /// TTS engine that uses the local Speech Synthesizer APIs,
14 | /// see documentation: https://msdn.microsoft.com/en-us/library/hh362831(v=office.14).aspx
15 | ///
16 | internal class TtsEngineLocal : ITtsEngine
17 | {
18 | private readonly SpeechSynthesizer _synth;
19 |
20 | public TtsEngineLocal()
21 | {
22 | // initialize the Speech Synthesizer with a female voice
23 | _synth = new SpeechSynthesizer();
24 | _synth.SelectVoiceByHints(VoiceGender.Female);
25 | }
26 |
27 | public MemoryStream SynthesizeText(string text)
28 | {
29 | var audioStream = new MemoryStream();
30 |
31 | // set the synthesizer output to the stream, make sure the output format is matching the audio socket settings
32 | _synth.SetOutputToAudioStream(audioStream,
33 | new SpeechAudioFormatInfo(samplesPerSecond: 16000, bitsPerSample: AudioBitsPerSample.Sixteen, channel: AudioChannel.Mono));
34 |
35 | _synth.Speak(text);
36 |
37 | return audioStream;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/Utilities.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Threading.Tasks;
8 | using FrontEnd.Logging;
9 |
10 | namespace FrontEnd
11 | {
12 | internal static class Utilities
13 | {
14 | ///
15 | /// Extension for Task to execute the task in background and log any exception
16 | ///
17 | ///
18 | ///
19 | public static async void ForgetAndLogException(this Task task, string description = null)
20 | {
21 | try
22 | {
23 | await task.ConfigureAwait(false);
24 | }
25 | catch (Exception e)
26 | {
27 | //ignore
28 | Log.Error(new CallerInfo(),
29 | LogContext.FrontEnd,
30 | "Caught an Exception running the task: {0} \n StackTrace: {1}", e.Message, e.StackTrace);
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/FrontEnd/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/ServiceConfiguration.Cloud.cscfg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/TextToSpeech.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.15
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "TextToSpeech", "TextToSpeech.ccproj", "{4EABD84F-6AD2-48D5-B286-B86758D4F806}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A} = {BD841814-05F3-498D-834D-CC7AFE2A8F1A}
9 | EndProjectSection
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkerRole", "WorkerRole\WorkerRole.csproj", "{9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}"
12 | EndProject
13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrontEnd", "FrontEnd\FrontEnd.csproj", "{BD841814-05F3-498D-834D-CC7AFE2A8F1A}"
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|x64 = Debug|x64
18 | Release|x64 = Release|x64
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Debug|x64.ActiveCfg = Debug|Any CPU
22 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Debug|x64.Build.0 = Debug|Any CPU
23 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Release|x64.ActiveCfg = Release|Any CPU
24 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Release|x64.Build.0 = Release|Any CPU
25 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Debug|x64.ActiveCfg = Debug|x64
26 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Debug|x64.Build.0 = Debug|x64
27 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Release|x64.ActiveCfg = Release|x64
28 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Release|x64.Build.0 = Release|x64
29 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Debug|x64.ActiveCfg = Debug|x64
30 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Debug|x64.Build.0 = Debug|x64
31 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Release|x64.ActiveCfg = Release|x64
32 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Release|x64.Build.0 = Release|x64
33 | EndGlobalSection
34 | GlobalSection(SolutionProperties) = preSolution
35 | HideSolutionNode = FALSE
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/InstallMediaFoundation.ps1:
--------------------------------------------------------------------------------
1 | # Error handling
2 | trap
3 | {
4 | Write-Output "Error Hit: $_"
5 | Write-Output "Error File: $($_.InvocationInfo.ScriptName)"
6 | Write-Output "Error Line #: $($_.InvocationInfo.ScriptLineNumber)"
7 | Write-Output ""
8 | Write-Output "Exception: $($_.Exception)"
9 | Write-Output ""
10 | Write-Output "Exception.InnerException: $($_.Exception.InnerException)"
11 | exit 1
12 | }
13 |
14 | Write-Output "Checking if Media Foundation is installed"
15 | if((Get-WindowsFeature Server-Media-Foundation).Installed -eq 0)
16 | {
17 | Write-Output "Installing Media Foundation."
18 | Add-WindowsFeature Server-Media-Foundation
19 |
20 | Write-Output "Rebooting VM for changes to take effect."
21 | Restart-Computer
22 | }
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/InstallNETFX.cmd:
--------------------------------------------------------------------------------
1 | REM Code Courtesy https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-install-dotnet/
2 | REM Set the value of netfx to install appropriate .NET Framework.
3 | REM ***** To install .NET 4.5.2 set the variable netfx to "NDP452" *****
4 | REM ***** To install .NET 4.6 set the variable netfx to "NDP46" *****
5 | REM ***** To install .NET 4.6.1 set the variable netfx to "NDP461" *****
6 | set netfx="%NetFxVersion%"
7 |
8 | REM ***** Needed to correctly install .NET 4.6.1, otherwise you may see an out of disk space error *****
9 | set TMP=%PathToNETFXInstall%
10 | set TEMP=%PathToNETFXInstall%
11 |
12 | REM ***** Setup .NET filenames and registry keys *****
13 | if %netfx%=="NDP461" goto NDP461
14 | if %netfx%=="NDP46" goto NDP46
15 | set netfxinstallfile="NDP452-KB2901954-Web.exe"
16 | set netfxregkey="0x5cbf5"
17 | goto logtimestamp
18 |
19 | :NDP46
20 | set netfxinstallfile="NDP46-KB3045560-Web.exe"
21 | set netfxregkey="0x60051"
22 | goto logtimestamp
23 |
24 | :NDP461
25 | set netfxinstallfile="NDP461-KB3102438-Web.exe"
26 | set netfxregkey="0x6041f"
27 |
28 | :logtimestamp
29 | REM ***** Setup LogFile with timestamp *****
30 | set timehour=%time:~0,2%
31 | set timestamp=%date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour: =0%%time:~3,2%
32 | md "%PathToNETFXInstall%\log"
33 | set startuptasklog="%PathToNETFXInstall%log\startuptasklog-%timestamp%.txt"
34 | set netfxinstallerlog="%PathToNETFXInstall%log\NetFXInstallerLog-%timestamp%"
35 |
36 | echo Logfile generated at: %startuptasklog% >> %startuptasklog%
37 | echo TMP set to: %TMP% >> %startuptasklog%
38 | echo TEMP set to: %TEMP% >> %startuptasklog%
39 |
40 | REM ***** Check if .NET is installed *****
41 | echo Checking if .NET (%netfx%) is installed >> %startuptasklog%
42 | reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v Release | Find %netfxregkey%
43 | if %ERRORLEVEL%== 0 goto end
44 |
45 | REM ***** Installing .NET *****
46 | echo Installing .NET: start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% >> %startuptasklog%
47 | start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% >> %startuptasklog% 2>>&1
48 |
49 | :end
50 | echo install.cmd completed: %date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour: =0%%time:~3,2% >> %startuptasklog%
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/NDP461-KB3102438-Web.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/NDP461-KB3102438-Web.exe
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Reflection;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | [assembly: AssemblyTitle("WorkerRole")]
14 | [assembly: AssemblyDescription("")]
15 | [assembly: AssemblyConfiguration("")]
16 | [assembly: AssemblyCompany("")]
17 | [assembly: AssemblyProduct("WorkerRole")]
18 | [assembly: AssemblyCopyright("Copyright © 2016")]
19 | [assembly: AssemblyTrademark("")]
20 | [assembly: AssemblyCulture("")]
21 |
22 | // Setting ComVisible to false makes the types in this assembly not visible
23 | // to COM components. If you need to access a type in this assembly from
24 | // COM, set the ComVisible attribute to true on that type.
25 | [assembly: ComVisible(false)]
26 |
27 | // The following GUID is for the ID of the typelib if this project is exposed to COM
28 | [assembly: Guid("9f593a7b-8935-4bc8-9fbb-c3a9e3bc2a23")]
29 |
30 | // Version information for an assembly consists of the following four values:
31 | //
32 | // Major Version
33 | // Minor Version
34 | // Build Number
35 | // Revision
36 | //
37 | // You can specify all the values or you can default the Build and Revision Numbers
38 | // by using the '*' as shown below:
39 | // [assembly: AssemblyVersion("1.0.*")]
40 | [assembly: AssemblyVersion("1.0.0.0")]
41 | [assembly: AssemblyFileVersion("1.0.0.0")]
42 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/SetupMediaFoundation.cmd:
--------------------------------------------------------------------------------
1 | echo Launching Powershell to install Media Foundation
2 | PowerShell -ExecutionPolicy Unrestricted .\InstallMediaFoundation.ps1 >> InstallMediaFoundation.log 2>&1
3 | EXIT /B 0
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToSpeech/WorkerRole/startup.cmd:
--------------------------------------------------------------------------------
1 | REM --- Move to this scripts location ---
2 | pushd "%~dp0"
3 |
4 | REM --- Print out environment variables for debugging ---
5 | set
6 |
7 | REM--- Register media perf dlls ---
8 | powershell .\skype_media_lib\MediaPlatformStartupScript.bat
9 |
10 | REM --- Delete existing certificate bindings and URL ACL registrations ---
11 | netsh http delete sslcert ipport=%InstanceIpAddress%:%PrivateDefaultCallControlPort%
12 | netsh http delete sslcert ipport=%InstanceIpAddress%:%PrivateInstanceCallControlPort%
13 | netsh http delete urlacl url=https://%InstanceIpAddress%:%PrivateDefaultCallControlPort%/
14 | netsh http delete urlacl url=https://%InstanceIpAddress%:%PrivateInstanceCallControlPort%/
15 |
16 | REM --- Delete new URL ACLs and certificate bindings ---
17 | netsh http add urlacl url=https://%InstanceIpAddress%:%PrivateDefaultCallControlPort%/ user="NT AUTHORITY\NETWORK SERVICE"
18 | netsh http add urlacl url=https://%InstanceIpAddress%:%PrivateInstanceCallControlPort%/ user="NT AUTHORITY\NETWORK SERVICE"
19 | netsh http add sslcert ipport=%InstanceIpAddress%:%PrivateDefaultCallControlPort% clientcertnegotiation=enable "appid={00000000-0000-0000-0000-000000000001}" cert=%DefaultCertificate%
20 | netsh http add sslcert ipport=%InstanceIpAddress%:%PrivateInstanceCallControlPort% clientcertnegotiation=enable "appid={00000000-0000-0000-0000-000000000001}" cert=%DefaultCertificate%
21 |
22 | REM --- Disable strong-name validation. This should not be needed once all external binaries are properly signed ---
23 | REGEDIT /S %~dp0\DisableStrongNameVerification.reg
24 |
25 | popd
26 | exit /b 0
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | # User-specific files
6 | *.suo
7 | *.user
8 | *.userosscache
9 | *.sln.docstates
10 |
11 | # User-specific files (MonoDevelop/Xamarin Studio)
12 | *.userprefs
13 | .vs/
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | [Xx]64/
21 | [Xx]86/
22 | [Bb]uild/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | /packages
27 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Http/CallEndpointStartup.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Web.Http;
7 | using System.Web.Http.ExceptionHandling;
8 | using FrontEnd.Logging;
9 | using Owin;
10 | using Microsoft.Bot.Builder.RealTimeMediaCalling.ObjectModel.Misc;
11 |
12 | namespace FrontEnd.Http
13 | {
14 | ///
15 | /// Initialize the httpConfiguration for OWIN
16 | ///
17 | public class CallEndpointStartup
18 | {
19 | ///
20 | /// Configuration settings like Auth, Routes for OWIN
21 | ///
22 | ///
23 |
24 | public void Configuration(IAppBuilder app)
25 | {
26 | HttpConfiguration httpConfig = new HttpConfiguration();
27 | httpConfig.MapHttpAttributeRoutes();
28 | httpConfig.MessageHandlers.Add(new LoggingMessageHandler(isIncomingMessageHandler: true, logContext: LogContext.FrontEnd));
29 |
30 | httpConfig.Services.Add(typeof(IExceptionLogger), new ExceptionLogger());
31 | httpConfig.Formatters.JsonFormatter.SerializerSettings = RealTimeMediaSerializer.GetSerializerSettings();
32 | httpConfig.EnsureInitialized();
33 |
34 | app.UseWebApi(httpConfig);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Http/ExceptionLogger.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using System.Web.Http.ExceptionHandling;
9 | using FrontEnd.Logging;
10 |
11 | namespace FrontEnd.Http
12 | {
13 | internal class ExceptionLogger : IExceptionLogger
14 | {
15 | public ExceptionLogger()
16 | {
17 | }
18 |
19 | public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
20 | {
21 | Log.Error(new CallerInfo(), LogContext.FrontEnd, "Exception processing HTTP request. {0}", context.Exception.ToString());
22 | return Task.FromResult(null);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Http/HttpRouteConstants.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | namespace FrontEnd.Http
7 | {
8 | ///
9 | /// HTTP route constants for routing requests to CallController methods.
10 | ///
11 | public static class HttpRouteConstants
12 | {
13 | ///
14 | /// Route prefix for all incoming requests.
15 | ///
16 | public const string CallSignalingRoutePrefix = "api/calling";
17 |
18 | ///
19 | /// Route prefix for incoming requests
20 | ///
21 | public const string OnIncomingMessageRoute = "api/messages";
22 |
23 | ///
24 | /// Route for incoming calls.
25 | ///
26 | public const string OnIncomingCallRoute = "call";
27 |
28 | ///
29 | /// Route for existing call callbacks.
30 | ///
31 | public const string OnCallbackRoute = "callback";
32 |
33 | ///
34 | /// Route for existing call notifications.
35 | ///
36 | public const string OnNotificationRoute = "notification";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Http/MessagesController.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Net.Http;
7 | using System.Threading.Tasks;
8 | using System.Web.Http;
9 | using FrontEnd.Logging;
10 | using Microsoft.Bot.Builder.RealTimeMediaCalling;
11 | using Microsoft.Bot.Connector;
12 |
13 | namespace FrontEnd.Http
14 | {
15 | ///
16 | /// MessagesController handles the incoming messages for this bot.
17 | ///
18 | public class MessagesController : ApiController
19 | {
20 | ///
21 | /// Handle an incoming message.
22 | ///
23 | ///
24 | /// HttpResponseMessage with StatusCode as Accepted
25 | [HttpPost]
26 | [Route(HttpRouteConstants.OnIncomingMessageRoute)]
27 | [BotAuthentication]
28 | public HttpResponseMessage Post(HttpRequestMessage request)
29 | {
30 | Log.Info(new CallerInfo(), LogContext.FrontEnd, $"Received HTTP {request.Method}, {request.RequestUri}");
31 |
32 | return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Http/RealTimeMediaCallingBotServiceSettings.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using Microsoft.Bot.Builder.RealTimeMediaCalling;
8 |
9 | namespace FrontEnd.Http
10 | {
11 | ///
12 | /// Service settings to configure the RealTimeMediaCalling
13 | ///
14 | public class RealTimeMediaCallingBotServiceSettings : IRealTimeMediaCallServiceSettings
15 | {
16 | ///
17 | /// The url where the callbacks for the calls to this bot needs to be sent.
18 | /// For example "https://testservice.azurewebsites.net/api/calling/callback"
19 | ///
20 | public Uri CallbackUrl { get; private set; }
21 |
22 | ///
23 | /// The url where the notifications for the calls to this bot needs to be sent.
24 | /// For example "https://testservice.azurewebsites.net/api/calling/notification"
25 | ///
26 | public Uri NotificationUrl { get; private set; }
27 |
28 | public RealTimeMediaCallingBotServiceSettings()
29 | {
30 | CallbackUrl = Service.Instance.Configuration.CallControlCallbackUrl;
31 | NotificationUrl = Service.Instance.Configuration.NotificationCallbackUrl;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/IConfiguration.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using Microsoft.Skype.Bots.Media;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Linq;
10 | using System.Text;
11 | using System.Threading.Tasks;
12 |
13 | namespace FrontEnd
14 | {
15 | ///
16 | /// IConfiguration contains the static configuration information the application needs
17 | /// to run such as the urls it needs to listen on, credentials to communicate with
18 | /// Bing translator, settings for media.platform, etc.
19 | ///
20 | /// The concrete implementation AzureConfiguration gets the configuration from Azure. However,
21 | /// other concrete classes could be created to allow the application to run outside of Azure
22 | /// for testing.
23 | ///
24 | public interface IConfiguration : IDisposable
25 | {
26 | ///
27 | /// List of HTTP urls the app should listen on for incoming call
28 | /// signaling requests from Skype Platform.
29 | ///
30 | IEnumerable CallControlListeningUrls { get; }
31 |
32 | ///
33 | /// The base callback URL for this instance. To ensure that all requests
34 | /// for a given call go to the same instance, this Url is unique to each
35 | /// instance by way of its instance input endpoint port.
36 | ///
37 | Uri CallControlCallbackUrl { get; }
38 |
39 | ///
40 | /// The template for call notifications like call state change notifications.
41 | /// To ensure that all requests for a given call go to the same instance, this Url
42 | /// is unique to each instance by way of its instance input endpoint port.
43 | ///
44 | Uri NotificationCallbackUrl { get; }
45 |
46 | ///
47 | /// Speech subscription credentials
48 | ///
49 | string SpeechSubscription { get; }
50 |
51 | ///
52 | /// MicrosoftAppId generated at the time of registration of the bot
53 | ///
54 | string MicrosoftAppId { get; }
55 |
56 | ///
57 | /// Settings for the bot media platform
58 | ///
59 | MediaPlatformSettings MediaPlatformSettings { get; }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Logging/CallerInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Collections.Concurrent;
8 | using System.IO;
9 | using System.Runtime.CompilerServices;
10 |
11 | namespace FrontEnd.Logging
12 | {
13 | ///
14 | /// Class that encapsulates the caller's (creator's) information. This is helpful to provide more context in log statements.
15 | ///
16 | public class CallerInfo
17 | {
18 | private static ConcurrentDictionary toStringCache = new ConcurrentDictionary();
19 |
20 | ///
21 | /// The name of the method or property of the caller
22 | ///
23 | public string MemberName { get; protected set; }
24 |
25 | ///
26 | /// The full path of the source file of the caller
27 | ///
28 | public string FilePath { get; protected set; }
29 |
30 | ///
31 | /// The line number of the source file of the caller
32 | ///
33 | public int LineNumber { get; protected set; }
34 |
35 | ///
36 | /// Creates a new instance of the CallerInfo class
37 | ///
38 | public CallerInfo(
39 | [CallerMemberName] string memberName = "",
40 | [CallerFilePath] string filePath = "",
41 | [CallerLineNumber] int lineNumber = 0
42 | )
43 | {
44 | this.MemberName = memberName;
45 | this.FilePath = filePath;
46 | this.LineNumber = lineNumber;
47 | }
48 |
49 | ///
50 | /// Get the hashcode for this instance
51 | ///
52 | ///
53 | public override int GetHashCode()
54 | {
55 | return MemberName.GetHashCode() ^ FilePath.GetHashCode() ^ LineNumber;
56 | }
57 |
58 | ///
59 | /// String representation of the caller's info
60 | ///
61 | ///
62 | public override string ToString()
63 | {
64 | return toStringCache.GetOrAdd(this.GetHashCode(), hc => String.Format(
65 | "{0},{1}({2})",
66 | this.MemberName,
67 | Path.GetFileName(this.FilePath),
68 | this.LineNumber
69 | ));
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Logging/CorrelationId.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.Remoting.Messaging;
8 |
9 | namespace FrontEnd.Logging
10 | {
11 | internal class CorrelationId
12 | {
13 | private class Holder : MarshalByRefObject
14 | {
15 | public string Id;
16 | }
17 |
18 | internal const string LogicalDataName = "FrontEnd.Logging.CorrelationId";
19 |
20 | ///
21 | /// Sets the current correlation ID. This is necessary to call in event handler callbacks because the event producer
22 | /// may not be aware of the call id.
23 | ///
24 | ///
25 | public static void SetCurrentId(string value)
26 | {
27 | if (string.IsNullOrEmpty(value))
28 | {
29 | return;
30 | }
31 |
32 | Holder holder = CallContext.LogicalGetData(LogicalDataName) as Holder;
33 | if (holder == null)
34 | {
35 | CallContext.LogicalSetData(LogicalDataName, new Holder { Id = value });
36 | }
37 | else
38 | {
39 | try
40 | {
41 | holder.Id = value;
42 | }
43 | catch (AppDomainUnloadedException)
44 | {
45 | CallContext.LogicalSetData(LogicalDataName, new Holder { Id = value });
46 | }
47 | }
48 | }
49 |
50 | ///
51 | /// Gets the current correlation id.
52 | ///
53 | ///
54 | public static string GetCurrentId()
55 | {
56 | Holder holder = CallContext.LogicalGetData(LogicalDataName) as Holder;
57 | if (holder != null)
58 | {
59 | try
60 | {
61 | return holder.Id;
62 | }
63 | catch (AppDomainUnloadedException)
64 | {
65 | CallContext.FreeNamedDataSlot(LogicalDataName);
66 | return null;
67 | }
68 | }
69 |
70 | return null;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/MediaLogic/AudioSendBuffer.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.InteropServices;
8 | using FrontEnd.Logging;
9 | using Microsoft.Skype.Bots.Media;
10 |
11 |
12 | namespace FrontEnd.Media
13 | {
14 | ///
15 | /// Creates an Audio Buffer for Send and also implements Dispose
16 | ///
17 | class AudioSendBuffer : AudioMediaBuffer
18 | {
19 | private bool _disposed;
20 |
21 | [DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
22 | public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
23 |
24 | public AudioSendBuffer(IntPtr mediaBuffer, long length, AudioFormat format, long timeStamp)
25 | {
26 | Data = mediaBuffer;
27 | Length = length;
28 | AudioFormat = format;
29 | Timestamp = timeStamp;
30 | }
31 |
32 | protected override void Dispose(bool disposing)
33 | {
34 | if (!_disposed)
35 | {
36 | Marshal.FreeHGlobal(Data);
37 | }
38 |
39 | _disposed = true;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/MediaLogic/VideoSendBuffer.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.InteropServices;
8 | using System.Threading;
9 | using Microsoft.Skype.Bots.Media;
10 |
11 | namespace FrontEnd.Media
12 | {
13 | ///
14 | /// Creates a Video Buffer for Send and also implements Dispose
15 | ///
16 | class VideoSendBuffer : VideoMediaBuffer
17 | {
18 | private int _disposed;
19 |
20 | public VideoSendBuffer(IntPtr data, long length, VideoFormat videoformat, long timeStamp)
21 | {
22 | Data = data;
23 | Length = length;
24 | VideoFormat = videoformat;
25 | Timestamp = timeStamp;
26 | }
27 |
28 | protected override void Dispose(bool disposing)
29 | {
30 | if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0)
31 | {
32 | Marshal.FreeHGlobal(Data);
33 | Data = IntPtr.Zero;
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Reflection;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | [assembly: AssemblyTitle("FrontEnd")]
14 | [assembly: AssemblyDescription("")]
15 | [assembly: AssemblyConfiguration("")]
16 | [assembly: AssemblyCompany("")]
17 | [assembly: AssemblyProduct("FrontEnd")]
18 | [assembly: AssemblyCopyright("Copyright © 2016")]
19 | [assembly: AssemblyTrademark("")]
20 | [assembly: AssemblyCulture("")]
21 |
22 | // Setting ComVisible to false makes the types in this assembly not visible
23 | // to COM components. If you need to access a type in this assembly from
24 | // COM, set the ComVisible attribute to true on that type.
25 | [assembly: ComVisible(false)]
26 |
27 | // The following GUID is for the ID of the typelib if this project is exposed to COM
28 | [assembly: Guid("bd841814-05f3-498d-834d-cc7afe2a8f1a")]
29 |
30 | // Version information for an assembly consists of the following four values:
31 | //
32 | // Major Version
33 | // Minor Version
34 | // Build Number
35 | // Revision
36 | //
37 | // You can specify all the values or you can default the Build and Revision Numbers
38 | // by using the '*' as shown below:
39 | // [assembly: AssemblyVersion("1.0.*")]
40 | [assembly: AssemblyVersion("1.0.0.0")]
41 | [assembly: AssemblyFileVersion("1.0.0.0")]
42 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_AH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_AH.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_EH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_EH.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_FV.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_FV.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_L_TH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_L_TH.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_MM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_MM.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_OH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_OH.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_OOH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_OOH.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_S_D_H_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_S_D_H_Z.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_U.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_U.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_neutral.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Resources/avatar_neutral.png
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Ttvs/VisemesTimeline.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Collections.Generic;
7 |
8 | namespace FrontEnd.Ttvs
9 | {
10 | ///
11 | /// A representation of a visemes timeline
12 | ///
13 | class VisemesTimeline
14 | {
15 | private int _referenceTimeStamp = 0;
16 |
17 | private readonly SortedDictionary _visemesIds = new SortedDictionary();
18 |
19 | public int Length => _referenceTimeStamp;
20 |
21 | ///
22 | /// Add a viseme id
23 | ///
24 | /// The id of the viseme
25 | /// The duration in ms starting from the previous viseme
26 | public void Add(int visemeId, int durationInMs)
27 | {
28 | _referenceTimeStamp += durationInMs;
29 |
30 | _visemesIds.Add(_referenceTimeStamp, visemeId);
31 | }
32 |
33 | ///
34 | /// Get the viseme id for the given timestamp
35 | ///
36 | ///
37 | ///
38 | public int Get(int timestamp)
39 | {
40 | var visemeId = 0;
41 | foreach (var key in _visemesIds.Keys)
42 | {
43 | if (timestamp < key)
44 | {
45 | _visemesIds.TryGetValue(key, out visemeId);
46 | break;
47 | }
48 | }
49 | return visemeId;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/Utilities.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Drawing;
8 | using System.Drawing.Imaging;
9 | using System.Runtime.InteropServices;
10 | using System.Threading.Tasks;
11 | using FrontEnd.Logging;
12 | using Microsoft.Skype.Bots.Media;
13 |
14 | namespace FrontEnd
15 | {
16 | internal static class Utilities
17 | {
18 | ///
19 | /// Extension for Task to execute the task in background and log any exception
20 | ///
21 | ///
22 | ///
23 | public static async void ForgetAndLogException(this Task task, string description = null)
24 | {
25 | try
26 | {
27 | await task.ConfigureAwait(false);
28 | }
29 | catch (Exception e)
30 | {
31 | //ignore
32 | Log.Error(new CallerInfo(),
33 | LogContext.FrontEnd,
34 | "Caught an Exception running the task: {0} \n StackTrace: {1}", e.Message, e.StackTrace);
35 | }
36 | }
37 | ///
38 | /// Convert the bitmap to a byte array
39 | ///
40 | public static byte[] BitmapToByteArray(Bitmap inputBitmap, VideoFormat videoFormat)
41 | {
42 | // resize bitmap to match the videoformat
43 | Bitmap bmp = new Bitmap(inputBitmap, videoFormat.Width, videoFormat.Height);
44 |
45 | BitmapData bData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
46 |
47 | int lineSize = bData.Width * 3;
48 | int byteCount = lineSize * bData.Height;
49 | byte[] bytes = new byte[byteCount];
50 |
51 | IntPtr scan = bData.Scan0;
52 | for (int i = 0; i < bData.Height; i++)
53 | {
54 | Marshal.Copy(scan, bytes, i * lineSize, lineSize);
55 | scan += bData.Stride;
56 | }
57 | return bytes;
58 | }
59 |
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/FrontEnd/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/ServiceConfiguration.Cloud.cscfg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/TextToVideoSpeech.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.6
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "TextToVideoSpeech", "TextToVideoSpeech.ccproj", "{4EABD84F-6AD2-48D5-B286-B86758D4F806}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A} = {BD841814-05F3-498D-834D-CC7AFE2A8F1A}
9 | EndProjectSection
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkerRole", "WorkerRole\WorkerRole.csproj", "{9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}"
12 | EndProject
13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrontEnd", "FrontEnd\FrontEnd.csproj", "{BD841814-05F3-498D-834D-CC7AFE2A8F1A}"
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|x64 = Debug|x64
18 | Release|x64 = Release|x64
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Debug|x64.ActiveCfg = Debug|Any CPU
22 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Debug|x64.Build.0 = Debug|Any CPU
23 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Release|x64.ActiveCfg = Release|Any CPU
24 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Release|x64.Build.0 = Release|Any CPU
25 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Debug|x64.ActiveCfg = Debug|x64
26 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Debug|x64.Build.0 = Debug|x64
27 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Release|x64.ActiveCfg = Release|x64
28 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Release|x64.Build.0 = Release|x64
29 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Debug|x64.ActiveCfg = Debug|x64
30 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Debug|x64.Build.0 = Debug|x64
31 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Release|x64.ActiveCfg = Release|x64
32 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Release|x64.Build.0 = Release|x64
33 | EndGlobalSection
34 | GlobalSection(SolutionProperties) = preSolution
35 | HideSolutionNode = FALSE
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/InstallMediaFoundation.ps1:
--------------------------------------------------------------------------------
1 | # Error handling
2 | trap
3 | {
4 | Write-Output "Error Hit: $_"
5 | Write-Output "Error File: $($_.InvocationInfo.ScriptName)"
6 | Write-Output "Error Line #: $($_.InvocationInfo.ScriptLineNumber)"
7 | Write-Output ""
8 | Write-Output "Exception: $($_.Exception)"
9 | Write-Output ""
10 | Write-Output "Exception.InnerException: $($_.Exception.InnerException)"
11 | exit 1
12 | }
13 |
14 | Write-Output "Checking if Media Foundation is installed"
15 | if((Get-WindowsFeature Server-Media-Foundation).Installed -eq 0)
16 | {
17 | Write-Output "Installing Media Foundation."
18 | Add-WindowsFeature Server-Media-Foundation
19 |
20 | Write-Output "Rebooting VM for changes to take effect."
21 | Restart-Computer
22 | }
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/InstallNETFX.cmd:
--------------------------------------------------------------------------------
1 | REM Code Courtesy https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-install-dotnet/
2 | REM Set the value of netfx to install appropriate .NET Framework.
3 | REM ***** To install .NET 4.5.2 set the variable netfx to "NDP452" *****
4 | REM ***** To install .NET 4.6 set the variable netfx to "NDP46" *****
5 | REM ***** To install .NET 4.6.1 set the variable netfx to "NDP461" *****
6 | set netfx="%NetFxVersion%"
7 |
8 | REM ***** Needed to correctly install .NET 4.6.1, otherwise you may see an out of disk space error *****
9 | set TMP=%PathToNETFXInstall%
10 | set TEMP=%PathToNETFXInstall%
11 |
12 | REM ***** Setup .NET filenames and registry keys *****
13 | if %netfx%=="NDP461" goto NDP461
14 | if %netfx%=="NDP46" goto NDP46
15 | set netfxinstallfile="NDP452-KB2901954-Web.exe"
16 | set netfxregkey="0x5cbf5"
17 | goto logtimestamp
18 |
19 | :NDP46
20 | set netfxinstallfile="NDP46-KB3045560-Web.exe"
21 | set netfxregkey="0x60051"
22 | goto logtimestamp
23 |
24 | :NDP461
25 | set netfxinstallfile="NDP461-KB3102438-Web.exe"
26 | set netfxregkey="0x6041f"
27 |
28 | :logtimestamp
29 | REM ***** Setup LogFile with timestamp *****
30 | set timehour=%time:~0,2%
31 | set timestamp=%date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour: =0%%time:~3,2%
32 | md "%PathToNETFXInstall%\log"
33 | set startuptasklog="%PathToNETFXInstall%log\startuptasklog-%timestamp%.txt"
34 | set netfxinstallerlog="%PathToNETFXInstall%log\NetFXInstallerLog-%timestamp%"
35 |
36 | echo Logfile generated at: %startuptasklog% >> %startuptasklog%
37 | echo TMP set to: %TMP% >> %startuptasklog%
38 | echo TEMP set to: %TEMP% >> %startuptasklog%
39 |
40 | REM ***** Check if .NET is installed *****
41 | echo Checking if .NET (%netfx%) is installed >> %startuptasklog%
42 | reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v Release | Find %netfxregkey%
43 | if %ERRORLEVEL%== 0 goto end
44 |
45 | REM ***** Installing .NET *****
46 | echo Installing .NET: start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% >> %startuptasklog%
47 | start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% >> %startuptasklog% 2>>&1
48 |
49 | :end
50 | echo install.cmd completed: %date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour: =0%%time:~3,2% >> %startuptasklog%
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/NDP461-KB3102438-Web.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/NDP461-KB3102438-Web.exe
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Reflection;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | [assembly: AssemblyTitle("WorkerRole")]
14 | [assembly: AssemblyDescription("")]
15 | [assembly: AssemblyConfiguration("")]
16 | [assembly: AssemblyCompany("")]
17 | [assembly: AssemblyProduct("WorkerRole")]
18 | [assembly: AssemblyCopyright("Copyright © 2016")]
19 | [assembly: AssemblyTrademark("")]
20 | [assembly: AssemblyCulture("")]
21 |
22 | // Setting ComVisible to false makes the types in this assembly not visible
23 | // to COM components. If you need to access a type in this assembly from
24 | // COM, set the ComVisible attribute to true on that type.
25 | [assembly: ComVisible(false)]
26 |
27 | // The following GUID is for the ID of the typelib if this project is exposed to COM
28 | [assembly: Guid("9f593a7b-8935-4bc8-9fbb-c3a9e3bc2a23")]
29 |
30 | // Version information for an assembly consists of the following four values:
31 | //
32 | // Major Version
33 | // Minor Version
34 | // Build Number
35 | // Revision
36 | //
37 | // You can specify all the values or you can default the Build and Revision Numbers
38 | // by using the '*' as shown below:
39 | // [assembly: AssemblyVersion("1.0.*")]
40 | [assembly: AssemblyVersion("1.0.0.0")]
41 | [assembly: AssemblyFileVersion("1.0.0.0")]
42 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/SetupMediaFoundation.cmd:
--------------------------------------------------------------------------------
1 | echo Launching Powershell to install Media Foundation
2 | PowerShell -ExecutionPolicy Unrestricted .\InstallMediaFoundation.ps1 >> InstallMediaFoundation.log 2>&1
3 | EXIT /B 0
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/TextToVideoSpeech/WorkerRole/startup.cmd:
--------------------------------------------------------------------------------
1 | REM --- Move to this scripts location ---
2 | pushd "%~dp0"
3 |
4 | REM --- Print out environment variables for debugging ---
5 | set
6 |
7 | REM--- Register media perf dlls ---
8 | powershell .\skype_media_lib\MediaPlatformStartupScript.bat
9 |
10 | REM --- Delete existing certificate bindings and URL ACL registrations ---
11 | netsh http delete sslcert ipport=%InstanceIpAddress%:%PrivateDefaultCallControlPort%
12 | netsh http delete sslcert ipport=%InstanceIpAddress%:%PrivateInstanceCallControlPort%
13 | netsh http delete urlacl url=https://%InstanceIpAddress%:%PrivateDefaultCallControlPort%/
14 | netsh http delete urlacl url=https://%InstanceIpAddress%:%PrivateInstanceCallControlPort%/
15 |
16 | REM --- Delete new URL ACLs and certificate bindings ---
17 | netsh http add urlacl url=https://%InstanceIpAddress%:%PrivateDefaultCallControlPort%/ user="NT AUTHORITY\NETWORK SERVICE"
18 | netsh http add urlacl url=https://%InstanceIpAddress%:%PrivateInstanceCallControlPort%/ user="NT AUTHORITY\NETWORK SERVICE"
19 | netsh http add sslcert ipport=%InstanceIpAddress%:%PrivateDefaultCallControlPort% clientcertnegotiation=enable "appid={00000000-0000-0000-0000-000000000001}" cert=%DefaultCertificate%
20 | netsh http add sslcert ipport=%InstanceIpAddress%:%PrivateInstanceCallControlPort% clientcertnegotiation=enable "appid={00000000-0000-0000-0000-000000000001}" cert=%DefaultCertificate%
21 |
22 | REM --- Disable strong-name validation. This should not be needed once all external binaries are properly signed ---
23 | REGEDIT /S %~dp0\DisableStrongNameVerification.reg
24 |
25 | popd
26 | exit /b 0
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | # User-specific files
6 | *.suo
7 | *.user
8 | *.userosscache
9 | *.sln.docstates
10 |
11 | # User-specific files (MonoDevelop/Xamarin Studio)
12 | *.userprefs
13 | .vs/
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | [Xx]64/
21 | [Xx]86/
22 | [Bb]uild/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | /packages
27 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Http/CallEndpointStartup.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Web.Http;
7 | using System.Web.Http.ExceptionHandling;
8 | using FrontEnd.Logging;
9 | using Owin;
10 | using Microsoft.Bot.Builder.RealTimeMediaCalling.ObjectModel.Misc;
11 |
12 | namespace FrontEnd.Http
13 | {
14 | ///
15 | /// Initialize the httpConfiguration for OWIN
16 | ///
17 | public class CallEndpointStartup
18 | {
19 | ///
20 | /// Configuration settings like Auth, Routes for OWIN
21 | ///
22 | ///
23 |
24 | public void Configuration(IAppBuilder app)
25 | {
26 | HttpConfiguration httpConfig = new HttpConfiguration();
27 | httpConfig.MapHttpAttributeRoutes();
28 | httpConfig.MessageHandlers.Add(new LoggingMessageHandler(isIncomingMessageHandler: true, logContext: LogContext.FrontEnd));
29 |
30 | httpConfig.Services.Add(typeof(IExceptionLogger), new ExceptionLogger());
31 | httpConfig.Formatters.JsonFormatter.SerializerSettings = RealTimeMediaSerializer.GetSerializerSettings();
32 | httpConfig.EnsureInitialized();
33 |
34 | app.UseWebApi(httpConfig);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Http/ExceptionLogger.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using System.Web.Http.ExceptionHandling;
9 | using FrontEnd.Logging;
10 |
11 | namespace FrontEnd.Http
12 | {
13 | internal class ExceptionLogger : IExceptionLogger
14 | {
15 | public ExceptionLogger()
16 | {
17 | }
18 |
19 | public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
20 | {
21 | Log.Error(new CallerInfo(), LogContext.FrontEnd, "Exception processing HTTP request. {0}", context.Exception.ToString());
22 | return Task.FromResult(null);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Http/HttpRouteConstants.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | namespace FrontEnd.Http
7 | {
8 | ///
9 | /// HTTP route constants for routing requests to CallController methods.
10 | ///
11 | public static class HttpRouteConstants
12 | {
13 | ///
14 | /// Route prefix for all incoming requests.
15 | ///
16 | public const string CallSignalingRoutePrefix = "api/calling";
17 |
18 | ///
19 | /// Route for incoming calls.
20 | ///
21 | public const string OnIncomingCallRoute = "call";
22 |
23 | ///
24 | /// Route for existing call callbacks.
25 | ///
26 | public const string OnCallbackRoute = "callback";
27 |
28 | ///
29 | /// Route for existing call notifications.
30 | ///
31 | public const string OnNotificationRoute = "notification";
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Http/RealTimeMediaCallingBotServiceSettings.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using Microsoft.Bot.Builder.RealTimeMediaCalling;
8 |
9 | namespace FrontEnd.Http
10 | {
11 | ///
12 | /// Service settings to configure the RealTimeMediaCalling
13 | ///
14 | public class RealTimeMediaCallingBotServiceSettings : IRealTimeMediaCallServiceSettings
15 | {
16 | ///
17 | /// The url where the callbacks for the calls to this bot needs to be sent.
18 | /// For example "https://testservice.azurewebsites.net/api/calling/callback"
19 | ///
20 | public Uri CallbackUrl { get; private set; }
21 |
22 | ///
23 | /// The url where the notifications for the calls to this bot needs to be sent.
24 | /// For example "https://testservice.azurewebsites.net/api/calling/notification"
25 | ///
26 | public Uri NotificationUrl { get; private set; }
27 |
28 | public RealTimeMediaCallingBotServiceSettings()
29 | {
30 | CallbackUrl = Service.Instance.Configuration.CallControlCallbackUrl;
31 | NotificationUrl = Service.Instance.Configuration.NotificationCallbackUrl;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/IConfiguration.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using Microsoft.Skype.Bots.Media;
7 | using System;
8 | using System.Collections.Generic;
9 |
10 | namespace FrontEnd
11 | {
12 | ///
13 | /// IConfiguration contains the static configuration information the application needs
14 | /// to run such as the urls it needs to listen on, credentials to communicate with
15 | /// Bing translator, settings for media.platform, etc.
16 | ///
17 | /// The concrete implementation AzureConfiguration gets the configuration from Azure. However,
18 | /// other concrete classes could be created to allow the application to run outside of Azure
19 | /// for testing.
20 | ///
21 | public interface IConfiguration : IDisposable
22 | {
23 | ///
24 | /// List of HTTP urls the app should listen on for incoming call
25 | /// signaling requests from Skype Platform.
26 | ///
27 | IEnumerable CallControlListeningUrls { get; }
28 |
29 | ///
30 | /// The base callback URL for this instance. To ensure that all requests
31 | /// for a given call go to the same instance, this Url is unique to each
32 | /// instance by way of its instance input endpoint port.
33 | ///
34 | Uri CallControlCallbackUrl { get; }
35 |
36 | ///
37 | /// The template for call notifications like call state change notifications.
38 | /// To ensure that all requests for a given call go to the same instance, this Url
39 | /// is unique to each instance by way of its instance input endpoint port.
40 | ///
41 | Uri NotificationCallbackUrl { get; }
42 |
43 | ///
44 | /// MicrosoftAppId generated at the time of registration of the bot
45 | ///
46 | string MicrosoftAppId { get; }
47 |
48 | string StorageAccountConnection { get; }
49 |
50 | string AudioContainer { get; }
51 |
52 | string AudioFile { get; }
53 |
54 | string VideoContainer { get; }
55 |
56 | string VideoFile { get; }
57 |
58 | ///
59 | /// Settings for the bot media platform
60 | ///
61 | MediaPlatformSettings MediaPlatformSettings { get; }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Logging/CallerInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Collections.Concurrent;
8 | using System.IO;
9 | using System.Runtime.CompilerServices;
10 |
11 | namespace FrontEnd.Logging
12 | {
13 | ///
14 | /// Class that encapsulates the caller's (creator's) information. This is helpful to provide more context in log statements.
15 | ///
16 | public class CallerInfo
17 | {
18 | private static ConcurrentDictionary toStringCache = new ConcurrentDictionary();
19 |
20 | ///
21 | /// The name of the method or property of the caller
22 | ///
23 | public string MemberName { get; protected set; }
24 |
25 | ///
26 | /// The full path of the source file of the caller
27 | ///
28 | public string FilePath { get; protected set; }
29 |
30 | ///
31 | /// The line number of the source file of the caller
32 | ///
33 | public int LineNumber { get; protected set; }
34 |
35 | ///
36 | /// Creates a new instance of the CallerInfo class
37 | ///
38 | public CallerInfo(
39 | [CallerMemberName] string memberName = "",
40 | [CallerFilePath] string filePath = "",
41 | [CallerLineNumber] int lineNumber = 0
42 | )
43 | {
44 | this.MemberName = memberName;
45 | this.FilePath = filePath;
46 | this.LineNumber = lineNumber;
47 | }
48 |
49 | ///
50 | /// Get the hashcode for this instance
51 | ///
52 | ///
53 | public override int GetHashCode()
54 | {
55 | return MemberName.GetHashCode() ^ FilePath.GetHashCode() ^ LineNumber;
56 | }
57 |
58 | ///
59 | /// String representation of the caller's info
60 | ///
61 | ///
62 | public override string ToString()
63 | {
64 | return toStringCache.GetOrAdd(this.GetHashCode(), hc => String.Format(
65 | "{0},{1}({2})",
66 | this.MemberName,
67 | Path.GetFileName(this.FilePath),
68 | this.LineNumber
69 | ));
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Logging/CorrelationId.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.Remoting.Messaging;
8 |
9 | namespace FrontEnd.Logging
10 | {
11 | internal class CorrelationId
12 | {
13 | private class Holder : MarshalByRefObject
14 | {
15 | public string Id;
16 | }
17 |
18 | internal const string LogicalDataName = "FrontEnd.Logging.CorrelationId";
19 |
20 | ///
21 | /// Sets the current correlation ID. This is necessary to call in event handler callbacks because the event producer
22 | /// may not be aware of the call id.
23 | ///
24 | ///
25 | public static void SetCurrentId(string value)
26 | {
27 | if (string.IsNullOrEmpty(value))
28 | {
29 | return;
30 | }
31 |
32 | Holder holder = CallContext.LogicalGetData(LogicalDataName) as Holder;
33 | if (holder == null)
34 | {
35 | CallContext.LogicalSetData(LogicalDataName, new Holder { Id = value });
36 | }
37 | else
38 | {
39 | try
40 | {
41 | holder.Id = value;
42 | }
43 | catch (AppDomainUnloadedException)
44 | {
45 | CallContext.LogicalSetData(LogicalDataName, new Holder { Id = value });
46 | }
47 | }
48 | }
49 |
50 | ///
51 | /// Gets the current correlation id.
52 | ///
53 | ///
54 | public static string GetCurrentId()
55 | {
56 | Holder holder = CallContext.LogicalGetData(LogicalDataName) as Holder;
57 | if (holder != null)
58 | {
59 | try
60 | {
61 | return holder.Id;
62 | }
63 | catch (AppDomainUnloadedException)
64 | {
65 | CallContext.FreeNamedDataSlot(LogicalDataName);
66 | return null;
67 | }
68 | }
69 |
70 | return null;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/MediaLogic/AudioSendBuffer.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.InteropServices;
8 | using System.Threading;
9 | using Microsoft.Skype.Bots.Media;
10 |
11 |
12 | namespace FrontEnd.Media
13 | {
14 | ///
15 | /// Creates an Audio Buffer for Send and also implements Dispose
16 | ///
17 | class AudioSendBuffer : AudioMediaBuffer
18 | {
19 | private int _disposed;
20 |
21 | public AudioSendBuffer(IntPtr data, long length, AudioFormat audioFormat, long timeStamp)
22 | {
23 | Data = data;
24 | Length = length;
25 | AudioFormat = audioFormat;
26 | Timestamp = timeStamp;
27 | }
28 |
29 | protected override void Dispose(bool disposing)
30 | {
31 | if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0)
32 | {
33 | Marshal.FreeHGlobal(Data);
34 | Data = IntPtr.Zero;
35 | }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/MediaLogic/VideoSendBuffer.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Runtime.InteropServices;
8 | using System.Threading;
9 | using Microsoft.Skype.Bots.Media;
10 |
11 | namespace FrontEnd.Media
12 | {
13 | ///
14 | /// Creates a Video Buffer for Send and also implements Dispose
15 | ///
16 | class VideoSendBuffer : VideoMediaBuffer
17 | {
18 | private int _disposed;
19 |
20 | public VideoSendBuffer(IntPtr data, long length, VideoFormat videoformat, long timeStamp)
21 | {
22 | Data = data;
23 | Length = length;
24 | VideoFormat = videoformat;
25 | Timestamp = timeStamp;
26 | }
27 |
28 | protected override void Dispose(bool disposing)
29 | {
30 | if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0)
31 | {
32 | Marshal.FreeHGlobal(Data);
33 | Data = IntPtr.Zero;
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Reflection;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | [assembly: AssemblyTitle("FrontEnd")]
14 | [assembly: AssemblyDescription("")]
15 | [assembly: AssemblyConfiguration("")]
16 | [assembly: AssemblyCompany("")]
17 | [assembly: AssemblyProduct("FrontEnd")]
18 | [assembly: AssemblyCopyright("Copyright © 2016")]
19 | [assembly: AssemblyTrademark("")]
20 | [assembly: AssemblyCulture("")]
21 |
22 | // Setting ComVisible to false makes the types in this assembly not visible
23 | // to COM components. If you need to access a type in this assembly from
24 | // COM, set the ComVisible attribute to true on that type.
25 | [assembly: ComVisible(false)]
26 |
27 | // The following GUID is for the ID of the typelib if this project is exposed to COM
28 | [assembly: Guid("bd841814-05f3-498d-834d-cc7afe2a8f1a")]
29 |
30 | // Version information for an assembly consists of the following four values:
31 | //
32 | // Major Version
33 | // Minor Version
34 | // Build Number
35 | // Revision
36 | //
37 | // You can specify all the values or you can default the Build and Revision Numbers
38 | // by using the '*' as shown below:
39 | // [assembly: AssemblyVersion("1.0.*")]
40 | [assembly: AssemblyVersion("1.0.0.0")]
41 | [assembly: AssemblyFileVersion("1.0.0.0")]
42 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/Utilities.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System;
7 | using System.Threading.Tasks;
8 | using FrontEnd.Logging;
9 |
10 | namespace FrontEnd
11 | {
12 | internal static class Utilities
13 | {
14 | ///
15 | /// Extension for Task to execute the task in background and log any exception
16 | ///
17 | ///
18 | ///
19 | public static async void ForgetAndLogException(this Task task, string description = null)
20 | {
21 | try
22 | {
23 | await task.ConfigureAwait(false);
24 | }
25 | catch (Exception e)
26 | {
27 | //ignore
28 | Log.Error(new CallerInfo(),
29 | LogContext.FrontEnd,
30 | "Caught an Exception running the task: {0} \n StackTrace: {1}", e.Message, e.StackTrace);
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/FrontEnd/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/ServiceConfiguration.Cloud.cscfg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/ServiceConfiguration.Local.cscfg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/VideoPlayer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.16
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "VideoPlayer", "VideoPlayer.ccproj", "{4EABD84F-6AD2-48D5-B286-B86758D4F806}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A} = {BD841814-05F3-498D-834D-CC7AFE2A8F1A}
9 | EndProjectSection
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkerRole", "WorkerRole\WorkerRole.csproj", "{9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}"
12 | EndProject
13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrontEnd", "FrontEnd\FrontEnd.csproj", "{BD841814-05F3-498D-834D-CC7AFE2A8F1A}"
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|x64 = Debug|x64
18 | Release|x64 = Release|x64
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Debug|x64.ActiveCfg = Debug|Any CPU
22 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Debug|x64.Build.0 = Debug|Any CPU
23 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Release|x64.ActiveCfg = Release|Any CPU
24 | {4EABD84F-6AD2-48D5-B286-B86758D4F806}.Release|x64.Build.0 = Release|Any CPU
25 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Debug|x64.ActiveCfg = Debug|x64
26 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Debug|x64.Build.0 = Debug|x64
27 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Release|x64.ActiveCfg = Release|x64
28 | {9F593A7B-8935-4BC8-9FBB-C3A9E3BC2A23}.Release|x64.Build.0 = Release|x64
29 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Debug|x64.ActiveCfg = Debug|x64
30 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Debug|x64.Build.0 = Debug|x64
31 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Release|x64.ActiveCfg = Release|x64
32 | {BD841814-05F3-498D-834D-CC7AFE2A8F1A}.Release|x64.Build.0 = Release|x64
33 | EndGlobalSection
34 | GlobalSection(SolutionProperties) = preSolution
35 | HideSolutionNode = FALSE
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/InstallMediaFoundation.ps1:
--------------------------------------------------------------------------------
1 | # Error handling
2 | trap
3 | {
4 | Write-Output "Error Hit: $_"
5 | Write-Output "Error File: $($_.InvocationInfo.ScriptName)"
6 | Write-Output "Error Line #: $($_.InvocationInfo.ScriptLineNumber)"
7 | Write-Output ""
8 | Write-Output "Exception: $($_.Exception)"
9 | Write-Output ""
10 | Write-Output "Exception.InnerException: $($_.Exception.InnerException)"
11 | exit 1
12 | }
13 |
14 | Write-Output "Checking if Media Foundation is installed"
15 | if((Get-WindowsFeature Server-Media-Foundation).Installed -eq 0)
16 | {
17 | Write-Output "Installing Media Foundation."
18 | Add-WindowsFeature Server-Media-Foundation
19 |
20 | Write-Output "Rebooting VM for changes to take effect."
21 | Restart-Computer
22 | }
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/InstallNETFX.cmd:
--------------------------------------------------------------------------------
1 | REM Code Courtesy https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-install-dotnet/
2 | REM Set the value of netfx to install appropriate .NET Framework.
3 | REM ***** To install .NET 4.5.2 set the variable netfx to "NDP452" *****
4 | REM ***** To install .NET 4.6 set the variable netfx to "NDP46" *****
5 | REM ***** To install .NET 4.6.1 set the variable netfx to "NDP461" *****
6 | set netfx="%NetFxVersion%"
7 |
8 | REM ***** Needed to correctly install .NET 4.6.1, otherwise you may see an out of disk space error *****
9 | set TMP=%PathToNETFXInstall%
10 | set TEMP=%PathToNETFXInstall%
11 |
12 | REM ***** Setup .NET filenames and registry keys *****
13 | if %netfx%=="NDP461" goto NDP461
14 | if %netfx%=="NDP46" goto NDP46
15 | set netfxinstallfile="NDP452-KB2901954-Web.exe"
16 | set netfxregkey="0x5cbf5"
17 | goto logtimestamp
18 |
19 | :NDP46
20 | set netfxinstallfile="NDP46-KB3045560-Web.exe"
21 | set netfxregkey="0x60051"
22 | goto logtimestamp
23 |
24 | :NDP461
25 | set netfxinstallfile="NDP461-KB3102438-Web.exe"
26 | set netfxregkey="0x6041f"
27 |
28 | :logtimestamp
29 | REM ***** Setup LogFile with timestamp *****
30 | set timehour=%time:~0,2%
31 | set timestamp=%date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour: =0%%time:~3,2%
32 | md "%PathToNETFXInstall%\log"
33 | set startuptasklog="%PathToNETFXInstall%log\startuptasklog-%timestamp%.txt"
34 | set netfxinstallerlog="%PathToNETFXInstall%log\NetFXInstallerLog-%timestamp%"
35 |
36 | echo Logfile generated at: %startuptasklog% >> %startuptasklog%
37 | echo TMP set to: %TMP% >> %startuptasklog%
38 | echo TEMP set to: %TEMP% >> %startuptasklog%
39 |
40 | REM ***** Check if .NET is installed *****
41 | echo Checking if .NET (%netfx%) is installed >> %startuptasklog%
42 | reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v Release | Find %netfxregkey%
43 | if %ERRORLEVEL%== 0 goto end
44 |
45 | REM ***** Installing .NET *****
46 | echo Installing .NET: start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% >> %startuptasklog%
47 | start /wait %~dp0%netfxinstallfile% /q /serialdownload /log %netfxinstallerlog% >> %startuptasklog% 2>>&1
48 |
49 | :end
50 | echo install.cmd completed: %date:~-4,4%%date:~-10,2%%date:~-7,2%-%timehour: =0%%time:~3,2% >> %startuptasklog%
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/NDP461-KB3102438-Web.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/NDP461-KB3102438-Web.exe
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT license.
4 | */
5 |
6 | using System.Reflection;
7 | using System.Runtime.CompilerServices;
8 | using System.Runtime.InteropServices;
9 |
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | [assembly: AssemblyTitle("WorkerRole")]
14 | [assembly: AssemblyDescription("")]
15 | [assembly: AssemblyConfiguration("")]
16 | [assembly: AssemblyCompany("")]
17 | [assembly: AssemblyProduct("WorkerRole")]
18 | [assembly: AssemblyCopyright("Copyright © 2016")]
19 | [assembly: AssemblyTrademark("")]
20 | [assembly: AssemblyCulture("")]
21 |
22 | // Setting ComVisible to false makes the types in this assembly not visible
23 | // to COM components. If you need to access a type in this assembly from
24 | // COM, set the ComVisible attribute to true on that type.
25 | [assembly: ComVisible(false)]
26 |
27 | // The following GUID is for the ID of the typelib if this project is exposed to COM
28 | [assembly: Guid("9f593a7b-8935-4bc8-9fbb-c3a9e3bc2a23")]
29 |
30 | // Version information for an assembly consists of the following four values:
31 | //
32 | // Major Version
33 | // Minor Version
34 | // Build Number
35 | // Revision
36 | //
37 | // You can specify all the values or you can default the Build and Revision Numbers
38 | // by using the '*' as shown below:
39 | // [assembly: AssemblyVersion("1.0.*")]
40 | [assembly: AssemblyVersion("1.0.0.0")]
41 | [assembly: AssemblyFileVersion("1.0.0.0")]
42 |
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/SetupMediaFoundation.cmd:
--------------------------------------------------------------------------------
1 | echo Launching Powershell to install Media Foundation
2 | PowerShell -ExecutionPolicy Unrestricted .\InstallMediaFoundation.ps1 >> InstallMediaFoundation.log 2>&1
3 | EXIT /B 0
--------------------------------------------------------------------------------
/Samples/Csharp/RealtimeMedia/VideoPlayer/WorkerRole/startup.cmd:
--------------------------------------------------------------------------------
1 | REM --- Move to this scripts location ---
2 | pushd "%~dp0"
3 |
4 | REM --- Print out environment variables for debugging ---
5 | set
6 |
7 | REM--- Register media perf dlls ---
8 | powershell .\skype_media_lib\MediaPlatformStartupScript.bat
9 |
10 | REM --- Delete existing certificate bindings and URL ACL registrations ---
11 | netsh http delete sslcert ipport=%InstanceIpAddress%:%PrivateDefaultCallControlPort%
12 | netsh http delete sslcert ipport=%InstanceIpAddress%:%PrivateInstanceCallControlPort%
13 | netsh http delete urlacl url=https://%InstanceIpAddress%:%PrivateDefaultCallControlPort%/
14 | netsh http delete urlacl url=https://%InstanceIpAddress%:%PrivateInstanceCallControlPort%/
15 |
16 | REM --- Delete new URL ACLs and certificate bindings ---
17 | netsh http add urlacl url=https://%InstanceIpAddress%:%PrivateDefaultCallControlPort%/ user="NT AUTHORITY\NETWORK SERVICE"
18 | netsh http add urlacl url=https://%InstanceIpAddress%:%PrivateInstanceCallControlPort%/ user="NT AUTHORITY\NETWORK SERVICE"
19 | netsh http add sslcert ipport=%InstanceIpAddress%:%PrivateDefaultCallControlPort% clientcertnegotiation=enable "appid={00000000-0000-0000-0000-000000000001}" cert=%DefaultCertificate%
20 | netsh http add sslcert ipport=%InstanceIpAddress%:%PrivateInstanceCallControlPort% clientcertnegotiation=enable "appid={00000000-0000-0000-0000-000000000001}" cert=%DefaultCertificate%
21 |
22 | REM --- Disable strong-name validation. This should not be needed once all external binaries are properly signed ---
23 | REGEDIT /S %~dp0\DisableStrongNameVerification.reg
24 |
25 | popd
26 | exit /b 0
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/AppSettings.cs:
--------------------------------------------------------------------------------
1 | namespace Notes
2 | {
3 | using System;
4 | using System.Configuration;
5 |
6 | public static class AppSettings
7 | {
8 | private static Lazy skypeBotId = new Lazy(() => ConfigurationManager.AppSettings["SkypeBotId"].ToString());
9 | private static Lazy skypeBotMention = new Lazy(() => ConfigurationManager.AppSettings["SkypeBotAtMention"].ToString());
10 | private static Lazy mongoDBConnectionString = new Lazy(() => ConfigurationManager.ConnectionStrings["MongoDB"].ToString());
11 | private static Lazy dbName = new Lazy(() => ConfigurationManager.AppSettings["DBName"].ToString());
12 | private static Lazy collectionName = new Lazy(() => ConfigurationManager.AppSettings["CollectionName"].ToString());
13 |
14 |
15 | public static string SkypeBotId => skypeBotId.Value;
16 | public static string DbName => dbName.Value;
17 | public static string CollectionName => collectionName.Value;
18 | public static string MongoDBConnectionString => mongoDBConnectionString.Value;
19 | }
20 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/App_Start/WebApiConfig.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Http;
2 | using Newtonsoft.Json;
3 | using Newtonsoft.Json.Serialization;
4 |
5 | namespace Notes
6 | {
7 | public static class WebApiConfig
8 | {
9 | public static void Register(HttpConfiguration config)
10 | {
11 | // Json settings
12 | config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
13 | config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
14 | new CamelCasePropertyNamesContractResolver();
15 | config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
16 | JsonConvert.DefaultSettings = () => new JsonSerializerSettings
17 | {
18 | ContractResolver = new CamelCasePropertyNamesContractResolver(),
19 | Formatting = Formatting.Indented,
20 | NullValueHandling = NullValueHandling.Ignore
21 | };
22 |
23 | // Web API configuration and services
24 |
25 | // Web API routes
26 | config.MapHttpAttributeRoutes();
27 |
28 | config.Routes.MapHttpRoute(
29 | "DefaultApi",
30 | "api/{controller}/{id}",
31 | new {id = RouteParameter.Optional}
32 | );
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Dialogs/DeleteDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Microsoft.Bot.Builder.Dialogs;
5 | using Microsoft.Bot.Connector;
6 | using Notes.Properties;
7 |
8 | namespace Notes.Dialogs
9 | {
10 | [Serializable]
11 | public sealed class DeleteDialog : IDialog
12 | {
13 | public async Task StartAsync(IDialogContext context)
14 | {
15 | // Create a reply and send it.
16 | IMessageActivity reply = context.MakeMessage();
17 | reply.Attachments.Add(GetDeleteCard().ToAttachment());
18 | await context.PostAsync(reply);
19 |
20 | context.Done(null);
21 | }
22 |
23 | private static HeroCard GetDeleteCard()
24 | {
25 | return new HeroCard
26 | {
27 | Title = Resources.DELETE_ASK_CARD_TITLE,
28 | Text = Resources.DELETE_ASK_CARD_TEXT,
29 | Buttons = new List
30 | {
31 | new CardAction(ActionTypes.ImBack, Resources.DELETE_ASK_CARD_YES, value: Resources.DELETE_FORCE),
32 | new CardAction(ActionTypes.ImBack, Resources.DELETE_ASK_CARD_NO, value: Resources.SHOW)
33 | }
34 | };
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Dialogs/DeleteForceDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Bot.Builder.Dialogs;
4 | using Microsoft.Bot.Connector;
5 | using Notes.Properties;
6 | using MongoDB.Driver;
7 | using Notes.Models;
8 | using Notes.Helpers;
9 |
10 | namespace Notes.Dialogs
11 | {
12 | [Serializable]
13 | public sealed class DeleteForceDialog : IDialog
14 | {
15 | public async Task StartAsync(IDialogContext context)
16 | {
17 | var userId = context.Activity.From.Id;
18 | var deletedCount = await DeleteNotes(userId);
19 |
20 | var replyString = deletedCount > 0 ?
21 | String.Format(Resources.DELETED_ALL_TEXT, deletedCount) :
22 | Resources.NO_NOTES_TO_DELETE;
23 |
24 | await context.PostAsync(replyString);
25 |
26 | context.Done(null);
27 | }
28 |
29 | // Delete all notes given user ID, and returns the number of deleted notes on success.
30 | private static async Task DeleteNotes(string userId)
31 | {
32 | var collection = DbSingleton.GetDatabase().GetCollection(AppSettings.CollectionName);
33 | var filter = Builders.Filter.Where(x => x.UserId == userId);
34 |
35 | var response = await collection.DeleteManyAsync(filter);
36 |
37 | return response.DeletedCount;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Dialogs/RootDialog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Microsoft.Bot.Builder.Dialogs;
5 | using Microsoft.Bot.Connector;
6 | using Notes.Properties;
7 |
8 | namespace Notes.Dialogs
9 | {
10 | [Serializable]
11 | public sealed class RootDialog : IDialog
12 | {
13 | #pragma warning disable 1998
14 | public async Task StartAsync(IDialogContext context)
15 | {
16 | context.Wait(MessageReceivedAsync);
17 | }
18 |
19 | public async Task StartAsync(IDialogContext context, IAwaitable activity)
20 | #pragma warning restore 1998
21 | {
22 | context.Wait(MessageReceivedAsync);
23 | }
24 |
25 | private async Task MessageReceivedAsync(IDialogContext context, IAwaitable activity)
26 | {
27 | var message = await activity as Activity;
28 |
29 | // Get the command, or the first word, that the user typed in.
30 | var userInput = message.Text != null ? message.Text : "";
31 | var command = (userInput.Split(new[] {' '}, 2))[0];
32 |
33 | // Command is Note.
34 | if (command.Equals(Resources.NOTE, StringComparison.CurrentCultureIgnoreCase))
35 | {
36 | await context.Forward(new NoteDialog(), this.StartAsync, message, CancellationToken.None);
37 | }
38 | // Command is Show.
39 | else if (command.Equals(Resources.SHOW, StringComparison.CurrentCultureIgnoreCase))
40 | {
41 | await context.Forward(new ShowDialog(), this.StartAsync, message, CancellationToken.None);
42 | }
43 | // Command is Delete.
44 | else if (userInput.Equals(Resources.DELETE, StringComparison.CurrentCultureIgnoreCase))
45 | {
46 | context.Call(new DeleteDialog(), this.StartAsync);
47 | }
48 | // Command is Delete force
49 | else if (userInput.Equals(Resources.DELETE_FORCE, StringComparison.CurrentCultureIgnoreCase))
50 | {
51 | context.Call(new DeleteForceDialog(), this.StartAsync);
52 | }
53 | // Command is Help or unknown.
54 | else
55 | {
56 | await context.Forward(new HelpDialog(), this.StartAsync, message, CancellationToken.None);
57 | }
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="Notes.WebApiApplication" Language="C#" %>
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System.Configuration;
2 | using System.Web;
3 | using System.Web.Http;
4 |
5 | namespace Notes
6 | {
7 | public class WebApiApplication : HttpApplication
8 | {
9 | protected void Application_Start()
10 | {
11 | GlobalConfiguration.Configure(WebApiConfig.Register);
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Helpers/DbSingleton.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Driver;
2 |
3 | namespace Notes.Helpers
4 | {
5 | public sealed class DbSingleton
6 | {
7 | private static readonly DbSingleton instance;
8 | private static IMongoDatabase database = null;
9 |
10 | private DbSingleton()
11 | {
12 | database = new MongoClient(AppSettings.MongoDBConnectionString).GetDatabase(AppSettings.DbName);
13 | }
14 |
15 | static DbSingleton()
16 | {
17 | instance = new DbSingleton();
18 | }
19 |
20 | public static IMongoDatabase GetDatabase()
21 | {
22 | return database;
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Models/Note.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using MongoDB.Bson.Serialization.Attributes;
4 |
5 | namespace Notes.Models
6 | {
7 | [Serializable]
8 | public sealed class Note
9 | {
10 | [BsonId]
11 | public string NoteId { get; set; }
12 |
13 | [BsonElement]
14 | public string UserId { get; set; }
15 |
16 | [BsonElement]
17 | public string Content { get; set; }
18 |
19 | [BsonElement]
20 | public long Timestamp { get; set; }
21 | }
22 | }
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("Notes")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Notes")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 |
25 | [assembly: Guid("a8ba1066-5695-4d71-abb4-65e5a5e0c3d4")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Revision and Build Numbers
35 | // by using the '*' as shown below:
36 |
37 | [assembly: AssemblyVersion("1.0.0.0")]
38 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/Resources/welcome_card.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Csharp/Storage-MongoDB/Notes/Bot/Resources/welcome_card.png
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/Bot/default.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Storage-NotesBot
9 | A sample bot "end-to-end" bot with a MongoDB storage solution.
10 | Visit Bot Framework to register your bot. When you register it, remember to set your bot's endpoint to
https://your_bots_hostname /api/messages
11 |
12 |
--------------------------------------------------------------------------------
/Samples/Csharp/Storage-MongoDB/Notes/NotesBot.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.16
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotesBot", "Bot\NotesBot.csproj", "{A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Samples/Node/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/.gitignore
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/.env:
--------------------------------------------------------------------------------
1 | #Bot Framework Variables
2 | MICROSOFT_APP_ID=''
3 | MICROSOFT_APP_PASSWORD=''
4 |
5 | # QnAMaker service API Variables
6 | OCP_APIM_SUBSCRIPTION_KEY=''
7 | KNOWLEDGE_BASE=''
8 | QNA_SERVICE_API_URL='https://westus.api.cognitive.microsoft.com/qnamaker/v2.0/knowledgebases/'
9 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | * app.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | require('dotenv').config();
10 |
11 | const restify = require('restify');
12 | const qnamaker = require('./src/bot/qnamaker.js');
13 |
14 | // Setup Restify Server
15 | var server = restify.createServer();
16 | server.listen(process.env.port || process.env.PORT || 3978, function () {
17 | console.log('%s listening to %s', server.name, server.url);
18 | });
19 |
20 | // Listen for messages from users
21 | server.post('/api/messages', qnamaker.connector('*').listen());
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/assets/create-kb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Knowledge/QnA/assets/create-kb.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/assets/generate-answer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Knowledge/QnA/assets/generate-answer.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/assets/kb-keys.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Knowledge/QnA/assets/kb-keys.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/assets/no-match.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Knowledge/QnA/assets/no-match.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/assets/publish-kb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Knowledge/QnA/assets/publish-kb.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "skypedevplatform-qnamaker",
3 | "version": "1.0.0",
4 | "description": "Leverage Microsoft Bot Framework and Microsoft QnA Maker REST API that trains AI to respond to user's questions in a more natural, conversational way.",
5 | "license": "@ Microsoft 2017",
6 | "engines": {
7 | "node": ">=6.7.0",
8 | "npm": ">=3.10.3"
9 | },
10 | "scripts": {
11 | "start": "node app.js",
12 | "clean": "rimraf node_modules",
13 | "start-dev": "npm run installtools && npm run start",
14 | "installtools": "npm install rimraf && npm install"
15 | },
16 | "author": "yanxz",
17 | "dependencies": {
18 | "botbuilder": "^3.9.1",
19 | "dotenv": "4.0.0",
20 | "jslint": "^0.11.0",
21 | "request": "^2.81.0",
22 | "restify": "^5.2.0"
23 | },
24 | "devDependencies": {
25 | "@types/restify": "^5.0.1"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/Strings.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Strings.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | module.exports = {
10 | QUERY_RESULT_COUNTS: 3,
11 |
12 | INTRO_TITLE: 'I am the QnA bot.',
13 | INTRO_TEXT: 'I am here to help you find answer(s) of Azure Support questions. You can also check the FAQ on Azure website.',
14 | INTRO_BUTTON_TITLE: 'Help',
15 | INTRO_BUTTON_VALUE: 'Want to know more?',
16 |
17 | HELP_BUTTON_TITLE_ASK: 'Ask a question',
18 | HELP_CARD_TEXT: 'Select a command to learn how to use it.',
19 | HELP_CHECK_THE_FAQ: 'Check the FAQ website',
20 | HELP_ASK_A_QUESTION: 'Ask a question and get the answer(s). Please start the question with **what is, How, Does, Do, Is there, Where**, and end the question with a question mark. For example: What is azure?',
21 |
22 | NO_MATCH_FROM_SERVICE: 'QnA maker was not able to find an answer for your question',
23 | NO_ANSWER_FOUND: 'No good match found in the KB',
24 | PROPOSE_QUESTION_CARD_TITLE: 'Are these questions you want to ask?',
25 | FAQ_URL: 'https://azure.microsoft.com/en-us/support/faq/'
26 | };
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/bot/qnamaker.js:
--------------------------------------------------------------------------------
1 | /**
2 | * qnamaker.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | 'use strict';
10 |
11 | global.builder = require('botbuilder');
12 |
13 | const connector = new builder.ChatConnector({
14 | appId: process.env.MICROSOFT_APP_ID,
15 | appPassword: process.env.MICROSOFT_APP_PASSWORD
16 | });
17 |
18 | global.bot = new builder.UniversalBot(connector);
19 |
20 | require('../dialogs/intro.js')();
21 | require('../dialogs/help.js')();
22 |
23 | bot.on('contactRelationUpdate', (message) => {
24 | if (message.action == 'add') {
25 | bot.beginDialog(message.address, 'intro');
26 | } else if (message.action == 'remove') {
27 | session.endConversation();
28 | session.userData = {};
29 | session.conversationData = {};
30 | session.privateConversationData = {};
31 | session.dialogData = {};
32 | }
33 | });
34 |
35 | bot.dialog('/', [
36 | (session, args) => {
37 | session.beginDialog('help');
38 | }
39 | ]);
40 |
41 | module.exports = bot;
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/controller/qnaQueryService.js:
--------------------------------------------------------------------------------
1 | /**
2 | * qnaQueryService.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | require('dotenv').config();
10 |
11 | const request = require('request');
12 |
13 | module.exports = function () {
14 | const headers = {
15 | 'content-type': 'application/json',
16 | 'Ocp-Apim-Subscription-Key': process.env.OCP_APIM_SUBSCRIPTION_KEY
17 | };
18 |
19 | function query(question, counts) {
20 | return new Promise(
21 | (resolve, reject) => {
22 | let url = buildUrl() + '/generateAnswer';
23 | if (url && headers) {
24 | const requestData = {
25 | url: url,
26 | headers: headers,
27 | body: JSON.stringify({
28 | question: question,
29 | top: counts
30 | })
31 | };
32 |
33 | request.post(requestData, (error, response, body) => {
34 | if (error || response.statusCode != 200) {
35 | reject(error);
36 | } else {
37 | resolve(body);
38 | }
39 | });
40 | } else {
41 | reject('The request url or headers is not valid.');
42 | }
43 | }
44 | );
45 | }
46 |
47 | function getFaqUrl() {
48 | return new Promise(
49 | (resolve, reject) => {
50 | let url = buildUrl();
51 | if (url && headers) {
52 | const requestData = {
53 | url: url,
54 | headers: headers
55 | };
56 |
57 | request.get(requestData, (error, response, body) => {
58 | if (error || response.statusCode != 200) {
59 | reject(error);
60 | } else {
61 | resolve(body);
62 | }
63 | });
64 | } else {
65 | reject('The request url or headers is not valid.');
66 | }
67 | }
68 | );
69 | }
70 |
71 | function buildUrl() {
72 | const url = process.env.QNA_SERVICE_API_URL;
73 | return url + process.env.KNOWLEDGE_BASE;
74 | }
75 |
76 | return {
77 | query: query,
78 | getFaqUrl: getFaqUrl
79 | };
80 | }();
81 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/dialogs/answersCarousel.js:
--------------------------------------------------------------------------------
1 | /**
2 | * answersCarousel.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | 'use strict';
10 |
11 | const _ = require('lodash');
12 | const buildCardUtils = require('../utils/buildCardUtils');
13 |
14 | module.exports = function () {
15 | bot.dialog('answersCarousel', [
16 | (session, args, next) => {
17 | session.endDialog(getShowAnswersCarousel(session, args.data));
18 | }
19 | ]);
20 |
21 | function getShowAnswersCarousel(session, data) {
22 | let meaningfulAnswerCounts = 0;
23 | let cards = new Array();
24 |
25 | _.forEach(data, (result) => {
26 | cards.push(buildCardUtils.buildCard(session, result));
27 | meaningfulAnswerCounts++;
28 | });
29 |
30 | let title = '\n**The top ' + meaningfulAnswerCounts + ' answers are:**\n\n';
31 | let reply = new builder.Message(session)
32 | .text(title)
33 | .attachmentLayout(builder.AttachmentLayout.carousel)
34 | .attachments(cards);
35 | session.send(reply);
36 | }
37 | };
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/dialogs/askQuestion.js:
--------------------------------------------------------------------------------
1 | /**
2 | * askQuestion.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | const _ = require('lodash');
10 | const qnaQueryService = require('../controller/qnaQueryService');
11 | const strings = require('../strings');
12 | var fs = require('fs');
13 |
14 | require('../dialogs/answersCarousel')();
15 | require('../dialogs/proposeQuestionsCard')();
16 |
17 | module.exports = function () {
18 | var data;
19 |
20 | bot.dialog('askQuestion', [
21 | (session, args, next) => {
22 | session.options.autoBatchDelay = 1000;
23 | let question = session.message.text;
24 |
25 | if (question) {
26 | qnaQueryService
27 | .query(question, strings.QUERY_RESULT_COUNTS)
28 | .then(results => {
29 | handleResult(session, results);
30 | },
31 | err => {
32 | return err;
33 | }
34 | );
35 | }
36 |
37 | function handleResult(session, results) {
38 | if (results) {
39 | var resultsJson = JSON.parse(results);
40 | data = resultsJson.answers;
41 |
42 | if (data && !_.isEmpty(data)) {
43 | if (data.length == 1 && data[0].answer === strings.NO_ANSWER_FOUND) {
44 | session.send(strings.NO_MATCH_FROM_SERVICE);
45 |
46 | // Get the first 3 questions from faq, and build a list carousel
47 | session.beginDialog('proposeQuestionsCard');
48 | } else {
49 | session.beginDialog('answersCarousel', { data: data });
50 | }
51 | }
52 | }
53 | }
54 | }
55 | ]).triggerAction({
56 | matches: /(what is|Question:|How to|How do|How|Does|Do|I have a question|Is there|where).*\?$/i
57 | });
58 | };
59 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/dialogs/help.js:
--------------------------------------------------------------------------------
1 | /**
2 | * help.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | const strings = require('../strings');
10 | require('./askQuestion.js')();
11 |
12 | module.exports = function () {
13 | bot.dialog('help',
14 | (session) => {
15 | let message = '';
16 | if (session.message.text == 'Ask a question') {
17 | message = strings.HELP_ASK_A_QUESTION;
18 | } else {
19 | let card = getHelpCard(session);
20 | message = new builder.Message(session).addAttachment(card);
21 | }
22 | session.endDialog(message);
23 | }
24 | )
25 | .triggerAction({
26 | matches: /^(help|h|details|want to know more\?|ask a question)$/i,
27 | });
28 |
29 | function getHelpCard(session) {
30 | return new builder.HeroCard()
31 | .title('Help')
32 | .text(strings.HELP_CARD_TEXT)
33 | .buttons([
34 | new builder.CardAction(session).title(strings.HELP_BUTTON_TITLE_ASK).value('Ask a question').type('postBack'),
35 | new builder.CardAction(session).title(strings.HELP_CHECK_THE_FAQ).value(strings.FAQ_URL).type('openUrl'),
36 | ]);
37 | }
38 | };
39 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/dialogs/intro.js:
--------------------------------------------------------------------------------
1 | /**
2 | * intro.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | const strings = require('../strings');
10 |
11 | module.exports = function () {
12 | bot.dialog('intro',
13 | (session, args) => {
14 | let user;
15 | if (session.message.user) {
16 | if (session.message.user.name) {
17 | user = session.message.user.name;
18 | } else {
19 | user = session.message.user.id;
20 | }
21 | }
22 | const card = getIntroCard(session, user);
23 | const message = new builder.Message(session).addAttachment(card);
24 | session.endDialog(message);
25 | }
26 | )
27 | .triggerAction({
28 | matches:/^(hi|Hi|hello|Hello|Intro)$/i
29 | });
30 |
31 | function getIntroCard(session, user) {
32 | return new builder.HeroCard()
33 | .title('Welcome ' + user + ', ' + strings.INTRO_TITLE)
34 | .text(strings.INTRO_TEXT)
35 | .buttons([
36 | new builder.CardAction(session).title(strings.INTRO_BUTTON_TITLE).value(strings.INTRO_BUTTON_VALUE).type('postBack'),
37 | ]);
38 | }
39 | };
40 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/dialogs/proposeQuestionsCard.js:
--------------------------------------------------------------------------------
1 | /**
2 | * proposeQuestionsCard.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | 'use strict';
10 |
11 | const _ = require('lodash');
12 |
13 | const faqFetcher = require('../controller/faqFetcher');
14 | const buildCardUtils = require('../utils/buildCardUtils');
15 | const strings = require('../strings');
16 |
17 | module.exports = function () {
18 | bot.dialog('proposeQuestionsCard', [
19 | (session, args, next) => {
20 | session.endDialog(getProposeQuestionsCard(session));
21 | }
22 | ]);
23 |
24 | function getProposeQuestionsCard(session) {
25 | let cards = new Array();
26 | let title = '\n**' + strings.PROPOSE_QUESTION_CARD_TITLE + '**\n\n';
27 |
28 | faqFetcher
29 | .streamFaq()
30 | .then(data => {
31 | _.forEach(data, (result) => {
32 | cards.push(buildCardUtils.buildCard(session, result));
33 | });
34 |
35 | let reply = new builder.Message(session)
36 | .text(title)
37 | .attachmentLayout(builder.AttachmentLayout.carousel)
38 | .attachments(cards);
39 |
40 | session.send(reply);
41 | })
42 | }
43 | };
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/models/faqModel.js:
--------------------------------------------------------------------------------
1 | /**
2 | * faqModel.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | 'use strict'
10 |
11 | module.exports = class faqModel {
12 | constructor(question, answer) {
13 | this.question = question;
14 | this.answer = answer;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Knowledge/QnA/src/utils/buildCardUtils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * buildCardUtils.js
3 | *
4 | * Copyright (c) Microsoft Corporation. All rights reserved.
5 | * Licensed under the MIT license.
6 | *
7 | */
8 |
9 | 'use strict'
10 |
11 | const strings = require('../strings');
12 |
13 | module.exports = function () {
14 | function buildCard(session, result) {
15 | let subTitleText = result.question ?
16 | result.question :
17 | result.questions ? result.questions[0] : null;
18 | return new builder.HeroCard(session)
19 | .subtitle(subTitleText)
20 | .text(result.answer ? result.answer : null)
21 | .tap(new builder.CardAction(session).value(strings.FAQ_URL).type('openUrl'));
22 | }
23 |
24 | return {
25 | buildCard: buildCard
26 | }
27 | }();
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/.env:
--------------------------------------------------------------------------------
1 | MICROSOFT_APP_ID=$MICROSOFT_APP_ID$
2 | MICROSOFT_APP_PASSWORD=$MICROSOFT_APP_PASSWORD$
3 | MICROSOFT_LUIS_ENDPOINT=$MICROSOFT_LUIS_ENDPOINT$
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_add_entity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_add_entity.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_add_intent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_add_intent.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_add_utterances.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_add_utterances.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_create_a_new_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_create_a_new_app.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_label_entity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_label_entity.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_train_and_test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/skype-dev-bots/797b98701ec16b00b749232e61c8068117f3cf44/Samples/Node/CognitiveServices-Language/Fridge/images/LUIS_train_and_test.png
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "myfridgebot",
3 | "version": "1.0.0",
4 | "description": "MyFridgeBot is a bot that helps users to manage their refrigerator inventory. Users can add or delete an item or see the inventory of their fridge. The bot uses LUIS(Language Understanding Intelligent Service) to recognize user's intents so that users can talk to the bot as if they are talking to a person. We believe this sample bot will not only increase developers' engagement on Skype bots but also serve as a good example of incorporating a natural langauge processing service, LUIS, to Skype bots.",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Karen Lee",
10 | "license": "ISC",
11 | "dependencies": {
12 | "botbuilder": "^3.8.4",
13 | "dotenv": "^4.0.0",
14 | "restify": "^5.0.1"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/strings.js:
--------------------------------------------------------------------------------
1 | // constant strings
2 | module.exports = {
3 | GREET: "Hi, I am your fridge, Fridge Bot :) \n\nWhat can I do for you today? Say \'help\' for help.",
4 | NOT_YET_SUPPORTED: "Sorry, we do not support that action yet.",
5 | NO_ITEM_TO_ADD: "Did you forget to mention what you want to add? Try again.",
6 | NO_ITEM_TO_REMOVE: "Did you forget to mention what you want to remove? Try again.",
7 | ADDED: "Thank you for the %s! Appreciate it :)",
8 | REMOVED_SUCC: "Here\'s the %s! It\'s no longer in my tummy.",
9 | REMOVED_ERR: "I don\'t have %s in my stomach; are you sure you fed it to me?",
10 | SHOW: "I have %s in my stomach!",
11 | HELP: "I am your Fridge Bot, and I take care of your fridge inventory. "
12 | + "You can put things in, take things out and see what is in the fridge. "
13 | + "You can say \'put apple\' and I will add an apple, "
14 | + "or \'remove apple\' and I will remove an apple. "
15 | + "You can say \'show what you have\' and I will show you the inventory, "
16 | + "or say \'clear all\' and I will clear out the fridge for you. "
17 | + "Try it out now and say \'add an apple\' :). "
18 | + "This sample bot does not support numerics.",
19 | CLEAR: "Are you sure you want to clear up the fridge? Say yes or no.",
20 | CLEAR_YES: "I cleared up myself! I am hungry now because I am empty.",
21 | CLEAR_NO: "Whew. I knew it! I will keep everything."
22 | };
--------------------------------------------------------------------------------
/Samples/Node/CognitiveServices-Language/Fridge/util.js:
--------------------------------------------------------------------------------
1 | // helper functions
2 |
3 | var isFirstTime = function (session) {
4 | return (session.userData.ingredients == null);
5 | };
6 |
7 | var initFridge = function (session) {
8 | if (isFirstTime(session)) {
9 | session.userData.ingredients = [];
10 | }
11 | };
12 |
13 | var isInFridge = function (session, item) {
14 | return isFirstTime(session) ? false : (session.userData.ingredients.indexOf(item) != -1);
15 | };
16 |
17 | var addToFridge = function (session, item) {
18 | if (isFirstTime(session)) {
19 | session.userData.ingredients = [item];
20 | } else {
21 | session.userData.ingredients.push(item);
22 | }
23 | };
24 |
25 | var removeFromFridge = function (session, item) {
26 | if (isFirstTime(session)) {
27 | return false;
28 | }
29 |
30 | var idx = session.userData.ingredients.indexOf(item);
31 | var removed = session.userData.ingredients.splice(idx, 1);
32 |
33 | // if splice returns an empty array, there is an error
34 | if (removed.length != 1) {
35 | return false;
36 | }
37 | return true;
38 | };
39 |
40 | var removeAllFromFridge = function (session) {
41 | session.userData.ingredients = [];
42 | }
43 |
44 | var itemsToString = function (items) {
45 | if (typeof items == 'undefined' || items.length == 0) {
46 | return 'nothing';
47 | }
48 |
49 | var itemsString = '';
50 | for (var idx = 0; idx < items.length; idx++) {
51 | itemsString += items[idx] + ', ';
52 | }
53 |
54 | return itemsString.slice(0, -2);
55 | }
56 |
57 | module.exports = {
58 | // checks whether the user accessed the bot for the first time
59 | isFirstTime: isFirstTime,
60 |
61 | // initializes userdata for ingredients
62 | initFridge: initFridge,
63 |
64 | // checks whether the given item is in the fridge
65 | isInFridge: isInFridge,
66 |
67 | // adds given item to the fridge
68 | addToFridge: addToFridge,
69 |
70 | // removes given item from the fridge
71 | removeFromFridge: removeFromFridge,
72 |
73 | // removes all items from the fridge
74 | removeAllFromFridge: removeAllFromFridge,
75 |
76 | // given an array of items, format them in a user-friendly way
77 | itemsToString: itemsToString
78 | };
--------------------------------------------------------------------------------
/Samples/Node/Fundamentals/DoctorCode/.env:
--------------------------------------------------------------------------------
1 | MICROSOFT_APP_ID=$MICROSOFT_APP_ID$
2 | MICROSOFT_APP_PASSWORD=$MICROSOFT_APP_PASSWORD$
--------------------------------------------------------------------------------
/Samples/Node/Fundamentals/DoctorCode/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 | node_modules/
--------------------------------------------------------------------------------
/Samples/Node/Fundamentals/DoctorCode/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "drcodebot",
3 | "version": "1.0.0",
4 | "description": "Dr. Code Bot teaches you handful of basic functionalities that you can implement for your Skype Bot.",
5 | "main": "app.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://myfridgebotdeploy@drcodebotnodejs.scm.azurewebsites.net:443/DrCodeBotNodejs.git"
12 | },
13 | "author": "Karen Jong-Hwi Lee",
14 | "license": "ISC",
15 | "dependencies": {
16 | "botbuilder": "^3.9.0",
17 | "dotenv": "^4.0.0",
18 | "restify": "^5.1.0"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/.env:
--------------------------------------------------------------------------------
1 | MICROSOFT_APP_ID=$MICROSOFT_APP_ID$
2 | MICROSOFT_APP_PASSWORD=$MICROSOFT_APP_PASSWORD$
3 | MONGO_DB_STRING=$MONGO_DB_STRING$
4 | DB_NAME=$DB_NAME$
5 | COLLECTION_NAME=$COLLECTION_NAME$
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "notes",
3 | "version": "1.0.0",
4 | "description": "Note is a bot that helps you manage personal notes. The bot uses MongoDB as storage. You can add a note, search for a note, and delete all the notes.",
5 | "scripts": {
6 | "start": "node src/App.js",
7 | "dev": "nodemon src/App.js",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "botbuilder": "^3.9.1",
14 | "dotenv": "^4.0.0",
15 | "moment": "^2.18.1",
16 | "mongodb": "^2.2.30",
17 | "restify": "^5.2.0"
18 | },
19 | "devDependencies": {
20 | "nodemon": "^1.11.0"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/App.js:
--------------------------------------------------------------------------------
1 | require('dotenv').config({path: __dirname + '/../.env'});
2 | const restify = require('restify');
3 | const noteBot = require('./bot/NoteBot.js');
4 | const database = require('./store/Database');
5 | const dbHelper = require('./store/DbHelper');
6 |
7 | // Setup Restify Server
8 | const server = restify.createServer();
9 | server.listen(process.env.port || process.env.PORT || 3978, function () {
10 | console.log('%s listening to %s', server.name, server.url);
11 | dbHelper.connect(process.env.MONGO_DB_STRING)
12 | .then(db => database.setDB(db))
13 | .catch(error => console.log(error));
14 | });
15 | // Listen for messages from users
16 | server.post('/api/messages', noteBot.connector('*').listen());
17 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/Strings.js:
--------------------------------------------------------------------------------
1 | module.exports = Object.freeze({
2 | WELCOME_IMAGE_URL: "https://notesbotapp.azurewebsites.net/Resources/welcome_card.png",
3 |
4 | NOTE: "note",
5 | SHOW: "show",
6 | DELETE: "delete",
7 | HELP: "help",
8 |
9 | NOTE_NO_INPUT: "Please add text to save the note.",
10 | NOTE_CANNOT_SAVE: "Cannot save note.",
11 |
12 | DELETE_FORCE_SUCC: "All of your **%d notes** have been **permanently deleted.**",
13 | DELETE_FORCE_FAIL: "You have no notes to delete.",
14 |
15 | HELP_NOTE: "Use the **note** command to capture a simple note. For example... \n\n_note call mom tomorrow_\n\n_note send the project proposal_",
16 | HELP_SHOW: "Use the **show** command to display all of your notes. You can also display only notes that contain specific words."
17 | + " For example...\n\n_show_\n\n_show call mom_\n\n_show project_",
18 | HELP_DELETE: "Use the **delete** command to delete all your notes. You will be prompted before final deletion.",
19 |
20 | HELP_CARD_TITLE_EXPLICIT: "Help",
21 | HELP_CARD_TITLE_IMPLICIT: "Sorry, I didn\'t get that.",
22 | HELP_CARD_TEXT: "Select a command to learn how to use it.",
23 |
24 | DELETE_CARD_TITLE: "Delete all notes?",
25 | DELETE_CARD_TEXT: "This will permanently delete all of your notes. Are you sure?",
26 | DELETE_CARD_CHOICE_YES: "Yes, delete all",
27 | DELETE_CARD_CHOICE_NO: "No, show all",
28 |
29 | SAVED_NOTE_CARD_TITLE: "Note added successfully!",
30 | SAVED_NOTE_CARD_CHOICE_SHOW: "Show notes",
31 | SAVED_NOTE_CARD_CHOICE_DELETE: "Delete notes",
32 | SAVED_NOTE_CARD_NO_TAGS: "No tags found",
33 | SHOW_NOTES_CARD_TITLE: "You have %d notes. ",
34 |
35 | INTRO_CARD_TITLE: "Hello %s, I am the Notes bot.",
36 | INTRO_CARD_TEXT: "I am here to be your assistant and take notes for you."
37 | });
38 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/models/Note.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = class Note {
4 | constructor(_id, userId, content, timestamp) {
5 | this._id = _id;
6 | this.UserId = userId;
7 | this.Content = content;
8 | this.Timestamp = timestamp;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/store/Database.js:
--------------------------------------------------------------------------------
1 | /**
2 | Singleton to hold reference to mongoDb connection
3 | **/
4 |
5 | let dbSingleton = (function() {
6 |
7 | let instance;
8 | function init() {
9 |
10 | let _db;
11 |
12 | return {
13 | getDB: function() {
14 | return _db;
15 | },
16 | setDB: function(db) {
17 | _db = db;
18 | }
19 | };
20 | }
21 |
22 | return {
23 | getInstance: function() {
24 | if (!instance) {
25 | instance = init();
26 | }
27 | return instance;
28 | }
29 | };
30 |
31 | })();
32 |
33 | module.exports = dbSingleton.getInstance();
34 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/store/DbHelper.js:
--------------------------------------------------------------------------------
1 | const MongoClient = require('mongodb').MongoClient;
2 | const strings = require('.././Strings');
3 |
4 | module.exports = function(database) {
5 |
6 | function connect(uri) {
7 | return new Promise(function(resolve, reject) {
8 | MongoClient.connect(uri)
9 | .then(database => {
10 | resolve(database.db(process.env.DB_NAME));
11 | })
12 | .catch(err => {
13 | reject(err.message);
14 | });
15 | });
16 | }
17 |
18 | function close(db) {
19 | return;
20 | if (db) {
21 | db.close()
22 | .then()
23 | .catch(error => {
24 | reject(err.message);
25 | });
26 | }
27 | }
28 |
29 | function removeAllDocuments(db, collection, filter) {
30 | return new Promise(function(resolve, reject) {
31 | db.collection(collection, filter, (error, collection) => {
32 | if (error) {
33 | reject(error.message);
34 | } else {
35 | collection.deleteMany(filter, (error, result) => {
36 | if (error) {
37 | reject(error.message);
38 | } else {
39 | resolve(result);
40 | }
41 | });
42 | }
43 | })
44 | });
45 | }
46 |
47 | function addDocument(db, collection, doc) {
48 | return new Promise(function(resolve, reject) {
49 | db.db(process.env.DB_NAME).collection(collection, (error, collection) => {
50 | if (error) {
51 | reject(error.message);
52 | } else {
53 | collection.insert(doc, {
54 | w: "majority"
55 | })
56 | .then(result => {
57 | resolve(result)
58 | })
59 | .catch(error => {
60 | reject(error.message);
61 | });
62 | }
63 | })
64 | });
65 | }
66 |
67 | function queryForDocuments(db, collection, filter) {
68 | return new Promise((resolve, reject) => {
69 | db.collection(collection, (error, collection) => {
70 | if (error) {
71 | reject(error.message);
72 | } else {
73 | collection.find(filter).toArray((error, docs) => {
74 | if (error) {
75 | reject(error.message);
76 | } else {
77 | resolve(docs);
78 | }
79 | });
80 | }
81 | });
82 | });
83 | }
84 |
85 | return {
86 | connect: connect,
87 | close: close,
88 | removeAllDocuments: removeAllDocuments,
89 | addDocument: addDocument,
90 | queryForDocuments: queryForDocuments
91 | }
92 | }();
93 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/store/index.js:
--------------------------------------------------------------------------------
1 | const strings = require('../Strings');
2 | const dbHelper = require('./DbHelper');
3 | const noteUtil = require('../util/NoteUtil');
4 | const databaseSingleton = require('./Database');
5 | const Note = require('../models/Note');
6 |
7 | module.exports = function() {
8 | function saveNote(userId, content, callback) {
9 | if (!userId) {
10 | return;
11 | }
12 |
13 | const ticks = noteUtil.dateToTicks(Date.now());
14 | const note = new Note(userId + "_" + ticks, userId, content, ticks);
15 | const db = databaseSingleton.getDB();
16 | const collection_name = process.env.COLLECTION_NAME;
17 |
18 | dbHelper.addDocument(db, collection_name, note)
19 | .then(result => {
20 | callback(null, result.ops[0]);
21 | })
22 | .catch((error) => {
23 | callback(error);
24 | });
25 | }
26 |
27 | function getNotes(userId, searchText, callback) {
28 | if (!userId) {
29 | return;
30 | }
31 |
32 | const db = databaseSingleton.getDB();
33 | const filter = {
34 | UserId: userId
35 | };
36 |
37 | if (searchText && searchText.length > 0) {
38 | filter['Content'] = { $regex: searchText };
39 | }
40 |
41 | dbHelper.queryForDocuments(db, collection_name, filter)
42 | .then(docs => {
43 | callback(docs)
44 | })
45 | .catch(error => {
46 | });
47 | }
48 |
49 | function deleteAllNotes(userId, callback) {
50 | if (!userId) {
51 | return;
52 | }
53 |
54 | const db = databaseSingleton.getDB();
55 | const filter = {
56 | UserId: userId
57 | };
58 |
59 | dbHelper.removeAllDocuments(db, collection_name, filter)
60 | .then(results => {
61 | callback(results.deletedCount);
62 | })
63 | .catch(error => {
64 | });
65 | }
66 |
67 |
68 | return {
69 | saveNote: saveNote,
70 | getNotes: getNotes,
71 | deleteAllNotes: deleteAllNotes
72 | }
73 | }();
74 |
--------------------------------------------------------------------------------
/Samples/Node/Storage-MongoDB/Notes/src/util/NoteUtil.js:
--------------------------------------------------------------------------------
1 | var moment = require('moment');
2 |
3 |
4 | function NoteUtil() {}
5 |
6 | /**
7 | Convert the timestamp Date object to a human readable format
8 | **/
9 | NoteUtil.formatDate = function(date, localTimestamp) {
10 | let dateWrapper = moment(date);
11 | let localZoneWrapper = moment.parseZone(localTimestamp);
12 | dateWrapper.utcOffset(localZoneWrapper.utcOffset());
13 | return dateWrapper.format("MMM D, YYYY HH:mm");
14 | }
15 |
16 | /**
17 | * Given number of milliseconds elapsed since Jan 1st 1970 00:00:00 UTC,
18 | * convert it into universal ticks.
19 | */
20 | NoteUtil.dateToTicks = function (date) {
21 | // epochTicks is the value of ticks from Jan 1st 1900 to Jan 1st 1970.
22 | const epochTicks = 621355968000000000;
23 | // There are 10,000 ticks per millisecond.
24 | const ticksPerMs = 10000;
25 |
26 | return ((date * ticksPerMs) + epochTicks);
27 | }
28 |
29 | /**
30 | * Given universal ticks,
31 | * convert it to number of milliseconds elapsed since Jan 1 1970 00:00:00 UTC.
32 | */
33 | NoteUtil.ticksToDate = function (ticks) {
34 | // epochTicks is the value of ticks from Jan 1st 1900 to Jan 1st 1970.
35 | const epochTicks = 621355968000000000;
36 | // There are 10,000 ticks per millisecond.
37 | const ticksPerMs = 10000;
38 |
39 | return Math.floor((ticks - epochTicks) / ticksPerMs);
40 | }
41 |
42 | module.exports = NoteUtil;
--------------------------------------------------------------------------------
/certification/CHECKLIST.md:
--------------------------------------------------------------------------------
1 | # Certification Checklist
2 | This document captures the certification checklist used by Microsoft and Skype to validate Skype bots submitted for certification.
3 |
4 | | Number | Requirement | Notes |
5 | | ----------- | ------ | ------ |
6 | | **100** | **Bot Profile Information** |
7 | | 101 | Bot Name and Publisher Name | Your bot needs to have a clear and descriptive Bot Name and Publisher Name. Do not suffix ‘Bot’ to your bot name unless it is unavoidable and use spacing. E.g.: FooBot should ideally be Foo, or if unavoidable, Foo Bot.|
8 | | 102 | Privacy Policy and Terms of Use documents published online and referenced by the bot | Your bot must have links to a valid Privacy Policy and Terms of Use. |
9 | | 103 | Bot avatar image with non-black and non-white background color | Your bot must have an avatar image. You must not use the standard bot framework avatar. You must not infringe any copyrighted images. |
10 | | 104 | Bot description explains the purpose of the bot | Your bot must have a clear and comprehensive description to help users understand its purpose. |
11 | | **200** | **Bot Functionality** |
12 | | 201 | Automatically display a Welcome message | When a user adds the bot as a contact, the bot must automatically display a welcome message. This increases user engagement and guides the user to success. |
13 | | 202 | Display a Help screen when receiving unknown commands | Whenever a user sends any message / command to the bot that the bot doesn’t understand, the bot must respond with a help message, providing usage guidance. |
14 | | 203 | Bot functionality works correctly | Your bot must function correctly. Bots with obvious broken functionality will be rejected and / or removed from the directory. |
15 | | 204 | Bot must be fast | The bot must respond to user commands without extensive delays.|
16 | | 205 | Bot must be mobile-friendly | The bot must be designed in a way that enables users to be able to interact with it on a mobile device. For example, the bot should not send excessively long individual messages (instead it can send a sequence of several messages). To ensure the bot is mobile friendly, please test on a mobile device (Android or iOS) with the latest versions of Skype. |
17 | | **300** | **Compliance** |
18 | | 301 | Your Bot Submission must PASS Azure Online Service Terms| See [Azure Online Service Terms]( https://azure.microsoft.com/en-gb/support/legal/)|
19 | | 302 | Your Bot Submission must PASS Microsoft Channel Publication Terms | See [Microsoft Channel Publication Terms](https://www.botframework.com/content/bot-service-channels-terms.htm) |
20 |
--------------------------------------------------------------------------------