Skip to content

Commit

Permalink
fix ping handling
Browse files Browse the repository at this point in the history
  • Loading branch information
VladBrok committed Sep 30, 2023
1 parent 9df4f4c commit 917ec38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 0 additions & 3 deletions api/helpers/handle-utterance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default async function handleUtterance(
const isUpdateTask = intents?.["update_task"];
const isGetExpired = intents?.["get_expired"];
const isHelp = intents?.["help"];
const isPing = body.request.original_utterance.trim() === "ping"; // https://yandex.ru/dev/dialogs/alice/doc/moderation.html#check-after-moderation
let responseText = t("unhandle_utterance");
let responseTts = "";

Expand Down Expand Up @@ -205,8 +204,6 @@ export default async function handleUtterance(
} else if (isHelp) {
responseText = t("help");
responseTts = applyTts(responseText);
} else if (isPing) {
responseText = "pong";
}

const answer: ResBody = {
Expand Down
14 changes: 14 additions & 0 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import greetKnownUser from "./helpers/greet-known-user";
import greetNewUser from "./helpers/greet-new-user";
import handleError from "./helpers/handle-error";
import { initICU } from "./helpers/icu";
import end from "./helpers/end-response";

async function handler(req: VercelRequest, res: VercelResponse) {
if (req.method !== "POST") {
Expand All @@ -18,6 +19,19 @@ async function handler(req: VercelRequest, res: VercelResponse) {

const body = req?.body as ReqBody;
try {
// https://yandex.ru/dev/dialogs/alice/doc/moderation.html#check-after-moderation
const isPing = body.request.original_utterance.trim() === "ping";
if (isPing) {
end(res, {
version: body.version,
response: {
text: "pong",
end_session: false,
},
});
return;
}

await initICU();

const supportsAuth = Boolean(body.meta.interfaces.account_linking);
Expand Down

0 comments on commit 917ec38

Please sign in to comment.