Google上的操作:无法在DialogFlow实现中关闭Convo

时间:2018-09-01 18:00:20

标签: dialogflow actions-on-google

我正在使用ActionOnGoogle V2 SDK,并使用Firebase函数

我尝试过此代码...

import * as functions from 'firebase-functions';
const admin = require('firebase-admin');

const serviceAccount = require("../key/secretkey.json");

import {dialogflow, BasicCard, SimpleResponse, List, Carousel} from 'actions-on-google';


admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://dburl.com"
});

const getSomethingPromize = admin.database().ref(`/user_list/`).orderByChild('blood_group');


const app = dialogflow();
app.intent('getLocation', async (conv:any, parameters) => {
    console.log("params", parameters);

    return getSomethingPromize.equalTo(parameters.blood_group)
            .once('value')
            .then((snapshot) => {

                const childCount = snapshot.numChildren();
                let message = "";
                let singleRecord;

                switch (childCount) {

                    case 0:
                        message = `No Record`;
                        break;

                    case 1:
                        singleRecord = snapshot.val();
                        singleRecord =  singleRecord[Object.keys(singleRecord)[0]];
                        message = `1 Record`;
                        getBasicCard(conv, singleRecord);
                        break;

                    default: 
                        let myItems = {};

                        snapshot.forEach(childSnapshot => {

                            const entity = childSnapshot.val();
                            const state:any = parameters.indian_states;

                            if (entity.state.toLowerCase() !== state.toLowerCase()){                                
                                return;
                            }

                            myItems[entity.name] = {
                                synonyms: [
                                    entity.name,
                                ],
                                title: `  ${entity.name}  `,
                                description: ` Contact : ${entity.phone} ${entity.phone2}, ${entity.city}, ${entity.state}, ${entity.pincode}  `,
                            };

                        });


                        message = `Multiple Records`;


//ISSUE HERE
                        conv.close(new List({
                            title: `List Title`,
                            items: myItems,
                        }));
                }


                return getSimpleResponse(conv, parameters, message);
            });
});

function getSimpleResponse(conv, parameters, message=null){
    let displayMessage = message;

    if (!message) {
        displayMessage = `Sorry! No Record Found`;
    }
    return conv.close(new SimpleResponse({
        text: displayMessage,
        speech: displayMessage

    }));
}

function getBasicCard(conv, singleRecord){
    return conv.close(new BasicCard({
        text: `${singleRecord.blood_group}, ${singleRecord.state}`,
        subtitle: `Contact : ${singleRecord.phone} ${singleRecord.phone2}, ${singleRecord.city}, ${singleRecord.state}, ${singleRecord.pincode}, ${singleRecord.comment}  `,
        title: `${singleRecord.name}`,
        display: 'CROPPED',
    }));
}
export const fulfillment = functions.https.onRequest(app);

问题是::当我尝试通过发送丰富列表卡关闭Convo时,Convo保持打开状态。

因此,在Stackdriver上,我被发出

  

“格式错误的响应:必须设置'final_response'”

我正在引用此文档 https://developers.google.com/actions/assistant/responses#list

1 个答案:

答案 0 :(得分:1)

您只能使用SimpleResponse结束会话。根据{{​​3}},“您的最终响应必须是单个简单响应,其textToSpeech和displayText值不得超过60个字符。”