-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "maduka-Robot", "maduka-Robot\maduka-Robot.csproj", "{8707EE9C-14BD-429E-9FD1-0D977A99B077}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8707EE9C-14BD-429E-9FD1-0D977A99B077}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8707EE9C-14BD-429E-9FD1-0D977A99B077}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8707EE9C-14BD-429E-9FD1-0D977A99B077}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8707EE9C-14BD-429E-9FD1-0D977A99B077}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web.Http; | ||
|
||
namespace maduka_Robot | ||
{ | ||
public static class WebApiConfig | ||
{ | ||
public static void Register(HttpConfiguration config) | ||
{ | ||
// Web API 設定和服務 | ||
|
||
// Web API 路由 | ||
config.MapHttpAttributeRoutes(); | ||
|
||
config.Routes.MapHttpRoute( | ||
name: "DefaultApi", | ||
routeTemplate: "api/{controller}/{id}", | ||
defaults: new { id = RouteParameter.Optional } | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using System.Web.Http.Description; | ||
using Microsoft.Bot.Connector; | ||
using Newtonsoft.Json; | ||
using maduka_Robot.Models; | ||
using System.IO; | ||
using System.Web; | ||
using System.Configuration; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
|
||
namespace maduka_Robot.Controllers | ||
{ | ||
[Serializable] | ||
public class EchoDialog : IDialog<object> | ||
{ | ||
public async Task StartAsync(IDialogContext context) | ||
{ | ||
context.Wait(MessageReceivedAsync); | ||
} | ||
|
||
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument) | ||
{ | ||
var message = await argument; | ||
await context.PostAsync("You said: " + message.Text); | ||
context.Wait(MessageReceivedAsync); | ||
} | ||
} | ||
|
||
[BotAuthentication] | ||
public class MessagesController : ApiController | ||
{ | ||
/// <summary> | ||
/// 取得從Bot Framework送進來的訊息 | ||
/// </summary> | ||
public async Task<HttpResponseMessage> Post([FromBody]Activity activity) | ||
{ | ||
if (activity != null && activity.GetActivityType() == ActivityTypes.Message) | ||
{ | ||
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); | ||
string strLuisKey = ConfigurationManager.AppSettings["LUISAPIKey"].ToString(); | ||
string strLuisAppId = ConfigurationManager.AppSettings["LUISAppId"].ToString(); | ||
string strMessage = HttpUtility.UrlEncode(activity.Text); | ||
string strLuisUrl = $"https://api.projectoxford.ai/luis/v1/application?id={strLuisAppId}&subscription-key={strLuisKey}&q={strMessage}"; | ||
|
||
// 找到文字後,往LUIS送 | ||
WebRequest request = WebRequest.Create(strLuisUrl); | ||
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | ||
Stream dataStream = response.GetResponseStream(); | ||
StreamReader reader = new StreamReader(dataStream); | ||
string json = reader.ReadToEnd(); | ||
CognitiveModels.LUISResult objLUISRes = JsonConvert.DeserializeObject<CognitiveModels.LUISResult>(json); | ||
|
||
string strReply = "無法識別的內容"; | ||
|
||
if (objLUISRes.intents.Count > 0) | ||
{ | ||
string strIntent = objLUISRes.intents[0].intent; | ||
if (strIntent == "詢問") | ||
{ | ||
string strDate = objLUISRes.entities.Find((x => x.type == "日期")).entity; | ||
string strAir = objLUISRes.entities.Find((x => x.type == "航空公司")).entity; | ||
string strService = objLUISRes.entities.Find((x => x.type == "服務")).entity; | ||
|
||
strReply = $"您要詢問的航空公司:{strAir},日期:{strDate},相關服務是:{strService}。我馬上幫您找出資訊"; | ||
strReply += ".....這裡加上後續資料的呈現....."; | ||
} | ||
|
||
if (strIntent == "只是打招呼") | ||
{ | ||
strReply = "您好,有什麼能幫得上忙的呢?"; | ||
} | ||
|
||
if (strIntent == "None") | ||
{ | ||
strReply = "您在說什麼,我聽不懂~~~(轉圈圈"; | ||
} | ||
} | ||
|
||
Activity reply = activity.CreateReply(strReply); | ||
await connector.Conversations.ReplyToActivityAsync(reply); | ||
} | ||
else | ||
{ | ||
HandleSystemMessage(activity); | ||
} | ||
|
||
var responses = Request.CreateResponse(HttpStatusCode.OK); | ||
return responses; | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Web.Http; | ||
using Swashbuckle.Swagger.Annotations; | ||
|
||
namespace maduka_Robot.Controllers | ||
{ | ||
public class ValuesController : ApiController | ||
{ | ||
// GET api/values | ||
[SwaggerOperation("GetAll")] | ||
public IEnumerable<string> Get() | ||
{ | ||
return new string[] { "value1", "value2" }; | ||
} | ||
|
||
// GET api/values/5 | ||
[SwaggerOperation("GetById")] | ||
[SwaggerResponse(HttpStatusCode.OK)] | ||
[SwaggerResponse(HttpStatusCode.NotFound)] | ||
public string Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// POST api/values | ||
[SwaggerOperation("Create")] | ||
[SwaggerResponse(HttpStatusCode.Created)] | ||
public void Post([FromBody]string value) | ||
{ | ||
} | ||
|
||
// PUT api/values/5 | ||
[SwaggerOperation("Update")] | ||
[SwaggerResponse(HttpStatusCode.OK)] | ||
[SwaggerResponse(HttpStatusCode.NotFound)] | ||
public void Put(int id, [FromBody]string value) | ||
{ | ||
} | ||
|
||
// DELETE api/values/5 | ||
[SwaggerOperation("Delete")] | ||
[SwaggerResponse(HttpStatusCode.OK)] | ||
[SwaggerResponse(HttpStatusCode.NotFound)] | ||
public void Delete(int id) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%@ Application Codebehind="Global.asax.cs" Inherits="maduka_Robot.WebApiApplication" Language="C#" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Http; | ||
using System.Web.Routing; | ||
|
||
namespace maduka_Robot | ||
{ | ||
public class WebApiApplication : System.Web.HttpApplication | ||
{ | ||
protected void Application_Start() | ||
{ | ||
GlobalConfiguration.Configure(WebApiConfig.Register); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace maduka_Robot.Models | ||
{ | ||
public class CognitiveModels | ||
{ | ||
public class LUISResult | ||
{ | ||
public string query { get; set; } | ||
public List<Intent> intents { get; set; } | ||
public List<Entity> entities { get; set; } | ||
|
||
public class Intent | ||
{ | ||
public string intent { get; set; } | ||
public float score { get; set; } | ||
public List<Action> actions { get; set; } | ||
} | ||
|
||
public class Action | ||
{ | ||
public bool triggered { get; set; } | ||
public string name { get; set; } | ||
public List<Parameter> parameters { get; set; } | ||
} | ||
|
||
public class Parameter | ||
{ | ||
public string name { get; set; } | ||
public bool required { get; set; } | ||
public List<Value> value { get; set; } | ||
} | ||
|
||
public class Value | ||
{ | ||
public string entity { get; set; } | ||
public string type { get; set; } | ||
public float score { get; set; } | ||
} | ||
|
||
public class Entity | ||
{ | ||
public string entity { get; set; } | ||
public string type { get; set; } | ||
public int startIndex { get; set; } | ||
public int endIndex { get; set; } | ||
public float score { get; set; } | ||
} | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.