Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Updating code virtual currency action
Browse files Browse the repository at this point in the history
  • Loading branch information
rosireddyr committed Aug 10, 2023
1 parent 4ede974 commit b2fd2ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ public static async Task RunAsync()
"Create a segment with name NewPlayersSegment for the players first logged in date greater than 2023-08-01?", // Working
"Create a segment with name LegacyPlayersSegment for the players last logged in date less than 2023-05-01?", // Working
"Create a segment with name EgyptNewPlayers for the players located in the Egypt?", // Working
//"Create a segment for china for the players logged in the last 30 days and grant them 10 virtual currency?",
"Create a segment with name ChinaPlayers for the players in china and grant them 10 VC virtual currency?", // Working
//"Create a segment with name ChinaNewPlayers for the players in china who first logged in the last 30 days and grant them 10 virtual currency?",
//"Create a segment with name WelcomeEgyptNewPlayers for the players located in the Egypt with entered segment action of email notification?", // With entered segment action
//"Create a segment with name EgyptNewPlayers for the players located in the Egypt?" // If the segment already exist, create a segment with name appended with guid
};

foreach (string prompt in goals)
{
await CreateSegmentExample(prompt);
try
{
await CreateSegmentExample(prompt);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}

Expand Down
24 changes: 19 additions & 5 deletions dotnet/samples/KernelSyntaxExamples/Skills/SegmentSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ public sealed class SegmentSkill
public async Task<string> CreateSegment([Description("Name of the segment.")] string segmentname,
[Description("Name of the segment definition. Some of the examples are FirstLoginDateFilter, LastLoginDateFilter, LocationFilter.")] string segmentdefinition,
[Description("Name of the segment comparison. Some of the examples are GreaterThan, LessThan, Equals.")] string segmentcomparison,
[Description("Value of the segment comparison. Some of the examples are 2023-08-01, India, Australia, Kenya. For country get 2 letter country code instead of country name.")] string segmentcomparisonvalue
[Description("Value of the segment comparison. Some of the examples are 2023-08-01, India, Australia, Kenya. For country get 2 letter country code instead of country name.")] string segmentcomparisonvalue,
[Description("Name of the segment action. Examples are GrantVirtualCurrencyAction, EmailNotificationAction. This is empty if there is no segment action.")] string segmentaction,
[Description("Name of the segment action key or code. Examples are virtual currency code, email template id. This is empty if there is no segment action.")] string segmentactioncode,
[Description("Name of the segment action key value or code value. Examples are template name, virtual currency amount. This is empty if there is no segment action.")] string segmentactionvalue
)
{
//ToDo: Create payload json using Playfab dlls/sdk
// Set properties to create a Segment using swagger.json
ContextVariables contextVariables = new();
contextVariables.Set("content_type", "application/json");
contextVariables.Set("server_url", TestConfiguration.PlayFab.Endpoint);
string segmentPayload = GetSegmentPayload(segmentname, segmentdefinition, segmentcomparison, ref segmentcomparisonvalue);
string segmentPayload = GetSegmentPayload(segmentname, segmentdefinition, segmentcomparison, segmentcomparisonvalue, segmentaction, segmentactioncode, segmentactionvalue);

contextVariables.Set("content_type", "application/json");
contextVariables.Set("payload", segmentPayload);
Expand All @@ -58,16 +61,27 @@ public async Task<string> CreateSegment([Description("Name of the segment.")] st
return $"Segment {segmentname} created with segment definition {segmentdefinition}";
}

private static string GetSegmentPayload(string segmentname, string segmentdefinition, string segmentcomparison, ref string segmentcomparisonvalue)
private static string GetSegmentPayload(string segmentname, string segmentdefinition, string segmentcomparison, string segmentcomparisonvalue, string segmentaction, string segmentactioncode, string segmentactionvalue)
{
string segmentPayload = "{\n \"SegmentModel\": {\n \"Name\": \"<SegmentName>\",\n \"SegmentOrDefinitions\": [\n {\n \"SegmentAndDefinitions\": [\n {\n \"<SegmentDefinition>\": {\n \"LogInDate\": \"<SegmentComparisonValue>T00:00:00Z\",\n \"Comparison\": \"<SegmentComparison>\"\n }\n }\n ]\n }\n ]\n }\n }";
string locationPayload = "{\n \"SegmentModel\": {\n \"Name\": \"<SegmentName>\",\n \"SegmentOrDefinitions\": [\n {\n \"SegmentAndDefinitions\": [\n {\n \"<SegmentDefinition>\": {\n \"CountryCode\": \"<SegmentComparisonValue>\",\n \"Comparison\": \"<SegmentComparison>\"\n }\n }\n ]\n }\n ]\n }\n }";
//ToDo: Need to explore and replace this logic with open ai chat.
string segmentPayload = "{\n \"SegmentModel\": {\n \"Name\": \"<SegmentName>\",\n \"SegmentOrDefinitions\": [\n {\n \"SegmentAndDefinitions\": [\n {\n \"<SegmentDefinition>\": {\n \"LogInDate\": \"<SegmentComparisonValue>T00:00:00Z\",\n \"Comparison\": \"<SegmentComparison>\"\n }\n }\n ]\n }\n ]\n <EnteredSegmentAction> }\n }";
string locationPayload = "{\n \"SegmentModel\": {\n \"Name\": \"<SegmentName>\",\n \"SegmentOrDefinitions\": [\n {\n \"SegmentAndDefinitions\": [\n {\n \"<SegmentDefinition>\": {\n \"CountryCode\": \"<SegmentComparisonValue>\",\n \"Comparison\": \"<SegmentComparison>\"\n }\n }\n ]\n }\n ]\n <EnteredSegmentAction> }\n }";

if (segmentdefinition == "LocationFilter")
{
segmentPayload = locationPayload;
}

if (!string.IsNullOrEmpty(segmentaction) && segmentaction == "GrantVirtualCurrencyAction")
{
string enteredSegmentAction = $", \"EnteredSegmentActions\": [\n {{\n \"GrantVirtualCurrencyAction\": {{\n \"CurrencyCode\": \"{segmentactioncode}\",\n \"Amount\": {segmentactionvalue}\n }}\n }}\n ]";
segmentPayload = segmentPayload.Replace("<EnteredSegmentAction>", enteredSegmentAction);
}
else
{
segmentPayload = segmentPayload.Replace("<EnteredSegmentAction>", string.Empty);
}

segmentPayload = segmentPayload.Replace("<SegmentName>", segmentname);
segmentPayload = segmentPayload.Replace("<SegmentDefinition>", segmentdefinition);
segmentPayload = segmentPayload.Replace("<SegmentComparison>", segmentcomparison);
Expand Down

0 comments on commit b2fd2ba

Please sign in to comment.