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 14, 2017
2 parents 47b9b30 + d914756 commit 1beb8c2
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 40 deletions.
3 changes: 2 additions & 1 deletion ANAConversationPlatform/Models/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum ButtonTypeEnum
DeepLink,
GetAgent,
ApiCall,
ShowConfirmation
ShowConfirmation,
FetchChatFlow
}
}
2 changes: 2 additions & 0 deletions ANAConversationSimulator/ANAConversationSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
<Compile Include="Models\UploadFileResponse.cs" />
<Compile Include="UIHelpers\AutoSuggestFilterItemsCommand.cs" />
<Compile Include="UIHelpers\AutoSuggestFilterItemsConverter.cs" />
<Compile Include="UIHelpers\DirectionToTextAlignmentConverter.cs" />
<Compile Include="UIHelpers\DirectionToBorderColorConverter.cs" />
<Compile Include="UIHelpers\DirectionToForegroundColorConverter.cs" />
<Compile Include="UIHelpers\HTML2XamlRichText\RichTextBlockProperties.cs" />
<Compile Include="UIHelpers\HTMLToRichTextHelper.cs" />
Expand Down
7 changes: 6 additions & 1 deletion ANAConversationSimulator/Helpers/ButtonActionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void HandlePostTextToThread(string text)
MainPageViewModel.CurrentInstance.AddOutgoingSection(new TextSection
{
SectionType = SectionTypeEnum.Text,
Text = text
Text = text,
});
}
public static void HandlePostMediaToThread(string mediaUrl, ButtonTypeEnum mediaType)
Expand Down Expand Up @@ -131,6 +131,11 @@ internal static async Task HandleDeepLinkAsync(string deeplinkSlug)
Utils.ShowDialog($"Deeplink: {deeplinkSlug}.\r\nNote: Deeplinks not supported here");
}

internal static async Task HandleFetchChatFlowAsync(string flowUrl)
{
await MainPageViewModel.CurrentInstance.JoinNodesFromFlowAsync(flowUrl);
}

public static void NavigateToNode(string nodeId)
{
MainPageViewModel.CurrentInstance.NavigateToNode(nodeId);
Expand Down
10 changes: 10 additions & 0 deletions ANAConversationSimulator/Helpers/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using ANAConversationSimulator.Models;
using ANAConversationSimulator.Models.Chat;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -201,6 +204,13 @@ public static string CalculateMD5Hash(string input)
sb.Append(hash[i].ToString("X2"));
return sb.ToString();
}

public static readonly ButtonTypeEnum[] IGNORED_DEFAULT_BUTTONS = new[] { ButtonTypeEnum.GetItemFromSource };

public static bool IsSectionTypePresentInNode(JToken node, SectionTypeEnum secType)
{
return node?["Sections"]?.Any(x => x.ToObject<Section>()?.SectionType == secType) == true;
}
}

public enum DeviceFormFactorType
Expand Down
3 changes: 2 additions & 1 deletion ANAConversationSimulator/Models/Chat/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public enum ButtonTypeEnum
DeepLink,
GetAgent,
ApiCall,
ShowConfirmation
ShowConfirmation,
FetchChatFlow
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ANAConversationSimulator.Models.Chat;

namespace ANAConversationSimulator.Models.Sections
namespace ANAConversationSimulator.Models.Chat.Sections
{
public class PrintOTPSection : Section
{
Expand All @@ -9,5 +9,8 @@ public PrintOTPSection()
{
SectionType = SectionTypeEnum.PrintOTP;
}

//Below fields will be filled at runtime
public static string OTP { get; set; }
}
}
2 changes: 1 addition & 1 deletion ANAConversationSimulator/Models/Chat/Sections/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public enum SectionTypeEnum
Image, Text, Graph, Gif, Audio, Video, Link, EmbeddedHtml, Carousel, Typing, PrintOTP
}

