Skip to content

Commit

Permalink
feat: added 10 point task
Browse files Browse the repository at this point in the history
  • Loading branch information
Дмитрий Никифоров committed Apr 24, 2022
1 parent 90d6762 commit 77694b3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
31 changes: 31 additions & 0 deletions cottage-cheese-response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { pick } = require("ramda");

const prepareText = (originalText) => {
return originalText.toLowerCase().replaceAll(",", "").replaceAll(" ", "");
};

const getResponseText = (text) => {
if (
(text.indexOf("вездекод") >= 0 || text.indexOf("вездеход") >= 0) &&
text.indexOf("нетворогатворог") >= 0
) {
return "Привет вездекодерам!";
}

return "Скажите 'Вездекод, команда не творог, а творог'";
};

module.exports = ({ request, session, version }) => {
let text = prepareText(request.original_utterance);
let responseText = getResponseText(text);

return {
response: {
text: responseText,
tts: responseText,
end_session: false,
},
session: pick(["session_id", "message_id", "user_id"], session),
version,
};
};
11 changes: 0 additions & 11 deletions create-echo-response.js

This file was deleted.

6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const express = require("express");
const server = express();
const bodyParser = require("body-parser");

const createEchoResponse = require("./create-echo-response.js");
const createResponse = require("./cottage-cheese-response.js");

server
.use(bodyParser.json())
.post("/webhook", (req, res) => res.json(createEchoResponse(req.body)))
.listen(process.env.PORT || 5000);
.post("/cottage-cheese", (req, res) => res.json(createResponse(req.body)))
.listen(process.env.PORT || 5000);

0 comments on commit 77694b3

Please sign in to comment.