Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull and push scenarios using a CLI.
- Loading branch information
Showing
6 changed files
with
620 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/getConfig.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const jwt = require("jsonwebtoken"); | ||
const rp = require("request-promise"); | ||
const fs = require('fs'); | ||
|
||
if (process.argv.length < 5 && process.argv.length > 7) { | ||
console.log("Usage: node healthbotCli.js get_scenarios <tenantName> <API_JWT_secret>"); | ||
console.log("Usage: node healthbotCli.js get_scenario <tenantName> <API_JWT_secret> <scenarioName> <outputFilePath>"); | ||
console.log("Usage: node healthbotCli.js post_scenario <tenantName> <API_JWT_secret> <inputFilePath>"); | ||
process.exit(); | ||
} | ||
const action = process.argv[2]; | ||
const tenantName = process.argv[3]; | ||
const jwtSecret = process.argv[4]; | ||
const scenarioName = process.argv[5]; | ||
const targetFile = process.argv[6]; | ||
|
||
const BASE_URL = "https://us.healthbot.microsoft.com/"; | ||
|
||
const jwtToken = jwt.sign({ "tenantName": tenantName }, jwtSecret); | ||
|
||
if (action === "post_scenario") { | ||
|
||
fs.readFile(targetFile, 'utf8', (err, scenarioJson) => { | ||
if (err) { | ||
console.log("File read failed:", err) | ||
return | ||
} else { | ||
const options = { | ||
method: 'POST', | ||
uri: `${BASE_URL}api/account/${tenantName}/scenarios`, | ||
headers: { | ||
'Authorization': 'Bearer ' + jwtToken | ||
}, | ||
body: [scenarioJson], | ||
json: true | ||
}; | ||
|
||
rp(options) | ||
.then(function (parsedBody) { | ||
console.log(parsedBody); | ||
}) | ||
.catch(function (err) { | ||
console.log(err.message); | ||
}); | ||
} | ||
}); | ||
|
||
|
||
} | ||
|
||
if (action === "get_scenarios") { | ||
const options = { | ||
method: 'GET', | ||
uri: `${BASE_URL}api/account/${tenantName}/scenarios`, | ||
headers: { | ||
'Authorization': 'Bearer ' + jwtToken | ||
} | ||
}; | ||
|
||
rp(options) | ||
.then(function (parsedBody) { | ||
const scenarios = JSON.parse(parsedBody); | ||
scenarios.map(i => { | ||
console.log(`${i.name} - ${i.id} - ${i.description ? i.description : "No description"}`) | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log(err.message); | ||
}); | ||
} | ||
|
||
if (action === "get_scenario") { | ||
const options = { | ||
method: 'GET', | ||
uri: `${BASE_URL}api/account/${tenantName}/scenarios`, | ||
headers: { | ||
'Authorization': 'Bearer ' + jwtToken | ||
} | ||
}; | ||
|
||
rp(options) | ||
.then(function (parsedBody) { | ||
const scenarios = JSON.parse(parsedBody); | ||
scenarios.map(i => { | ||
if (i.name === scenarioName) { | ||
var data = JSON.stringify(i); | ||
fs.writeFile(targetFile, data, (err) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
}; | ||
}); | ||
} | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log(err.message); | ||
}); | ||
} | ||
|
Oops, something went wrong.