Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Cortana integration from a hosted web app on Windows. To do this you'll need a meta tag in your html page pointint to an xml voice command definition file on your server. You'll also need to handle the Cortana activation event in your JavaScript.
<!DOCTYPE html>
<title>Cortana Example</title>
<!--Cortana meta tag pointing to VCD file on the server-->
<meta name="msapplication-cortanavcd" content=""/>
if (typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.ApplicationModel !== 'undefined')
// Subscribe to the Windows Activation Event
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (args) {
var activation = Windows.ApplicationModel.Activation;
// Check to see if the app was activated by a voice command
if (args.kind === activation.ActivationKind.voiceCommand) {
// Get the speech reco
var speechRecognitionResult = args.result;
var textSpoken = speechRecognitionResult.text;
// Determine the command type {search} defined in vcd
if (speechRecognitionResult.rulePath[0] === "search") {
// Determine the stream name specified
if (textSpoken.includes('foo') || textSpoken.includes('Foo')) {
console.log("The user is searching for foo");
else if (textSpoken.includes('bar') || textSpoken.includes('Bar') ) {
console.log("The user is searching for a bar");
else {
console.log("Invalid search term specified by user");
else {
console.log("No valid command specified");
} else {
console.log("Windows namespace is unavaiable");
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="">
<CommandSet xml:lang="en-us" Name="RJS">
<Example>MyApp search for foo</Example>
<Command Name="Search">
<Example>search {message} using myapp</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">Search for {searchTerm}</ListenFor>
<Feedback>Searching for {searchTerm} with MyApp</Feedback>
<Navigate Target="/search.htm"/>
<PhraseTopic Label="searchTerm" Scenario="Dictation"></PhraseTopic>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment