Skip to content

Commit

Permalink
query branches from answers
Browse files Browse the repository at this point in the history
  • Loading branch information
apav-dev committed Dec 9, 2021
1 parent bdfb7d8 commit a839192
Show file tree
Hide file tree
Showing 6 changed files with 2,222 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.env
.env
log.txt
55 changes: 38 additions & 17 deletions app/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"(Bond)[last_name], (James)[first_name], (Bond)[last_name]"
]
},
"house_num": {
"street_num": {
"open_set": true,
"values": [
{
Expand Down Expand Up @@ -223,21 +223,22 @@
}
],
"includes": [
"my building number is (seven)[house_num]",
"I live on (seventy five)[house_num] (William Penn Highway)[street]",
"my address is (one sixty two)[house_num] (Washington Road)[street]",
"deliver my order to (twenty seven)[house_num] (West Carson Street)[street]",
"deliver it to (six two one)[house_num] (McKnight Road)[street]",
"on (five hundred seventy nine)[house_num] (Centre Avenue)[street]",
"live on (Penn Avenue)[street] building number (seventy six)[house_num]",
"my address is (Centre ave)[street] building (one three six)[house_num]",
"my building number is (eighty three)[house_num]",
"house number is (two seventy three)[house_num]",
"my building number is (97)[house_num]",
"house number is (309)[house_num]",
"on (399)[house_num] (Centre Avenue)[street]",
"live on (Penn Avenue)[street] building number (598)[house_num]",
"my address is (Centre ave)[street] building (876)[house_num]"
"my building number is (seven)[street_num]",
"I live on (seventy five)[street_num] (William Penn Highway)[street]",
"my address is (one sixty two)[street_num] (Washington Road)[street]",
"deliver my order to (twenty seven)[street_num] (West Carson Street)[street]",
"deliver it to (six two one)[street_num] (McKnight Road)[street]",
"on (five hundred seventy nine)[street_num] (Centre Avenue)[street]",
"live on (Penn Avenue)[street] building number (seventy six)[street_num]",
"my address is (Centre ave)[street] building (one three six)[street_num]",
"my building number is (eighty three)[street_num]",
"street number is (two seventy three)[street_num]",
"my building number is (97)[street_num]",
"street number is (309)[street_num]",
"on (399)[street_num] (Centre Avenue)[street]",
"live on (Penn Avenue)[street] building number (598)[street_num]",
"my address is (Centre ave)[street] building (876)[street_num]",
"(829)[street_num] (elm spring road)[street] (pittsburgh)[city] (state)[state]"
]
},
"street": {
Expand Down Expand Up @@ -272,8 +273,28 @@
"I live on (Penn avenue)[street]"
]
},
"city": {
"open_set": true,
"values": [
{
"value": "Pittsburgh"
},
{
"value": "Chicago"
},
{
"value": "San Francisco"
},
{
"value": "Phoenix"
},
{
"value": "New York"
}
]
},
"state": {
"open_set": false,
"open_set": true,
"values": [
{
"value": "New York",
Expand Down
30 changes: 21 additions & 9 deletions app/main.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ context
last_name: string = "";
response: string = "";

house_num: string="";
street_num: string="";
street: string="";
city: string="";
state: string="";
zip_code: string="";
}

external function lookForBranch(zipCode: string): string;
external function lookForBranch(street_num: string, street: string, city: string, state: string, zip_code: string): string;

start node root //start node
{
Expand Down Expand Up @@ -66,18 +66,30 @@ digression set_zip_code
{
conditions
{
on #messageHasData("zip_code") and !#messageHasData("house_num") and !#messageHasData("street_name") and !#messageHasData("city") and !#messageHasData("state");
on #messageHasData("zip_code") and !#messageHasData("street_num") and !#messageHasData("street_name") and !#messageHasData("city") and !#messageHasData("state");
}
do
{
set $zip_code = #messageGetData("zip_code")[0]?.value??"";
set $zip_code = #messageGetData("zip_code")[0]?.value ?? "";
#sayText("Ok let me see if I can find a branch close by, just give me one second.");
var branch_response = external lookForBranch($zip_code);
var branch_response = external lookForBranch($street_num, $street, $city, $state, $zip_code);
#sayText("The closest branch I can find to you is located at " + branch_response);
}
}

// digression set_address
// {

// }
digression set_address
{
conditions
{
on #messageHasData("street_name") or #messageHasData("city") or !#messageHasData("state");
}
do
{
set $street_num = #messageGetData("street_num")[0]?.value ?? "";
set $street = #messageGetData("street")[0]?.value ?? "";
set $city = #messageGetData("city")[0]?.value ?? "";
set $state = #messageGetData("state")[0]?.value ?? "";
#sayText("Ok let me see if I can find a branch close by, just give me one second.");
var branch_response = external lookForBranch($street_num, $street, $city, $state, $zip_code);
}
}
48 changes: 41 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require("dotenv").config();
const { provideAnswersHeadless } = require("@yext/answers-headless");
const { provideCore } = require("@yext/answers-core");

const answers = provideAnswersHeadless({
const answers = provideCore({
apiKey: process.env.ANSWERS_API_KEY,
experienceKey: "firstfinancial-answers",
experienceKey: "dasha",
locale: "en",
experienceVersion: "PRODUCTION",
endpoints: {
Expand All @@ -24,6 +24,7 @@ const answers = provideAnswersHeadless({
});

const dasha = require("@dasha.ai/sdk");
const fs = require("fs");

const main = async () => {
const app = await dasha.deploy("./app");
Expand All @@ -36,16 +37,49 @@ const main = async () => {
: dasha.sip.connect(new dasha.sip.Endpoint("default"));

app.setExternal("lookForBranch", async (args, conv) => {
const zipCode = args.zipCode;
const street_num = args.street_num;
const street = args.street;
const city = args.city;
const state = args.state;
const zip_code = args.zip_code;
const locationQuery = `${street_num} ${street} ${city} ${state} ${zip_code}`;

console.log(zipCode);
return "Hello from Answers!";
console.log(
`street number: ${street_num} street: ${street} city: ${city} state: ${state} zip code: ${zip_code}`
);

const branchesResponse = await answers.verticalSearch({
query: locationQuery,
verticalKey: "locations",
limit: 1,
});

const branchLocation =
branchesResponse.verticalResults.results[0].rawData.address;

return `So it looks like we have a location at ${branchLocation.line1}. Would you like me to make you an appointment?`;
});

await app.start();

const conv = app.createConversation({
phone: process.argv[2],
phone: process.argv[2] ?? "",
});

if (conv.input.phone !== "chat") conv.on("transcription", console.log);

const logFile = await fs.promises.open("./log.txt", "w");
await logFile.appendFile("#".repeat(100) + "\n");

conv.on("transcription", async (entry) => {
await logFile.appendFile(`${entry.speaker}: ${entry.text}\n`);
});

conv.on("debugLog", async (event) => {
if (event?.msg?.msgId === "RecognizedSpeechMessage") {
const logEntry = event?.msg?.results[0]?.facts;
await logFile.appendFile(JSON.stringify(logEntry, undefined, 2) + "\n");
}
});

await conv.execute();
Expand Down
Loading

0 comments on commit a839192

Please sign in to comment.