Skip to content

Commit

Permalink
fix VoxaAI#140 utterance true turn to boolean (VoxaAI#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmberrios committed Mar 30, 2020
1 parent 660ab67 commit 0b41152
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 110 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ All notable changes to this project will be documented in this file
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [2.3.0] - 2020-03-27

### Added

- Added intent keys: parameterName and parameterValue
- Added tests
- Update spreadsheet files
- Updated spreadsheet files
- Added Google analytics to views

### Fixed

- Fixed true utterance to string

## [2.2.2] - 2020-02-05

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voxa-cli",
"version": "2.2.2",
"version": "2.3.0",
"description": "The Voxa CLI tools",
"bin": {
"voxa": "./bin/voxa.js"
Expand Down
27 changes: 25 additions & 2 deletions src/Processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ export function viewsProcessor(voxaSheets: IVoxaSheet[], AVAILABLE_LOCALES: stri
const shouldBeArray = [".text", ".say", ".reprompt", ".tell", ".ask"].find(suffix =>
path.includes(suffix)
);
const isGA = [".ga"].find(option => _.endsWith(pathLowerCase, option));
const isASuggestionChip = [".dialogflowsuggestions", ".facebooksuggestionchips"].find(
option => pathLowerCase.includes(option)
option => _.endsWith(pathLowerCase, option)
);

if (shouldBeArray && _.isString(value) && !_.isEmpty(value)) {
Expand All @@ -126,6 +127,28 @@ export function viewsProcessor(voxaSheets: IVoxaSheet[], AVAILABLE_LOCALES: stri
value = value.split("\n").map((v: string) => v.trim());
}

if (!_.isEmpty(value) && isGA) {
value = value.split("\n").reduce(
(accGA: { ec: string; ea: string; el: string }, next: string, index: number) => {
if (index === 0) {
accGA.ec = next;
accGA.ea = next;
}

if (index === 1) {
accGA.ea = next;
}

if (index === 2) {
accGA.el = next;
}

return accGA;
},
{} as any
);
}

_.set(acc, path, value);
return acc;
}, {})
Expand Down Expand Up @@ -389,7 +412,7 @@ export function publishingProcessor(voxaSheets: IVoxaSheet[], AVAILABLE_LOCALES:
);
}

function filterSheets(voxaSheets: IVoxaSheet[], sheetTypes: string[]): IVoxaSheet[] {
export function filterSheets(voxaSheets: IVoxaSheet[], sheetTypes: string[]): IVoxaSheet[] {
return _.filter(voxaSheets, voxaSheet => _.includes(sheetTypes, getSheetType(voxaSheet)));
}

Expand Down
11 changes: 9 additions & 2 deletions src/connectors/Excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import fs from "fs-extra";
import _ from "lodash";
import xlsx from "node-xlsx";
import path from "path";
import { IVoxaSheet } from "../VoxaSheet";
import { IVoxaSheet, SheetTypes } from "../VoxaSheet";
import { findSheetType, rowFormatted } from "./utils";
import { filterSheets } from "../Processor";

function findLocalFiles(spreadsheet: string): string[] {
const fsStats = fs.lstatSync(spreadsheet);
Expand Down Expand Up @@ -54,6 +55,8 @@ function readFileCreateWorkbook(f: string) {
}

function refactorExcelData(sheet: IVoxaSheet) {
const reestrictFormat = _.isEmpty(filterSheets([sheet], [SheetTypes.UTTERANCE]));

sheet.data = (_.chain(sheet).get("data") as any)
.map((next: any, index: number, arr: any) => {
if (index === 0) {
Expand All @@ -67,7 +70,11 @@ function refactorExcelData(sheet: IVoxaSheet) {
}
return next;
})
.reduce(rowFormatted, [] as any[])
.reduce(
(acc: any[], next: any, iindex: number, arr: any[]) =>
rowFormatted(acc, next, iindex, arr, reestrictFormat),
[] as any[]
)
.drop()
.value();
return sheet;
Expand Down
11 changes: 9 additions & 2 deletions src/connectors/Google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import bluebird from "bluebird";
import { auth, JWT } from "google-auth-library";
import { google, sheets_v4 } from "googleapis";
import _ from "lodash";
import { IVoxaSheet } from "../VoxaSheet";
import { IVoxaSheet, SheetTypes } from "../VoxaSheet";
import { findSheetType, rowFormatted } from "./utils";
import { filterSheets } from "../Processor";
global.Promise = bluebird;

const sheets = google.sheets("v4");
Expand Down Expand Up @@ -78,8 +79,14 @@ async function spreadsheetToVoxaSheet(
}

return spreadsheetResp.map((sheet: IVoxaSheet, index: number) => {
const reestrictFormat = _.isEmpty(filterSheets([sheet], [SheetTypes.UTTERANCE]));

const data = (_.chain(sheetPromises[index]).get("data.values", []) as any)
.reduce(rowFormatted, [])
.reduce(
(acc: any[], next: any, iindex: number, arr: any[]) =>
rowFormatted(acc, next, iindex, arr, reestrictFormat),
[] as any[]
)
.drop()
.value();

Expand Down
16 changes: 11 additions & 5 deletions src/connectors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,31 @@ export function findSheetType(spreadsheet: IVoxaSheet): IVoxaSheet | undefined {
return undefined;
}

export function rowFormatted(acc: any[], next: any, iindex: number, arr: any[]) {
export function rowFormatted(
acc: any[],
next: any,
iindex: number,
arr: any[],
reestrictFormat: boolean
) {
const item = (_.chain(arr).head() as any)
.zip(next)
.map((zipObj: any) => [zipObj[0], valueFormatted(zipObj[1])])
.map((zipObj: any) => [zipObj[0], valueFormatted(zipObj[1], reestrictFormat)])
.fromPairs()
.value();

acc.push(item);
return acc;
}

function valueFormatted(val: any) {
function valueFormatted(val: any, reestrictFormat: boolean) {
const valTemp = _.toLower(val);

if (_.includes(["true", "yes"], valTemp)) {
if (reestrictFormat && _.includes(["true", "yes"], valTemp)) {
val = true;
}

if (_.includes(["false", "no"], valTemp)) {
if (reestrictFormat && _.includes(["false", "no"], valTemp)) {
val = false;
}

Expand Down
3 changes: 2 additions & 1 deletion test/alexa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ configurations.forEach(interactionFile => {
"AMAZON.FallbackIntent",
"TravelIntent",
"BearIntent",
"HumanIntent"
"HumanIntent",
"AMAZON.YesIntent"
]);
});

Expand Down
2 changes: 1 addition & 1 deletion test/mocha.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { configurationToExecute } from "./utils";
export let configurations: any[] = configurationToExecute();

before(async function before() {
this.timeout(20000);
this.timeout(50000);

// make sure we delete the old assets
await fs.remove(path.join(__dirname, "out"));
Expand Down
Loading

0 comments on commit 0b41152

Please sign in to comment.