Skip to content

Commit

Permalink
Merge branch 'private-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
NizamLZ committed Jul 5, 2017
2 parents 47bf534 + 004b4b8 commit 47b9b30
Show file tree
Hide file tree
Showing 60 changed files with 1,816 additions and 390 deletions.
8 changes: 4 additions & 4 deletions ANAConversationPlatform/ANAConversationPlatform.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

<ItemGroup>
<Compile Remove="Logs\**" />
<Compile Remove="wwwroot\ChatMedia\**" />
<Content Remove="Logs\**" />
<Content Remove="wwwroot\ChatMedia\**" />
<EmbeddedResource Remove="Logs\**" />
<EmbeddedResource Remove="wwwroot\ChatMedia\**" />
<None Remove="Logs\**" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\ChatMedia\" />
<None Remove="wwwroot\ChatMedia\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.3.6.1" />
Expand Down
160 changes: 88 additions & 72 deletions ANAConversationPlatform/Controllers/ConversationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ANAConversationPlatform.Models;
using ANAConversationPlatform.Models.Sections;
using Microsoft.Extensions.Logging;
using static ANAConversationPlatform.Helpers.Constants;

namespace ANAConversationPlatform.Controllers
{
Expand All @@ -23,16 +24,23 @@ public ConversationController(ILogger<ConversationController> log)
[HttpGet]
public ActionResult Chat()
{
var chatNodes = MongoHelper.RetrieveRecordsFromChatNode();
Debug.WriteLine(chatNodes.ToJson());
if (chatNodes == null || chatNodes.Count == 0)
return Ok(new object[] { });
try
{
var chatNodes = MongoHelper.RetrieveRecordsFromChatNode();
if (chatNodes == null || chatNodes.Count == 0)
return Ok(new object[] { });

return Json(chatNodes, new JsonSerializerSettings()
return Json(chatNodes, new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new CustomStringEnumConverter() }
});
}
catch (System.Exception ex)
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new CustomStringEnumConverter() }
});
_log.LogError(new EventId((int)LoggerEventId.CHAT_ACTION_ERROR), ex, ex.Message);
return StatusCode(500, new { Message = ex.Message });
}
}

