Skip to content

Commit

Permalink
Lib
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed May 17, 2018
1 parent 5136b83 commit 0547364
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/decorators/dialog-flow-param.decorator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'reflect-metadata';
export declare const DialogFlowParam: (property?: string) => (target: any, key: any, index: any) => any;
12 changes: 12 additions & 0 deletions lib/decorators/dialog-flow-param.decorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constant_1 = require("../constant");
exports.DialogFlowParam = (property) => {
return (target, key, index) => {
const metadataValue = Reflect.getMetadata(constant_1.DIALOG_FLOW_PARAMS, target) || [];
metadataValue.push({ key, property, index });
Reflect.defineMetadata(constant_1.DIALOG_FLOW_PARAMS, metadataValue, target);
return target;
};
};
39 changes: 39 additions & 0 deletions lib/decorators/tests/fixtures/data.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export declare const dialogFlowResponseData: {
"responseId": string;
"queryResult": {
"queryText": string;
"parameters": {
"date": string;
"geo-city": string;
};
"allRequiredParamsPresent": boolean;
"fulfillmentMessages": {
"text": {
"text": string[];
};
}[];
"outputContexts": {
"name": string;
"lifespanCount": number;
"parameters": {
"date.original": string;
"date": string;
"geo-city.original": string;
"geo-city": string;
};
}[];
"intent": {
"name": string;
"displayName": string;
};
"intentDetectionConfidence": number;
"diagnosticInfo": {
"webhook_latency_ms": number;
};
"languageCode": string;
};
"webhookStatus": {
"code": number;
"message": string;
};
};
47 changes: 47 additions & 0 deletions lib/decorators/tests/fixtures/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dialogFlowResponseData = {
"responseId": "1d05835a-1092-442e-b363-910c34c6e735",
"queryResult": {
"queryText": "Météo de demain à marseille",
"parameters": {
"date": "2018-05-16T12:00:00+02:00",
"geo-city": "Marseille"
},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"outputContexts": [
{
"name": "projects/hermes-d8e54/agent/sessions/f060c5a3-f95e-4551-aedd-3d970d0d4dc4/contexts/weather_question",
"lifespanCount": 5,
"parameters": {
"date.original": "de demain",
"date": "2018-05-16T12:00:00+02:00",
"geo-city.original": "marseille",
"geo-city": "Marseille"
}
}
],
"intent": {
"name": "projects/hermes-d8e54/agent/intents/62e2d690-bf1b-4eaa-af39-c9c0d48b8c41",
"displayName": "Question:weather"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 75
},
"languageCode": "fr"
},
"webhookStatus": {
"code": 5,
"message": "Webhook call failed. Error: 404 Not Found"
}
};
1 change: 1 addition & 0 deletions lib/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function applyParamsMetadataDecorator(paramsMetadata: any[], args: any[]): any[];
19 changes: 19 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function applyParamsMetadataDecorator(paramsMetadata, args) {
if (paramsMetadata.length && args.length) {
for (const param of paramsMetadata) {
if (typeof args[param.index] === 'object') {
if (!param.property) {
args[param.index] = args[param.index];
continue;
}
args[param.index] = param.property
.split('.')
.reduce((accumulator, property) => accumulator[property], args[param.index]);
}
}
}
return args;
}
exports.applyParamsMetadataDecorator = applyParamsMetadataDecorator;

0 comments on commit 0547364

Please sign in to comment.