This commit is contained in:
MIDDLEEAST\ariesch 2017-12-05 16:52:29 +02:00
Родитель 2abcb5e89a
Коммит ab7fcad601
3 изменённых файлов: 109 добавлений и 0 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -57,3 +57,5 @@ typings/
# dotenv environment variables file
.env
.vscode

79
index.js Normal file
Просмотреть файл

@ -0,0 +1,79 @@
var restify = require('restify');
var rp = require('request-promise');
const server = restify.createServer({
name: 'myapp',
version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
server.get('/ping', function (req, res, next) {
if (!process.env.BOT_SECRET) {
res.send(400, "BOT_SECRET env variable is missing");
return next();
}
if (!req.query.utterance) {
res.send(400, "utterance query param is missing");
return next();
}
rp(
{
method: 'POST',
uri: 'https://directline.botframework.com/v3/directline/conversations',
headers:
{
Authorization: "Bearer " + process.env.BOT_SECRET
},
json: true
}
).then(function (data) {
console.log("conversation Id " + data.conversationId);
var uri = "https://directline.botframework.com/v3/directline/conversations/{id}/activities";
uri = uri.replace("{id}", data.conversationId);
return rp(
{
uri: uri, method: "POST",
headers: {
Authorization: "Bearer " + process.env.BOT_SECRET
},
body: {
"type": "message",
"from": {
"id": "user1"
},
"text": req.query.utterance
},
json: true
}).then(function (data2) {
var uri = "https://directline.botframework.com/v3/directline/conversations/{id}/activities";
uri = uri.replace("{id}", data.conversationId);
setTimeout(function () {
return rp({
uri: uri,
method: "GET",
headers: {
Authorization: "Bearer " + process.env.BOT_SECRET
},
json: true
}).then(function (data3) {
res.send(200, data3.activities[1].text);
})
}, 5000);
})
}).catch(function (err) {
res.send(400, err.message);
});
return next();
});
server.listen(process.env.PORT | 3000, function () {
console.log('%s listening at %s', server.name, server.url);
});

28
package.json Normal file
Просмотреть файл

@ -0,0 +1,28 @@
{
"name": "healthbotpingtest",
"version": "1.0.0",
"description": "Sample availability test for HealthBot",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/HealthBotPingTest.git"
},
"keywords": [
"health",
"bot"
],
"author": "Arie Schwartzman",
"license": "MIT",
"bugs": {
"url": "https://github.com/Microsoft/HealthBotPingTest/issues"
},
"homepage": "https://github.com/Microsoft/HealthBotPingTest#readme",
"dependencies": {
"request": "^2.83.0",
"request-promise": "^4.2.2",
"restify": "^6.3.4"
}
}