Skip to content

Commit

Permalink
Add AspNet Core pizza bot sample
Browse files Browse the repository at this point in the history
  • Loading branch information
iedeny authored and andreesteve committed Feb 24, 2017
1 parent c6b4f69 commit 094213e
Show file tree
Hide file tree
Showing 22 changed files with 1,615 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>50f1a769-433e-4668-bb36-514a5a52da94</ProjectGuid>
</PropertyGroup>
<PropertyGroup>
<NuProjPath Condition=" '$(NuProjPath)' == '' ">$(MSBuildExtensionsPath)\NuProj\</NuProjPath>
</PropertyGroup>
<Import Project="$(NuProjPath)\NuProj.props" Condition="Exists('$(NuProjPath)\NuProj.props')" />
<PropertyGroup Label="Configuration">
<Id>Bot.Connector.AspNetCore.Package</Id>
<Version>1.0.0</Version>
<Title>Bot.Connector.AspNetCore.Package</Title>
<Authors>cement</Authors>
<Owners>cement</Owners>
<Summary>Bot.Connector.AspNetCore.Package</Summary>
<Description>Bot.Connector.AspNetCore.Package</Description>
<ReleaseNotes>
</ReleaseNotes>
<ProjectUrl>
</ProjectUrl>
<LicenseUrl>
</LicenseUrl>
<Copyright>Copyright © cement</Copyright>
<Tags>Bot.Connector.AspNetCore.Package</Tags>
</PropertyGroup>
<ItemGroup>
<Content Include="Readme.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Library\Microsoft.Bot.Connector.Abstractions\Microsoft.Bot.Connector.Abstractions.csproj" />
<ProjectReference Include="..\Library\Microsoft.Bot.Connector.AspNetCore\Microsoft.Bot.Connector.AspNetCore.csproj" />
</ItemGroup>
<Import Project="$(NuProjPath)\NuProj.targets" />
</Project>
1 change: 1 addition & 0 deletions CSharp/Bot.Connector.AspNetCore.Package/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is your NuGet package.
45 changes: 45 additions & 0 deletions CSharp/Builder.Autofac.Package/Builder.Autofac.Package.nuproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>c1fe5500-356c-47f2-92a7-ccec2a87b773</ProjectGuid>
</PropertyGroup>
<PropertyGroup>
<NuProjPath Condition=" '$(NuProjPath)' == '' ">$(MSBuildExtensionsPath)\NuProj\</NuProjPath>
</PropertyGroup>
<Import Project="$(NuProjPath)\NuProj.props" Condition="Exists('$(NuProjPath)\NuProj.props')" />
<PropertyGroup Label="Configuration">
<Id>Builder.Autofac.Package</Id>
<Version>1.0.0</Version>
<Title>Builder.Autofac.Package</Title>
<Authors>cement</Authors>
<Owners>cement</Owners>
<Summary>Builder.Autofac.Package</Summary>
<Description>Builder.Autofac.Package</Description>
<ReleaseNotes>
</ReleaseNotes>
<ProjectUrl>
</ProjectUrl>
<LicenseUrl>
</LicenseUrl>
<Copyright>Copyright © cement</Copyright>
<Tags>Builder.Autofac.Package</Tags>
</PropertyGroup>
<ItemGroup>
<Content Include="Readme.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Library\Microsoft.Bot.Builder.Autofac\Microsoft.Bot.Builder.Autofac.csproj" />
<ProjectReference Include="..\Library\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj" />
</ItemGroup>
<Import Project="$(NuProjPath)\NuProj.targets" />
</Project>
1 change: 1 addition & 0 deletions CSharp/Builder.Autofac.Package/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is your NuGet package.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@
<Project>{645862ff-bf5e-4d5b-b1b5-1462ededbb12}</Project>
<Name>Microsoft.Bot.Connector.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.Bot.Connector.NetFramework\Microsoft.Bot.Connector.csproj">
<Project>{df397efc-91db-4911-9971-c509926fc288}</Project>
<Name>Microsoft.Bot.Connector</Name>
<ProjectReference Include="..\Microsoft.Bot.Connector.AspNetCore\Microsoft.Bot.Connector.AspNetCore.csproj">
<Project>{6efa2312-9e6f-462d-b4be-2df44c84db00}</Project>
<Name>Microsoft.Bot.Connector.AspNetCore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public sealed class ResumptionCookie : IEquatable<ResumptionCookie>
/// True if the <see cref="IAddress.ServiceUrl"/> is trusted; False otherwise.
/// </summary>
/// <remarks> Conversation.ResumeAsync adds
/// the host of the <see cref="IAddress.ServiceUrl"/> to <see cref="MicrosoftAppCredentials.TrustedHostNames"/> if this flag is True.
/// the host of the <see cref="IAddress.ServiceUrl"/> to <see cref="MicrosoftAppCredentialsBase.TrustedHostNames"/> if this flag is True.
/// </remarks>
public bool IsTrustedServiceUrl { private set; get; }

