Skip to content

Commit

Permalink
Added ChatNode.GroupName, Added ActivityTracking to Simulator View an…
Browse files Browse the repository at this point in the history
…d Click
  • Loading branch information
NizamLZ committed May 25, 2017
1 parent 6f7800d commit 6d58e75
Show file tree
Hide file tree
Showing 19 changed files with 280 additions and 49 deletions.
25 changes: 25 additions & 0 deletions ANAConversationPlatform/Controllers/ActivityController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using ANAConversationPlatform.Models.Activity;
using ANAConversationPlatform.Helpers;

namespace ANAConversationPlatform.Controllers
{
[Produces("application/json")]
public class ActivityController : Controller
{
[HttpGet]
public ActionResult Summary(string nodeIds)
{
var nodeIdList = nodeIds.Split(',');

return Ok(new { Message = "Done" });
}

[HttpPost]
public ActionResult Track([FromBody]ChatActivityEvent activityEvent)
{
MongoHelper.InsertActivityEvent(activityEvent);
return Ok();
}
}
}
4 changes: 2 additions & 2 deletions ANAConversationPlatform/Controllers/ConversationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public ActionResult Chat()
Debug.WriteLine(chatNodes.ToJson());
if (chatNodes == null || chatNodes.Count == 0)
{
//TODO: Log API Responsed as Not Found
//TODO: Log API Response as Not Found
//Task.Run(() => Logger.APILog("", ipAddress, requestTime, "Not Found", "Chat"));
return Ok(new object[] { });
}

//TODO: Log API Responsed as Not Found
//TODO: Log API Response as Ok
//Task.Run(() => Logger.APILog("", ipAddress, requestTime, "OK", "Chat"));

return Json(chatNodes, new JsonSerializerSettings()
Expand Down
21 changes: 18 additions & 3 deletions ANAConversationPlatform/Helpers/MongoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ANAConversationPlatform.Models.Activity;

namespace ANAConversationPlatform.Helpers
{
Expand Down Expand Up @@ -44,9 +45,14 @@ private static List<Content> Contents
{
get
{
if (_contents == null)
_contents = GetContentCollection();
return _contents;
if (Settings.CacheContent)
{
if (_contents == null)
_contents = GetContentCollection();
return _contents;
}
else
return GetContentCollection();
}
}

Expand Down Expand Up @@ -267,5 +273,14 @@ private static Section GetSection(BsonDocument sectionBsonDocument)
}
return sectObj;
}

public static void InsertActivityEvent(ChatActivityEvent activityEvent)
{
if (activityEvent != null && string.IsNullOrWhiteSpace(activityEvent._id))
activityEvent._id = ObjectId.GenerateNewId().ToString();

var coll = ChatDB.GetCollection<ChatActivityEvent>(Settings.ActivityEventLogCollectionName);
coll.InsertOne(activityEvent);
}
}
}
18 changes: 18 additions & 0 deletions ANAConversationPlatform/Models/Activity/ChatActivityItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;

namespace ANAConversationPlatform.Models.Activity
{
public class ChatActivityEvent
{
public string _id { get; set; }
public string EventCategory { get; set; }
public string EventChannel { get; set; }
public string EventName { get; set; }
public Dictionary<string, string> EventData { get; set; }
public Dictionary<string, string> UserData { get; set; }
public string UserId { get; set; }
public string NodeId { get; set; }
public DateTime EventDateTime { get; set; }
}
}
1 change: 1 addition & 0 deletions ANAConversationPlatform/Models/ChatNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ChatNode(string id)
public string ApiUrl { get; set; } = null;
public string NextNodeId { get; set; } = null;
public string[] RequiredVariables { get; set; } = null;
public string GroupName { get; set; }
}

public enum NodeTypeEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ namespace ANAConversationPlatform.Models.Settings
{
public class DatabaseConnectionSettings
{
[JsonProperty("ConnectionString")]
public string ConnectionString { get; set; }

[JsonProperty("TemplateCollectionName")]
public string TemplateCollectionName { get; set; }

[JsonProperty("ContentCollectionName")]
public string ContentCollectionName { get; set; }

[JsonProperty("DatabaseName")]
public string DatabaseName { get; set; }
public bool CacheContent { get; set; }
public string ActivityEventLogCollectionName { get; set; }
}
}
4 changes: 3 additions & 1 deletion ANAConversationPlatform/appsettings-Sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"ConnectionString": "[MongoDB Connection String]",
"TemplateCollectionName": "[New Empty Collection Name A]",
"ContentCollectionName": "[New Empty Collection Name B]",
"DatabaseName": "[Mongo Database name]"
"DatabaseName": "[Mongo Database name]",
"CacheContent": false,
"ActivityEventLogCollectionName": "[New Empty Collection Name C]"
}
}
4 changes: 4 additions & 0 deletions ANAConversationSimulator/ANAConversationSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="Models\ChatActivityEvent.cs" />
<Compile Include="Models\UploadFileResponse.cs" />
<Compile Include="UIHelpers\AutoSuggestFilterItemsCommand.cs" />
<Compile Include="UIHelpers\AutoSuggestFilterItemsConverter.cs" />
Expand Down Expand Up @@ -249,6 +250,9 @@
</Page>
</ItemGroup>
<ItemGroup>
<SDKReference Include="WindowsDesktop, Version=10.0.10586.0">
<Name>Windows Desktop Extensions for the UWP</Name>
</SDKReference>
<SDKReference Include="WindowsMobile, Version=10.0.10586.0">
<Name>Windows Mobile Extensions for the UWP</Name>
</SDKReference>
Expand Down
28 changes: 28 additions & 0 deletions ANAConversationSimulator/Helpers/APIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading.Tasks;
using Windows.Storage;
using System.IO;
using ANAConversationSimulator.Models;

