updated readme.md and bot controller code

This commit is contained in:
Joseph Velliah 2016-12-22 12:20:22 -06:00
parent 7470b353bd
commit 4b5e080a3b
7 changed files with 60 additions and 20 deletions

View File

@ -68,6 +68,8 @@ Version|Date|Comments
- configure bot name and web chat secret key
![preview](./assets/preview.png)
- type hello and proceed with site creation process
- final output
![botregister-step4](./assets/botregister-step4.png)
## Features

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -162,7 +162,7 @@
</site>
<site name="AskSPRider" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\veljo05\Desktop\js-bot-framework\bot\AskSPRider" />
<virtualDirectory path="/" physicalPath="C:\Source\Git\Microsoft\sp-dev-fx-webparts\samples\js-bot-framework\bot\AskSPRider" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:3979:localhost" />

View File

@ -2,10 +2,8 @@
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.FormFlow;
using Microsoft.Bot.Connector;
using System;
using System.Net;
using System.Net.Http;
using System.ServiceModel.Channels;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
@ -14,17 +12,55 @@ namespace AskSPRider
{
[BotAuthentication]
public class MessagesController : ApiController
{
{
internal static IDialog<SiteRequestOrder> BuildSiteRequestDialog()
{
return Chain.From(() => FormDialog.FromForm(SiteRequestOrder.BuildForm));
return Chain.From(() => FormDialog.FromForm(SiteRequestOrder.BuildForm));
}
[ResponseType(typeof(void))]
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
await Conversation.SendAsync(activity, BuildSiteRequestDialog);
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
}
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, BuildSiteRequestDialog);
return new HttpResponseMessage(HttpStatusCode.Accepted);
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
}

View File

@ -8,14 +8,15 @@ using System.ComponentModel;
namespace AskSPRider.Forms
{
public enum SiteTemplateOptions {
public enum SiteTemplateOptions
{
[Description("STS#0")]
Team,
[Description("PROJECTSITE#0")]
Project,
[Description("BLOG#0")]
Blog
};
};
[Serializable]
public class SiteRequestOrder
@ -33,12 +34,13 @@ namespace AskSPRider.Forms
[Optional]
[Prompt("What is the sub-site URL Name?")]
public string URLName;
[Describe("site template")]
public SiteTemplateOptions? Template;
public static IForm<SiteRequestOrder> BuildForm()
{
OnCompletionAsyncDelegate<SiteRequestOrder> wrapUpRequest = async (context, request) =>
{
@ -48,8 +50,8 @@ namespace AskSPRider.Forms
siteRquest.ParentSiteUrl = request.ParentSiteUrl;
siteRquest.Title = request.Title;
siteRquest.Description = request.Description;
siteRquest.URLName = request.URLName;
siteRquest.Template = Common.GetDescription(request.Template); ;
siteRquest.URLName = request.URLName;
siteRquest.Template = Common.GetDescription(request.Template); ;
string wrapUpMessage = Helper.ProcessRequest.createSubSite(siteRquest);
await context.PostAsync(wrapUpMessage);
@ -66,25 +68,25 @@ namespace AskSPRider.Forms
reply = "There is a problem in creating the sub-site at this moment. Please try again later.";
}
await context.PostAsync(reply);
}
}
};
return new FormBuilder<SiteRequestOrder>()
.Message("Welcome to SPOL Site Request bot!")
.Message("Welcome to SPOL Site Request bot!")
.Field(nameof(ParentSiteUrl), validate: ParentSiteValidator)
.Field(nameof(Title))
.Field(nameof(Description))
.Field(nameof(URLName), validate: SubSiteValidator)
.Field(nameof(Template))
.Confirm("Do you want to submit your sub-site request - {Title}?")
.Field(nameof(Template))
.AddRemainingFields()
.Confirm("Do you want to submit your sub-site request - {Title}?")
.Message("Thanks for submitting a new sub-site!")
.OnCompletion(wrapUpRequest)
.Build();
}
private static ValidateAsyncDelegate<SiteRequestOrder> ParentSiteValidator = async (state, response) =>
{
{
var result = new ValidateResult { IsValid = true, Value = response };
var parentSiteURL = (response as string).Trim();
@ -111,6 +113,6 @@ namespace AskSPRider.Forms
return await Task.FromResult(result);
};
}
}