Expand Down
27 changes: 27 additions & 0 deletions CSharp/Microsoft.Bot.Builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Bot.Connector.Asp
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Bot.Sample.AspNetCore.Echo", "Samples\Microsoft.Bot.Sample.AspNetCore.Echo\Microsoft.Bot.Sample.AspNetCore.Echo.xproj", "{CCAFB5F5-66DE-4119-B02C-1DDCF48BBB9A}"
EndProject
Project("{FF286327-C783-4F7A-AB73-9BCBAD0D4460}") = "Builder.Autofac.Package", "Builder.Autofac.Package\Builder.Autofac.Package.nuproj", "{C1FE5500-356C-47F2-92A7-CCEC2A87B773}"
EndProject
Project("{FF286327-C783-4F7A-AB73-9BCBAD0D4460}") = "Bot.Connector.AspNetCore.Package", "Bot.Connector.AspNetCore.Package\Bot.Connector.AspNetCore.Package.nuproj", "{50F1A769-433E-4668-BB36-514A5A52DA94}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Bot.Sample.AspNetCore.Pizza", "Samples\Microsoft.Bot.Sample.AspNetCore.Pizza\Microsoft.Bot.Sample.AspNetCore.Pizza.xproj", "{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -281,6 +287,24 @@ Global
{CCAFB5F5-66DE-4119-B02C-1DDCF48BBB9A}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{CCAFB5F5-66DE-4119-B02C-1DDCF48BBB9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCAFB5F5-66DE-4119-B02C-1DDCF48BBB9A}.Release|Any CPU.Build.0 = Release|Any CPU
{C1FE5500-356C-47F2-92A7-CCEC2A87B773}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1FE5500-356C-47F2-92A7-CCEC2A87B773}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1FE5500-356C-47F2-92A7-CCEC2A87B773}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{C1FE5500-356C-47F2-92A7-CCEC2A87B773}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{C1FE5500-356C-47F2-92A7-CCEC2A87B773}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1FE5500-356C-47F2-92A7-CCEC2A87B773}.Release|Any CPU.Build.0 = Release|Any CPU
{50F1A769-433E-4668-BB36-514A5A52DA94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50F1A769-433E-4668-BB36-514A5A52DA94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50F1A769-433E-4668-BB36-514A5A52DA94}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{50F1A769-433E-4668-BB36-514A5A52DA94}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{50F1A769-433E-4668-BB36-514A5A52DA94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50F1A769-433E-4668-BB36-514A5A52DA94}.Release|Any CPU.Build.0 = Release|Any CPU
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -312,5 +336,8 @@ Global
{645862FF-BF5E-4D5B-B1B5-1462EDEDBB12} = {28BCEB2C-F4BE-416D-A4FD-A311E99A9EB5}
{6EFA2312-9E6F-462D-B4BE-2DF44C84DB00} = {28BCEB2C-F4BE-416D-A4FD-A311E99A9EB5}
{CCAFB5F5-66DE-4119-B02C-1DDCF48BBB9A} = {FAEFFF66-7944-48F4-972A-9A1C13A5C206}
{C1FE5500-356C-47F2-92A7-CCEC2A87B773} = {28BCEB2C-F4BE-416D-A4FD-A311E99A9EB5}
{50F1A769-433E-4668-BB36-514A5A52DA94} = {28BCEB2C-F4BE-416D-A4FD-A311E99A9EB5}
{6EF6048D-91CA-43FA-96F3-2C7939C40ED9} = {FAEFFF66-7944-48F4-972A-9A1C13A5C206}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Threading.Tasks;