namespace ANAConversationSimulator.Helpers
{
public class APIHelper
Expand Down Expand Up @@ -47,6 +49,14 @@ public static async Task<TResponse> HitPostAsync<TRequest, TResponse>(string api
return JsonConvert.DeserializeObject<TResponse>(await resp.Content.ReadAsStringAsync());
}
}
public static async Task HitPostAsync<TRequest>(string api, TRequest data)
{
using (var client = new HttpClient())
{
var resp = await client.PostAsync(api, new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"));
resp = resp.EnsureSuccessStatusCode();
}
}

public static async Task<TResponse> UploadFile<TResponse>(string fileName, StorageFile sFile)
{
Expand All @@ -67,6 +77,24 @@ public static async Task<TResponse> UploadFile<TResponse>(string fileName, Stora
}
}

public static async Task TrackEvent(ChatActivityEvent activityEvent)
{
try
{
Utils.APISettings.Values.TryGetValue("ActivityTrackAPI", out object ActivityTrackAPI);
if (string.IsNullOrWhiteSpace(ActivityTrackAPI + ""))
{
Utils.ShowDialog("Activity Track API is not set. Please go to Menu(...) -> Update APIs and set it.");
return;
}
await HitPostAsync(ActivityTrackAPI + "", activityEvent);
}
catch (Exception ex)
{
await Utils.ShowDialogAsync(ex.ToString());
}
}

public static async Task<(string City, string Country, string Pincode, string FormattedAddress)> LoadCityCountryFromLatLongAsync(double lat, double lng)
{
try
Expand Down
60 changes: 59 additions & 1 deletion ANAConversationSimulator/Helpers/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Newtonsoft.Json;
using ANAConversationSimulator.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.System.Profile;
using Windows.UI.Popups;

namespace ANAConversationSimulator.Helpers
Expand Down Expand Up @@ -120,6 +123,61 @@ public static async Task LoadConfig()
ShowDialog("Unable to load Config.\r\n\r\nMessage: " + ex.Message);
}
}

public static ChatActivityEvent GetViewEvent(string nodeId, string userId)
{
return new ChatActivityEvent
{
EventCategory = "ANA_CHAT",
EventChannel = "ANA_SIM_WIN",
NodeId = nodeId,
EventName = "VIEW",
UserId = userId,
EventDateTime = DateTime.UtcNow,
};
}
public static ChatActivityEvent GetClickEvent(string nodeId, string userId, string buttonId, string buttonLabel, Dictionary<string, string> userData)
{
return new ChatActivityEvent
{
EventCategory = "ANA_CHAT",
EventChannel = "ANA_SIM_WIN",
NodeId = nodeId,
EventName = "CLICK",
UserId = userId,
EventDateTime = DateTime.UtcNow,
EventData = new Dictionary<string, string>
{
{ "ButtonID", buttonId },
{ "ButtonLabel", buttonLabel },
},
UserData = userData
};
}

private static string _deviceId;
public static string DeviceId
{
get
{
if (_deviceId == null)
_deviceId = GetDeviceId();
return _deviceId;
}
}
private static string GetDeviceId()
{
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification"))
{
var token = HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes).Replace("-", "");
}
return "DEVICE-ID-NOT-FOUND";
}
}

public enum DeviceFormFactorType
Expand Down
7 changes: 4 additions & 3 deletions ANAConversationSimulator/Models/Chat/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public Button() { }
public ButtonTypeEnum ButtonType { get; set; }
public string DeepLinkUrl { get; set; }
public string Url { get; set; }
public int? BounceTimeout { get; set; } = null;
public int? BounceTimeout { get; set; }
public string NextNodeId { get; set; }
public bool DefaultButton { get; set; } = false;
public bool Hidden { get; set; }
public string VariableValue { get; set; } = null;
public string VariableValue { get; set; }
public string PlaceholderText { get; set; }
public bool ConfirmInput { get; set; }
public string PrefixText { get; set; }
Expand Down Expand Up @@ -51,7 +51,8 @@ public Dictionary<string, string> Items
public Dictionary<string, string> ItemsSource { get; set; }

//Below fields are filled at runtime
public string VariableName { get; set; } = null;
public string VariableName { get; set; }
public string NodeId { get; set; }
public ButtonActionCommand Action { get; } = new ButtonActionCommand();
public bool Visible { get { return !Hidden; } }

Expand Down
1 change: 1 addition & 0 deletions ANAConversationSimulator/Models/Chat/ChatNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ChatNode(string id)
public string[] RequiredVariables { get; set; } = null;
public string NextNodeId { get; set; } = null;
public bool IsStartNode { get; set; }
public string GroupName { get; set; }
}

public enum NodeTypeEnum
Expand Down
17 changes: 17 additions & 0 deletions ANAConversationSimulator/Models/ChatActivityEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;

namespace ANAConversationSimulator.Models
{
public class ChatActivityEvent
{
public string EventCategory { get; set; }
public string EventChannel { get; set; }
public string EventName { get; set; }
public Dictionary<string, string> EventData { get; set; }
public Dictionary<string, string> UserData { get; set; }
public string UserId { get; set; }
public string NodeId { get; set; }
public DateTime EventDateTime { get; set; }
}
}
Loading

0 comments on commit 6d58e75

Please sign in to comment.