Actions on Google: Unable to Close Convo in DialogFlow Fulfillment

Deadly 提交于 2020-01-06 09:05:33

问题


I am on ActionOnGoogle V2 SDK, and using Firebase Functions

I tried this code...

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);

Issue is : When i Tried to Close Convo by Sending Rich List Card, the Convo remains Open.

Hence, on Stackdriver i am Issued with

"MalformedResponse: 'final_response' must be set"

I am Referencing this Docs https://developers.google.com/actions/assistant/responses#list


回答1:


You can only close the conversation with a SimpleResponse. According to the docs, "Your final response must be a single simple response with a 60-character limit on its textToSpeech and displayText values".



来源:https://stackoverflow.com/questions/52130823/actions-on-google-unable-to-close-convo-in-dialogflow-fulfillment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!