using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.FormFlow;
using Microsoft.Bot.Builder.Dialogs;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using System;

namespace Microsoft.Bot.Sample.AspNetCore.Pizza
{
[Route("api/[controller]")]
public class MessagesController : Controller
{
private static IForm<PizzaOrder> BuildForm()
{
var builder = new FormBuilder<PizzaOrder>();

ActiveDelegate<PizzaOrder> isBYO = (pizza) => pizza.Kind == PizzaOptions.BYOPizza;
ActiveDelegate<PizzaOrder> isSignature = (pizza) => pizza.Kind == PizzaOptions.SignaturePizza;
ActiveDelegate<PizzaOrder> isGourmet = (pizza) => pizza.Kind == PizzaOptions.GourmetDelitePizza;
ActiveDelegate<PizzaOrder> isStuffed = (pizza) => pizza.Kind == PizzaOptions.StuffedPizza;

return builder
// .Field(nameof(PizzaOrder.Choice))
.Field(nameof(PizzaOrder.Size))
.Field(nameof(PizzaOrder.Kind))
.Field("BYO.Crust", isBYO)
.Field("BYO.Sauce", isBYO)
.Field("BYO.Toppings", isBYO)
.Field(nameof(PizzaOrder.GourmetDelite), isGourmet)
.Field(nameof(PizzaOrder.Signature), isSignature)
.Field(nameof(PizzaOrder.Stuffed), isStuffed)
.AddRemainingFields()
.Confirm("Would you like a {Size}, {BYO.Crust} crust, {BYO.Sauce}, {BYO.Toppings} pizza?", isBYO)
.Confirm("Would you like a {Size}, {&Signature} {Signature} pizza?", isSignature, dependencies: new string[] { "Size", "Kind", "Signature" })
.Confirm("Would you like a {Size}, {&GourmetDelite} {GourmetDelite} pizza?", isGourmet)
.Confirm("Would you like a {Size}, {&Stuffed} {Stuffed} pizza?", isStuffed)
.Build()
;
}

internal static IDialog<PizzaOrder> MakeRoot()
{
return Chain.From(() => new PizzaOrderDialog(BuildForm));
}

private readonly IConfigurationRoot configuration;

public MessagesController(IConfigurationRoot configuration)
{
this.configuration = configuration;
}

[Authorize(Roles = "Bot")]
// POST api/values
[HttpPost]
public virtual async Task<OkResult> Post([FromBody]Activity activity)
{
var appCredentials = new MicrosoftAppCredentials(this.configuration);
var client = new ConnectorClient(new Uri(activity.ServiceUrl), appCredentials);
var reply = activity.CreateReply();

if (activity != null)
{
// one of these will have an interface and process it
switch (activity.GetActivityType())
{
case ActivityTypes.Message:
await Conversation.SendAsync(activity, MakeRoot);
break;

case ActivityTypes.ConversationUpdate:
case ActivityTypes.ContactRelationUpdate:
case ActivityTypes.Typing:
case ActivityTypes.DeleteUserData:
default:
Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}");
break;
}
}

await client.Conversations.ReplyToActivityAsync(reply);
return Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>6ef6048d-91ca-43fa-96f3-2c7939c40ed9</ProjectGuid>
<RootNamespace>WebApplication5</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Loading

0 comments on commit 094213e

Please sign in to comment.