gpt4 book ai didi

javascript - 使用 Actions on Google 库集成时不显示轮播

转载 作者:行者123 更新时间:2023-11-30 14:15:06 24 4
gpt4 key购买 nike

我正在尝试显示 carousel 从 Firebase 获取数据,Card 工作正常,但显示 Carousel 不起作用但让 conv = agent.conv();始终为空。但是我按照这里的说明进行操作:Using the Actions on Google library integration: .请不要生气,我正在努力学习。谢谢

'use strict';

const functions = require('firebase-functions');
const {WebhookClient, Card} = require('dialogflow-fulfillment');
const requestLib = require('request');
const {dialogflow, Carousel}= require('actions-on-google');
const app = dialogflow({debug: true});

// Constant for image URLs
const IMG_URL_AOG = 'https://developers.google.com/actions/images/badges' +
'/XPM_BADGING_GoogleAssistant_VER.png';

// Constant for image URLs

const IMG_URL_GOOGLE_ALLO = 'https://allo.google.com/images/allo-logo.png';
const IMG_URL_GOOGLE_HOME = 'https://lh3.googleusercontent.com' +
'/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw';
const IMG_URL_GOOGLE_PIXEL = 'https://storage.googleapis.com/madebygoog/v1' +
'/Pixel/Pixel_ColorPicker/Pixel_Device_Angled_Black-720w.png';
const IMG_URL_MEDIA = 'http://storage.googleapis.com/automotive-media/album_art.jpg';
const MEDIA_SOURCE = 'http://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3';

// initialise DB connection
const admin = require('firebase-admin');

admin.initializeApp({
// credential:admin.credential.applicationDefault(),
databaseURL:'ws://test-catWorldXXXXX.com/'
});

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });

console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

function handelModel (agent){

const chosenModel = agent.parameters["toyota-models"].toLowerCase();
let conv = agent.conv();

if (chosenModel == "corolla") {

return admin.database().ref('corolla').once("value")
.then(function(snapshot) {
snapshot.forEach(function(model) {
var value = model.val();
agent.add("Nombre: " + value.nombre);
Conv shows valor NULL...
agent.add("conv " + conv);

conv.ask(new Carousel({
items: {
// Add the first item to the carousel
[SELECTION_KEY_ONE]: {
synonyms: [
'synonym of title 1',
'synonym of title 2',
'synonym of title 3',
],
title: 'Title of First Carousel Item',
description: 'This is a description of a carousel item.',
image: new Image({
url: IMG_URL_AOG,
alt: 'Image alternate text',
}),
},
// Add the second item to the carousel
[SELECTION_KEY_GOOGLE_HOME]: {
synonyms: [
'Google Home Assistant',
'Assistant on the Google Home',
],
title: 'Google Home',
description: 'Google Home is a voice-activated speaker powered by ' +
'the Google Assistant.',
image: new Image({
url: IMG_URL_GOOGLE_HOME,
alt: 'Google Home',
}),
},
// Add third item to the carousel
[SELECTION_KEY_GOOGLE_PIXEL]: {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: 'Google Pixel',
description: 'Pixel. Phone by Google.',
image: new Image({
url: IMG_URL_GOOGLE_PIXEL,
alt: 'Google Pixel',
}),
},
// Add last item of the carousel
[SELECTION_KEY_GOOGLE_ALLO]: {
title: 'Google Allo',
synonyms: [
'Allo',
],
description: 'Introducing Google Allo, a smart messaging app that ' +
'helps you say more and do more.',
image: new Image({
url: IMG_URL_GOOGLE_ALLO,
alt: 'Google Allo Logo',
}),
},
},
}));
agent.add(conv);
});
});
}
else {
return admin.database().ref('yaris').once("value")
.then(function(snapshot) {
snapshot.forEach(function(model) {
var value = model.val();
const a11yText = 'Google Assistant Bubbles';
const googleUrl = 'https://google.com';

title: value.nombre,
imageUrl: 'https://developers.google.com/actions/assistant.png',
text: 'This is the body text of a card. You can even use line\n breaks and emoji! 💁',
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);
});
});
}
}

// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('ask-models', handelModel);
agent.handleRequest(intentMap);

});

enter image description here

最佳答案

我在这个问题上找到了一些东西 https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/37#issuecomment-437036370 :

Like jorgecasar pointed out, you need to set the agent.requestSource, otherwise, agent.conv() return null

const agent = new WebhookClient({ request, response });
agent.requestSource = agent.ACTIONS_ON_GOOGLE;

then agent.conv() would not return null

关于javascript - 使用 Actions on Google 库集成时不显示轮播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53713735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com