我在Dialogflow中创建了一个聊天机器人,并尝试在this tutorial之后将用户数据添加到Firestore。即使尝试定义其他上下文或其他获取参数的方法,它也无法使用我的参数。
当我尝试打印完整的输出以捕获未定义的值(如here所述)时,Firebase仅打印“未定义”。我在这里想念什么吗?
我在Dialogflow实现Webhook上的index.js:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function getNameHandler(agent) {
let email = agent.parameters.email;
db.collection("users").add({ name: email });
agent.add(`Thank you, $email`);
}
let intentMap = new Map();
intentMap.set('Final', getNameHandler);
agent.handleRequest(intentMap);
});
package.json
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.5.0",
"firebase-admin": "^8.2.0",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.6.1"
}
}
我还发布了完整的日志,因为有人在与此相关的问题中要求他们。
Firebase日志错误:
Error: Value for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore value (found in field name).
at Object.validateUserInput (/srv/node_modules/@google-cloud/firestore/build/src/serializer.js:273:15)
at Object.validateDocumentData (/srv/node_modules/@google-cloud/firestore/build/src/write-batch.js:611:22)
at CollectionReference.add (/srv/node_modules/@google-cloud/firestore/build/src/reference.js:1765:23)
at getNameHandler (/srv/index.js:17:28)
at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:313:44)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:24:9)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
Dialogflow原始交互日志:
{
"queryText": "FACEBOOK_MEDIA",
"action": "TrabalharAqui.TrabalharAqui-custom.TrabalharAqui-custom-custom.Nome-custom.E-mail-custom.Subir1-ajustado-yes.Subir1-ajustado-yes-custom",
"parameters": {},
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
},
"lang": "pt-br"
}
],
"outputContexts": [
{
"name": "generic",
"lifespanCount": 4,
"parameters": {
"facebook_sender_id": "3142211899182443",
"person": {
"name": "Felipe"
},
"person.original": "Felipe",
"email": "email@email.com",
"email.original": "email@email.com"
}
},
{
"name": "nome-followup",
"lifespanCount": 11,
"parameters": {
"person": {
"name": "Felipe"
},
"person.original": "Felipe",
"email": "email@email.com",
"email.original": "email@email.com"
}
},
{
"name": "trabalharaqui-followup",
"lifespanCount": 4,
"parameters": {
"person": {
"name": "Felipe"
},
"person.original": "Felipe",
"email": "email@email.com",
"email.original": "email@email.com"
}
},
{
"name": "subir1-ajustado-yes-followup",
"lifespanCount": 1
},
{
"name": "trabalharaqui-custom-custom-followup",
"lifespanCount": 11,
"parameters": {
"person": {
"name": "Felipe"
},
"person.original": "Felipe",
"email": "email@email.com",
"email.original": "email@email.com"
}
},
{
"name": "e-mail-followup",
"lifespanCount": 12,
"parameters": {
"person": {
"name": "Felipe"
},
"person.original": "Felipe",
"email": "email@email.com",
"email.original": "email@email.com"
}
},
{
"name": "subir1-followup-2",
"lifespanCount": 3,
"parameters": {
"email": "email@email.com",
"email.original": "email@email.com"
}
}
],
"intent": {
"id": "96c6e1f9-1682-42c4-bda8-3e02107bef90",
"displayName": "Final",
"priority": 500000,
"webhookState": "WEBHOOK_STATE_ENABLED",
"inputContextNames": [
"Subir1-ajustado-yes-followup"
],
"events": [
"FACEBOOK_MEDIA"
],
"action": "TrabalharAqui.TrabalharAqui-custom.TrabalharAqui-custom-custom.Nome-custom.E-mail-custom.Subir1-ajustado-yes.Subir1-ajustado-yes-custom",
"messages": [
{
"text": {},
"lang": "pt-br"
}
],
"endInteraction": true,
"rootFollowupIntentId": "c4b6c438-41bf-431b-9e46-9d53bcf11d3f",
"parentFollowupIntentId": "01f5cff4-722c-476e-9520-e84224f83037"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 386,
"end_conversation": true
},
"languageCode": "pt-br",
"slotfillingMetadata": {
"allRequiredParamsPresent": true
},
"id": "635f4b23-5e81-42dc-aa33-eefdaadca254-36cd004f",
"sessionId": "56a16be0-0657-4871-84fa-14f9a8f2d524",
"timestamp": "2019-10-30T20:50:13.307Z",
"source": "agent",
"webhookStatus": {
"webhookEnabledForAgent": true,
"webhookStatus": {
"code": 13,
"message": "Webhook call failed. Error: 500 Internal Server Error."
}
},
"agentEnvironmentId": {
"agentId": "f86a3353-f332-4a58-b90a-4f2f7f1c76f5",
"cloudProjectId": "small-talk-c7def"
}
}
Stackdriver日志
Dialogflow fulfillment request : { "responseId": "635f4b23-5e81-42dc-aa33-eefdaadca254-36cd004f", "queryResult": { "queryText": "FACEBOOK_MEDIA", "action": "TrabalharAqui.TrabalharAqui-custom.TrabalharAqui-custom-custom.Nome-custom.E-mail-custom.Subir1-ajustado-yes.Subir1-ajustado-yes-custom", "parameters": { }, "allRequiredParamsPresent": true, "fulfillmentMessages": [{ "text": { "text": [""] } }], "outputContexts": [{ "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/generic", "lifespanCount": 4, "parameters": { "facebook_sender_id": "3142211899182443", "agenciaArea": "", "agenciaArea.original": "", "person": { "name": "Felipe" }, "person.original": "Felipe", "email": "email@email.com", "email.original": "email@email.com" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/nome-followup", "lifespanCount": 11, "parameters": { "person": { "name": "Felipe" }, "person.original": "Felipe", "email": "email@email.com", "email.original": "email@email.com", "agenciaArea": "", "agenciaArea.original": "" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/trabalharaqui-followup", "lifespanCount": 4, "parameters": { "agenciaArea": "", "agenciaArea.original": "", "person": { "name": "Felipe" }, "person.original": "Felipe", "email": "email@email.com", "email.original": "email@email.com" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/subir1-ajustado-yes-followup", "lifespanCount": 1 }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/trabalharaqui-custom-custom-followup", "lifespanCount": 11, "parameters": { "person": { "name": "Felipe" }, "person.original": "Felipe", "email": "email@email.com", "email.original": "email@email.com", "agenciaArea": "", "agenciaArea.original": "" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/subir1-ajustado-followup", "parameters": { "email": "email@email.com", "email.original": "email@email.com" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/e-mail-followup", "lifespanCount": 12, "parameters": { "person": { "name": "Felipe" }, "person.original": "Felipe", "email": "email@email.com", "email.original": "email@email.com", "agenciaArea": "", "agenciaArea.original": "" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/subir1-followup-2", "lifespanCount": 3, "parameters": { "email": "email@email.com", "email.original": "email@email.com" } }, { "name": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524/contexts/facebook_media" }], "intent": { "name": "projects/small-talk-c7def/agent/intents/96c6e1f9-1682-42c4-bda8-3e02107bef90", "displayName": "Final", "endInteraction": true }, "intentDetectionConfidence": 1.0, "languageCode": "pt-br" }, "originalDetectIntentRequest": { "source": "facebook", "payload": { "data": { "recipient": { "id": "120676054689749" }, "message": { "attachments": [{ "payload": { "url": "https://cdn.fbsbx.com/v/t59.2708-21/72489391_411292759506400_2547957410975186944_n.txt/bot.txt?_nc_cat\u003d108\u0026_nc_oc\u003dAQnBAGuFxa0u-W4NRK5FPH4gZdq1MwpjgQjlC-pfbSGY7UkdfyRA18aSYMUyX5tN0lTqqYPU8sW6gTg4yTwn0vgK\u0026_nc_ht\u003dcdn.fbsbx.com\u0026oh\u003db322ef1af5154b43139f0a133d2468d9\u0026oe\u003d5DBCB98C" }, "type": "file" }], "mid": "m_2ZRrlcE88CIvxNwgMAZiNRwv8VxAlOHyWofyE4wHB2fGmqMtrlfKMYv_GbDLFUDpGydFktXmGRB29BfVbwxqAg" }, "timestamp": 1.572468612843E12, "sender": { "id": "3142211899182443" } }, "source": "facebook" } }, "session": "projects/small-talk-c7def/agent/sessions/56a16be0-0657-4871-84fa-14f9a8f2d524" }
答案 0 :(得分:1)
错误消息(阅读全文):
错误:参数“ data”的值不是有效的Firestore文档。不能使用“ undefined”作为Firestore值(在字段名称中找到)。
告诉您为“名称”字段传递的值未定义。鉴于这些代码行:
let email = agent.parameters.email;
db.collection("users").add({ name: email });
断言email
未定义。因此,您将必须弄清楚为什么会这样。
答案 1 :(得分:0)
解决方案是正确使用the context和the “original” value的组合。如果您刚开始使用Dialogflow,这还不是很清楚。