У меня есть большая программа, которая хорошо говорит в Dialogflow для домашних динамиков GA, но добавление поддержки экспресс-html делает тестовую ситуацию, показывающую, что две функции называют псевдонимами переменную. Небольшой минимальный пример показывает это с легкостью, и я хочу исправить это и понять, почему это тоже плохо.
Итак, добавьте, установите в ноль и посмотрите, как показано каждое поддерживаемое значение для переменной, котораяк сожалению два значения. как будто есть переменная HtmlCounter = 0;var SpeakerCounter = 0;
Очевидно, что желание состоит в том, что есть одно значение и т. д., а не два. Это псевдоним, «или что-то»!
Я пытался: () Создание var globals = {} и добавление псевдонима. () Изменение вложенности использования переменной, пытающейся заставить Dialogflow почувствовать, что она владеет переменной несколько больше.
'use strict';
// Me Daniel B Kolis
// dankolis@gmail.com
var versionNow = "03 Oct 2019 16:00";
// This is the troublesome variable
var aCounter = -1;
const functions = require( 'firebase-functions' );
const express = require( 'express' );
const eapp = express();
const {WebhookClient} = require( 'dialogflow-fulfillment' );
var bodyParser = require( 'body-parser' );
// Middleware
const cors = require( 'cors' ) ( { origin: true } );
eapp.use( cors );
// Import the service function and various response classes
const { dialogflow, actionssdk, Image, Table, Carousel } =
require( 'actions-on-google' );
// Dialog flow talks to humans using google assistant
const app = dialogflow();
// Three http pages via the express package
eapp.get( '/show_counter.html', (req, res) =>
{
let moreSeeable = "Counter is " + aCounter.toString();
res.send( moreSeeable );
});
eapp.get( '/reset_counter.html', (req, res) =>
{
let moreSeeable = "Acounter is this now: " + aCounter.toString() +
" but right now, set to 0";
aCounter = 0;
res.send( moreSeeable );
});
eapp.get( '/add_counter.html', (req, res) =>
{
let moreSeeable = "Acounter is this now: " + aCounter.toString() +
" but lets add one to it";
res.send( moreSeeable );
aCounter = aCounter + 1;
});
// Here we are configuring express to use body-parser as middleware
eapp.use( bodyParser.urlencoded( { extended: false } ) );
eapp.use( bodyParser.json() );
// Note: This `api` must match with `/firebase.json` rewrites rule
exports.api = functions.https.onRequest( eapp );
// Start up hint if you look at logs locally or on the cloud
console.log( "VR: " + versionNow );
console.log( "First line(s) in program, sort of. Now what ?" );
console.log( "aCounter starts at: " + aCounter );
// Create I/O object for dialogs
exports.dialogflowFirebaseFulfillment =
functions.https.onRequest((request, response) =>
{
const agent = new WebhookClient({ request, response });
// Left part is triggered by human speech, right is the
// function it calls
let intentMap = new Map();
intentMap.set( 'addone', addOne );
intentMap.set( 'questioncounter', questionCounter );
intentMap.set( 'resetcounter', resetCounter );
agent.handleRequest( intentMap );
});
// Three functions called by intents, a decode of speech spoken
function questionCounter ( agent )
{
// Computers speak this
agent.add( 'Counter is ' + aCounter.toString() );
}
function addOne( agent )
{
let rightNow = aCounter;
aCounter = aCounter + 1;
agent.add( 'Counter is now ' + rightNow.toString() +
' will be: ' + aCounter.toString() );
}
function resetCounter( agent )
{
aCounter = 0;
agent.add( 'Counter set to zero' );
}
// End of sad submission; last line of code
ЦЕЛЬ: изменить и доступ к HTML, и речь к и от речи через Dialogflowодно значение, aCounter, а не два. Надеюсь, вы понимаете это полностью!
Большое спасибо за внимание, Дэн Колис