[HttpGet]
Expand All @@ -45,75 +53,83 @@ public ActionResult RefreshContent()
[HttpGet]
public ActionResult HybridChat()
{
var chatNodes = MongoHelper.RetrieveRecordsFromChatNode();
try
{
var chatNodes = MongoHelper.RetrieveRecordsFromChatNode();

chatNodes.AddRange(new[] {
new ChatNode("INIT_CHAT_NODE")
{
ApiMethod = "GET",
ApiUrl = Url.Action("CreateUserSessionForHChat", "AgentChat", new { }, Request.Scheme),
Emotion = EmotionEnum.Cool,
Name = "Send Chat Text Node",
NodeType = NodeTypeEnum.ApiCall,
NextNodeId = "SEND_CHAT_HISTORY_TO_SERVER",
RequiredVariables = new[] { "DEVICE_ID", "PERSON_NAME" },
},
new ChatNode("SEND_CHAT_HISTORY_TO_SERVER")
{
ApiMethod = "POST",
ApiUrl = Url.Action("SubmitHistory", "AgentChat", new { }, Request.Scheme),
Emotion = EmotionEnum.Cool,
Name = "Send Chat History To Server",
NodeType = NodeTypeEnum.ApiCall,
NextNodeId = "GET_CHAT_TEXT_NODE",
RequiredVariables = new[] { "CHAT_USER_ID", "CHAT_USER_TOKEN", "DEVICE_ID", "AGENT", "HISTORY" },
},
new ChatNode("GET_CHAT_TEXT_NODE")
chatNodes.AddRange(new[]
{
Buttons = new List<Button>(new[]{
new Button("NEW BTN ID", "ChatText", "Send", EmotionEnum.Cool, ButtonTypeEnum.GetText, "SEND_CHAT_TEXT_NODE", false, false)
}),
Emotion = EmotionEnum.Cool,
Name = "Chat Input",
NodeType = NodeTypeEnum.Combination,
Sections = new List<Section>(),
TimeoutInMs = 0,
VariableName = "TEXT"
},
new ChatNode("SEND_CHAT_TEXT_NODE")
{
ApiMethod = "GET",
ApiUrl = Url.Action("UserInput", "AgentChat", new { }, Request.Scheme),
Buttons = null,
Emotion = EmotionEnum.Cool,
Name = "Send Chat Text Node",
NodeType = NodeTypeEnum.ApiCall,
NextNodeId = "CONTINUE_CHAT_NODE",
RequiredVariables = new[] { "CHAT_USER_ID", "CHAT_USER_TOKEN", "AGENT", "TEXT" },
},
new ChatNode("CONTINUE_CHAT_NODE")
{
Buttons = new List<Button>(new[]{
new Button("NEW BTN ID", "ChatText", "Send", EmotionEnum.Cool, ButtonTypeEnum.GetText, "SEND_CHAT_TEXT_NODE", false, false)
}),
Emotion = EmotionEnum.Cool,
Name = "Chat Input Continue",
NodeType = NodeTypeEnum.Combination,
Sections = new List<Section>(),
TimeoutInMs = 0,
VariableName = "TEXT"
}
});
new ChatNode("INIT_CHAT_NODE")
{
ApiMethod = "GET",
ApiUrl = Url.Action("CreateUserSessionForHChat", "AgentChat", new { }, Request.Scheme),
Emotion = EmotionEnum.Cool,
Name = "Send Chat Text Node",
NodeType = NodeTypeEnum.ApiCall,
NextNodeId = "SEND_CHAT_HISTORY_TO_SERVER",
RequiredVariables = new[] { "DEVICE_ID", "PERSON_NAME" },
},
new ChatNode("SEND_CHAT_HISTORY_TO_SERVER")
{
ApiMethod = "POST",
ApiUrl = Url.Action("SubmitHistory", "AgentChat", new { }, Request.Scheme),
Emotion = EmotionEnum.Cool,
Name = "Send Chat History To Server",
NodeType = NodeTypeEnum.ApiCall,
NextNodeId = "GET_CHAT_TEXT_NODE",
RequiredVariables = new[] { "CHAT_USER_ID", "CHAT_USER_TOKEN", "DEVICE_ID", "AGENT", "HISTORY" },
},
new ChatNode("GET_CHAT_TEXT_NODE")
{
Buttons = new List<Button>(new[]{
new Button("NEW BTN ID", "ChatText", "Send", EmotionEnum.Cool, ButtonTypeEnum.GetText, "SEND_CHAT_TEXT_NODE", false, false)
}),
Emotion = EmotionEnum.Cool,
Name = "Chat Input",
NodeType = NodeTypeEnum.Combination,
Sections = new List<Section>(),
TimeoutInMs = 0,
VariableName = "TEXT"
},
new ChatNode("SEND_CHAT_TEXT_NODE")
{
ApiMethod = "GET",
ApiUrl = Url.Action("UserInput", "AgentChat", new { }, Request.Scheme),
Buttons = null,
Emotion = EmotionEnum.Cool,
Name = "Send Chat Text Node",
NodeType = NodeTypeEnum.ApiCall,
NextNodeId = "CONTINUE_CHAT_NODE",
RequiredVariables = new[] { "CHAT_USER_ID", "CHAT_USER_TOKEN", "AGENT", "TEXT" },
},
new ChatNode("CONTINUE_CHAT_NODE")
{
Buttons = new List<Button>(new[]{
new Button("NEW BTN ID", "ChatText", "Send", EmotionEnum.Cool, ButtonTypeEnum.GetText, "SEND_CHAT_TEXT_NODE", false, false)
}),
Emotion = EmotionEnum.Cool,
Name = "Chat Input Continue",
NodeType = NodeTypeEnum.Combination,
Sections = new List<Section>(),
TimeoutInMs = 0,
VariableName = "TEXT"
}
});

if (chatNodes == null || chatNodes.Count == 0)
return Ok(new object[] { });
if (chatNodes == null || chatNodes.Count == 0)
return Ok(new object[] { });

return Json(chatNodes, new JsonSerializerSettings()
return Json(chatNodes, new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new CustomStringEnumConverter() }
});
}
catch (System.Exception ex)
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new CustomStringEnumConverter() }
});
_log.LogError(new EventId((int)LoggerEventId.HYBRID_CHAT_ACTION_ERROR), ex, ex.Message);
return StatusCode(500, new { Message = ex.Message });
}
}

}
}
54 changes: 54 additions & 0 deletions ANAConversationPlatform/Controllers/StudioDistController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using ANAConversationPlatform.Helpers;
using System.IO;