public enum MessageDirection { In, Out }
public enum MessageDirection { In, Out, AwkwardCenter }
}
2 changes: 1 addition & 1 deletion ANAConversationSimulator/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="44cabbc3-0a2f-4255-b5bb-b099cd5762f9" Publisher="CN=ProjectANA" Version="1.0.66.0" />
<Identity Name="44cabbc3-0a2f-4255-b5bb-b099cd5762f9" Publisher="CN=ProjectANA" Version="1.0.70.0" />
<mp:PhoneIdentity PhoneProductId="44cabbc3-0a2f-4255-b5bb-b099cd5762f9" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>ANA Conversation Simulator</DisplayName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ public async void Execute(object parameter)
{
if (parameter is Button button)
{
var parentNode = MainPageViewModel.CurrentInstance.GetNodeById(button.NodeId);
var parsedParentNode = parentNode?.ToObject<ChatNode>();

//Special Case: Print OTP Section
if (Utils.IsSectionTypePresentInNode(parentNode, SectionTypeEnum.PrintOTP))
button.VariableValue = PrintOTPSection.OTP;

var userData = new Dictionary<string, string>();
switch (button.ButtonType)
{
case ButtonTypeEnum.PostText:
if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.ButtonText);
break;
case ButtonTypeEnum.OpenUrl:
Expand All @@ -39,7 +46,7 @@ public async void Execute(object parameter)
if (string.IsNullOrWhiteSpace(button.VariableValue)) return;
ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue);
userData[button.VariableName] = button.VariableValue;
if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText);
break;
case ButtonTypeEnum.GetEmail:
Expand All @@ -52,7 +59,7 @@ public async void Execute(object parameter)
ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue);
userData[button.VariableName] = button.VariableValue;

if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText);
break;
case ButtonTypeEnum.GetNumber:
Expand All @@ -65,7 +72,7 @@ public async void Execute(object parameter)
}
ButtonActionHelper.HandleSaveTextInput(button.VariableName, d.ToString());
userData[button.VariableName] = d.ToString();
if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.PrefixText + d.ToString() + button.PostfixText);
break;
case ButtonTypeEnum.GetPhoneNumber:
Expand All @@ -78,20 +85,20 @@ public async void Execute(object parameter)
ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue);
userData[button.VariableName] = button.VariableValue;

if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText);
break;
case ButtonTypeEnum.GetItemFromSource:
var valueToSave = button.Items.FirstOrDefault(x => x.Value == button.VariableValue);
if (valueToSave.Key == null && valueToSave.Value == null)
var valueToSave = button.Items?.FirstOrDefault(x => x.Value == button.VariableValue);
if (valueToSave?.Key == null && valueToSave?.Value == null)
{
Utils.ShowDialog("Invalid value");
return;
}
ButtonActionHelper.HandleSaveTextInput(button.VariableName, valueToSave.Key);
userData[button.VariableName] = valueToSave.Key;
ButtonActionHelper.HandleSaveTextInput(button.VariableName, valueToSave?.Key);
userData[button.VariableName] = valueToSave?.Key;

if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.PrefixText + button.VariableValue + button.PostfixText);
break;
case ButtonTypeEnum.GetAddress:
Expand Down Expand Up @@ -122,7 +129,7 @@ public async void Execute(object parameter)
userData["STREET_ADDRESS"] = ad.StreetAddress;
#endregion

if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread($"{ad.StreetAddress}\r\n\r\nCity: {ad.City}\r\nCountry: {ad.Country}\r\nPin: {ad.PinCode}");
done = true;
}
Expand All @@ -143,21 +150,28 @@ public async void Execute(object parameter)
ButtonActionHelper.HandlePostMediaToThread(mediaUrl, button.ButtonType);
break;
case ButtonTypeEnum.NextNode:
if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.ButtonText);
if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only
ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue);
break;
case ButtonTypeEnum.DeepLink:
await ButtonActionHelper.HandleDeepLinkAsync(button.DeepLinkUrl);
if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.ButtonText);
break;
case ButtonTypeEnum.GetAgent:
if (MainPageViewModel.CurrentInstance != null)
MainPageViewModel.CurrentInstance.AgentChat();
if (!button.Hidden)
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.ButtonText);
break;
case ButtonTypeEnum.FetchChatFlow:
if (!button.Hidden && button.PostToChat)
ButtonActionHelper.HandlePostTextToThread(button.ButtonText);
if (!string.IsNullOrWhiteSpace(button.VariableName) && button.VariableValue != null) //VariableValue should be != null only
ButtonActionHelper.HandleSaveTextInput(button.VariableName, button.VariableValue);
await ButtonActionHelper.HandleFetchChatFlowAsync(button.Url);
break;
default:
Utils.ShowDialog($"Button type: {button.ButtonType} not supported");
Expand Down
Loading

0 comments on commit 1beb8c2

Please sign in to comment.