Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
826 changes: 826 additions & 0 deletions specs/activity/schema/activity-protocol.schema.json

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions specs/activity/schema/validator/csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using NJsonSchema;
using NJsonSchema.Validation;
using Newtonsoft.Json.Linq;

static async Task<JsonSchema> LoadSchemaAsync(string schemaPath) => await JsonSchema.FromFileAsync(schemaPath);

string schemaFile = Path.Combine(AppContext.BaseDirectory, "activity.schema.json");
if (!File.Exists(schemaFile))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Schema file not found: {schemaFile}");
Console.ResetColor();
return;
}

// Discover example files relative to project root (navigate up to validator folder structure)
// Expect examples under ../examples/json
string? baseDir = AppContext.BaseDirectory;
// Try to locate examples directory by walking up a few levels
string? examplesDir = null;
var current = new DirectoryInfo(baseDir);
for (int i = 0; i < 6 && current != null; i++)
{
var probe = Path.Combine(current.FullName, "examples", "json");
if (Directory.Exists(probe)) { examplesDir = probe; break; }
current = current.Parent;
}

if (examplesDir == null)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Examples directory not found (expected ../examples/json). Will fall back to input.json if present.");
Console.ResetColor();
}

var schema = await LoadSchemaAsync(schemaFile);

List<(string name, JToken instance)> instances = new();

if (examplesDir != null)
{
foreach (var file in Directory.GetFiles(examplesDir, "*.json", SearchOption.TopDirectoryOnly).OrderBy(f => f))
{
try
{
var text = File.ReadAllText(file);
instances.Add((Path.GetFileName(file), JToken.Parse(text)));
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Failed to parse {file}: {ex.Message}");
Console.ResetColor();
}
}
}

// Backward compatibility: single input.json
string singleInput = Path.Combine(AppContext.BaseDirectory, "input.json");
if (File.Exists(singleInput))
{
try
{
instances.Add(("input.json", JToken.Parse(File.ReadAllText(singleInput))));
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("input.json parse error: " + ex.Message);
Console.ResetColor();
}
}

if (instances.Count == 0)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("No JSON instances found to validate.");
Console.ResetColor();
return;
}

int total = 0;
int failures = 0;

foreach (var (name, token) in instances)
{
total++;
var errors = schema.Validate(token);
if (errors.Count == 0)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[OK] {name} ({token["type"] ?? "unknown-type"})");
Console.ResetColor();
}
else
{
failures++;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[FAIL] {name} ({token["type"] ?? "unknown-type"}) - {errors.Count} error(s)");
Console.ResetColor();
int i = 1;
foreach (var e in errors)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($" [{i}] {e.Kind}");
Console.ResetColor();
Console.WriteLine($" Path : {(string.IsNullOrEmpty(e.Path) ? "$" : "$" + e.Path)}");
Console.WriteLine($" Detail : {e}");
if (!string.IsNullOrEmpty(e.Property))
Console.WriteLine($" Property: {e.Property}");
i++;
}
}
}