namespace ANAConversationPlatform.Controllers
{
[Produces("application/json")]
public class StudioDistController : Controller
{
[HttpGet]
public ActionResult Latest()
{
if (!string.IsNullOrWhiteSpace(Utils.Settings?.StudioDistFolder))
{
Version v;
var fileVersions = Directory.EnumerateFiles(Utils.Settings?.StudioDistFolder)
.Where(x => Version.TryParse(Path.GetFileNameWithoutExtension(x), out v))
.Select(x => Version.Parse(Path.GetFileNameWithoutExtension(x))).ToList();

if (fileVersions.Count > 0)
{
var latest = fileVersions.OrderByDescending(x => x).First();
return Ok(new
{
DownloadLink = Url.Link(nameof(StudioDownload), new { version = latest.ToString() }),
Version = latest
});
}
}
return BadRequest("Studio Distribution Status Unknown");
}

[HttpGet]
[Route(nameof(StudioDownload), Name = nameof(StudioDownload))]
public ActionResult StudioDownload(string version)
{
try
{
var v = Version.Parse(version);
var fileName = Path.Combine(Utils.Settings.StudioDistFolder, v.ToString() + ".zip");
if (System.IO.File.Exists(fileName))
return File(System.IO.File.OpenRead(fileName), "application/zip", Path.GetFileName(fileName));
else
return NotFound();
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}
6 changes: 4 additions & 2 deletions ANAConversationPlatform/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
public static class Constants
{
public const string CHAT_MEDIA_FOLDER_NAME = "ChatMedia";

public enum LoggerEventId
{
ROCKET_CHAT_SDK_INIT_ERROR = 0,
AGENT_CHAT_SUBMIT_HISTORY_ERR = 1,
AGENT_CHAT_CREATE_USER_ERR = 2,
AGENT_CHAT_CALLBACK_RECEIVED_ERR = 3,
AGENT_CHAT_FIND_AGENT_ERR = 4,
AGENT_CHAT_CREATE_USER = 5
AGENT_CHAT_CREATE_USER = 5,
MONGO_HELPER_ERROR = 6,
CHAT_ACTION_ERROR = 7,
HYBRID_CHAT_ACTION_ERROR = 8,
}
}
}
20 changes: 16 additions & 4 deletions ANAConversationPlatform/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,36 @@ namespace ANAConversationPlatform.Helpers
{
public static class Extensions
{
public static Content GetFor(this List<Content> contentCollection, ChatNode node)
public static Content GetFor(this IEnumerable<Content> contentCollection, ChatNode node)
{
if (string.IsNullOrWhiteSpace(node.Id)) return null;
return contentCollection.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.NodeId) && x.NodeId == node.Id);
}

public static Content GetFor(this List<Content> contentCollection, Section section)
public static Content GetFor(this IEnumerable<Content> contentCollection, Section section)
{
if (string.IsNullOrWhiteSpace(section._id)) return null;
return contentCollection.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.SectionId) && x.SectionId == section._id);
}

public static Content GetFor(this List<Content> contentCollection, Button btn)
public static Content GetFor(this IEnumerable<Content> contentCollection, CarouselItem carouselItem)
{
if (string.IsNullOrWhiteSpace(carouselItem._id)) return null;
return contentCollection.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.CarouselItemId) && x.CarouselItemId == carouselItem._id);
}

public static Content GetFor(this IEnumerable<Content> contentCollection, CarouselButton carouselBtn)
{
if (string.IsNullOrWhiteSpace(carouselBtn._id)) return null;
return contentCollection.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.CarouselButtonId) && x.CarouselButtonId == carouselBtn._id);
}

public static Content GetFor(this IEnumerable<Content> contentCollection, Button btn)
{
if (string.IsNullOrWhiteSpace(btn._id)) return null;
return contentCollection.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.ButtonId) && x.ButtonId == btn._id);
}
public static Content GetFor(this List<Content> contentCollection, Coordinates coordiates)
public static Content GetFor(this IEnumerable<Content> contentCollection, Coordinates coordiates)
{
if (string.IsNullOrWhiteSpace(coordiates.CoordinateListId)) return null;
return contentCollection.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.ButtonId) && x.ButtonId == coordiates.CoordinateListId);
Expand Down
Loading

0 comments on commit 47b9b30

Please sign in to comment.