Console.WriteLine();
Console.WriteLine($"Summary: {total - failures} valid / {failures} invalid / {total} total");
if (failures == 0)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("All examples are valid.");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Some examples failed validation.");
Console.ResetColor();
Environment.ExitCode = 1;
}
14 changes: 14 additions & 0 deletions specs/activity/schema/validator/csharp/SchemaValidator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema" Version="11.5.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions specs/activity/schema/validator/csharp/SchemaValidator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36414.22 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchemaValidator", "SchemaValidator.csproj", "{2F44ACFB-7A40-4433-8D58-476B682C7AF7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {833ED1E0-B359-4969-936C-1C5ED1B6803F}
EndGlobalSection
EndGlobal
38 changes: 38 additions & 0 deletions specs/activity/schema/validator/examples/json/01-message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"type": "message",
"id": "message-activity-1",
"timestamp": "2025-09-15T10:00:01.000Z",
"localTimestamp": "2025-09-15T03:00:01.000-07:00",
"localTimezone": "America/Los_Angeles",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "isGroup": true, "id": "conv-1", "name": "Project Discussion" },
"recipient": { "id": "bot-id-1", "name": "HelpBot" },
"text": "Hello, I need help with my order.",
"textFormat": "plain",
"locale": "en-US",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"title": "Order #12345",
"text": "Status: Shipped"
}
}
],
"suggestedActions": {
"actions": [
{
"type": "imBack",
"title": "Track Package",
"value": "track order 12345"
},
{
"type": "imBack",
"title": "Cancel Order",
"value": "cancel order 12345"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "contactRelationUpdate",
"id": "contact-relation-update-1",
"timestamp": "2025-09-15T10:00:02.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "skype",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "id": "conv-2" },
"recipient": { "id": "bot-id-1", "name": "WelcomeBot" },
"action": "add"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "conversationUpdate",
"id": "conversation-update-1",
"timestamp": "2025-09-15T10:00:03.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-2", "name": "Jane Smith" },
"conversation": { "isGroup": true, "id": "conv-1", "name": "Project Discussion" },
"recipient": { "id": "bot-id-1", "name": "HelpBot" },
"membersAdded": [ { "id": "user-id-3", "name": "Sam Brown" } ],
"membersRemoved": [],
"topicName": "Project Discussion Kickoff"
}
10 changes: 10 additions & 0 deletions specs/activity/schema/validator/examples/json/04-typing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "typing",
"id": "typing-1",
"timestamp": "2025-09-15T10:00:04.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "webchat",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "id": "conv-3" },
"recipient": { "id": "bot-id-1", "name": "EchoBot" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "endOfConversation",
"id": "end-of-conv-1",
"timestamp": "2025-09-15T10:00:05.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "bot-id-1", "name": "SurveyBot" },
"conversation": { "id": "conv-4" },
"recipient": { "id": "user-id-4", "name": "Peter Jones" },
"code": "completedSuccessfully",
"text": "Thanks for completing the survey!"
}
12 changes: 12 additions & 0 deletions specs/activity/schema/validator/examples/json/06-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "event",
"id": "event-1",
"timestamp": "2025-09-15T10:00:06.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "webchat",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "id": "conv-5" },
"recipient": { "id": "bot-id-1", "name": "LocationBot" },
"name": "locationReceived",
"value": { "latitude": 47.6062, "longitude": -122.3321 }
}
12 changes: 12 additions & 0 deletions specs/activity/schema/validator/examples/json/07-invoke.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "invoke",
"id": "invoke-1",
"timestamp": "2025-09-15T10:00:07.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "id": "conv-6" },
"recipient": { "id": "bot-id-1", "name": "TaskBot" },
"name": "task/submit",
"value": { "taskId": "task-987", "data": { "comments": "All done." } }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "messageUpdate",
"id": "message-activity-1",
"timestamp": "2025-09-15T10:00:08.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "id": "conv-1" },
"recipient": { "id": "bot-id-1", "name": "HelpBot" },
"text": "Hello, I need help with my order #12345.",
"locale": "en-US"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "messageDelete",
"id": "message-activity-to-delete",
"timestamp": "2025-09-15T10:00:09.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-1", "name": "John Doe" },
"conversation": { "id": "conv-1" },
"recipient": { "id": "bot-id-1", "name": "HelpBot" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "installationUpdate",
"id": "install-update-1",
"timestamp": "2025-09-15T10:00:10.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-admin", "name": "Admin User" },
"conversation": { "id": "conv-tenant-level" },
"recipient": { "id": "bot-id-1", "name": "AdminBot" },
"action": "add"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "messageReaction",
"id": "reaction-1",
"timestamp": "2025-09-15T10:00:11.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "msteams",
"from": { "id": "user-id-2", "name": "Jane Smith" },
"conversation": { "id": "conv-1" },
"recipient": { "id": "bot-id-1", "name": "HelpBot" },
"replyToId": "message-activity-1",
"reactionsAdded": [ { "type": "like" } ],
"reactionsRemoved": []
}
13 changes: 13 additions & 0 deletions specs/activity/schema/validator/examples/json/12-suggestion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "suggestion",
"id": "suggestion-1",
"timestamp": "2025-09-15T10:00:12.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "cortana",
"from": { "id": "bot-id-1", "name": "CalendarBot" },
"conversation": { "id": "conv-7" },
"recipient": { "id": "user-id-1", "name": "John Doe" },
"replyToId": "original-message-id",
"text": "I can create that meeting for you.",
"textHighlights": [ { "text": "meet on Monday", "occurrence": 1 } ]
}
18 changes: 18 additions & 0 deletions specs/activity/schema/validator/examples/json/13-trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "trace",
"id": "trace-1",
"timestamp": "2025-09-15T10:00:13.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "emulator",
"from": { "id": "bot-id-1", "name": "DebuggingBot" },
"conversation": { "id": "conv-debug" },
"recipient": { "id": "user-id-dev", "name": "Developer" },
"name": "LUIS_TRACE",
"label": "LUIS Trace",
"valueType": "https://www.luis.ai/schemas/trace",
"value": {
"query": "book a flight to paris",
"topScoringIntent": { "intent": "BookFlight", "score": 0.98 },
"entities": [ { "type": "Location", "entity": "paris" } ]
}
}
11 changes: 11 additions & 0 deletions specs/activity/schema/validator/examples/json/14-handoff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "handoff",
"id": "handoff-1",
"timestamp": "2025-09-15T10:00:14.000Z",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"channelId": "custom-channel",
"from": { "id": "bot-id-1", "name": "TriageBot" },
"conversation": { "id": "conv-8" },
"recipient": { "id": "human-agent-system", "name": "Live Agent Hub" },
"value": { "reason": "User requested human agent", "transcript": [ "User: I need to speak to a person.", "Bot: OK, I'll connect you to a live agent." ] }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "message",
"channelId": "emulator",
"from": { "id": "user1", "name": "User One" },
"conversation": { "id": "conv1", "name": "Conversation 1" },
"recipient": { "id": "bot", "name": "Bot" },
"serviceUrl": "https://example.org",
"text": "Hello, world!"
}
Loading