【问题标题】:Dialogflow Fulfillment: Webhook call failed. Error: 500 Internal Server ErrorDialogflow Fulfillment:Webhook 调用失败。错误:500 内部服务器错误
【发布时间】:2019-01-17 20:24:40
【问题描述】:

所以我正在尝试从 Dialogflow 创建一个关于维生素的对话。但是,我不断收到同样的错误,因此,人工智能也做出了同样的反应。所以我们想要发生的是, (用户) - 给我更多关于维生素的信息 (AI) - 当然。哪种维生素 (用户)- *这里我们指定哪种维生素,例如 - * 维生素 A。 (AI) - 然后 AI 给了我们维生素 A 的特定反应

请帮忙

这是我们正在执行的代码

const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google')

const VITAMIN_INTENT = 'Vitamin'
const VITAMINS_ENTITY = 'Vitamins'

const app = dialogflow()

app.intent(VITAMIN_INTENT, (conv) => {
    const vitamin_type = conv.parameters[VITAMINS_ENTITY].toLowerCase();
    if (vitamin_type == 'Vitamin A') {
    conv.ask("Sources: carrots, sweet potato, green leafy vegetable, squash")
    } else if (vitamin_type == 'Vitamin B') {
        conv.ask("Sources: Animal products (such as fish, poultry, meat, eggs, or dairy); Also found in fortified breakfast cereals and enriched soy or rice milk.")
    } else if (vitamin_type == 'Vitamin B1') {
        conv.ask("Sources: Sunflower seeds, asparagus, lettuce, mushrooms, black beans, navy beans, lentils, spinach, peas, pinto beans, lima beans, eggplant, Brussels sprouts, tomatoes, tuna, whole wheat, soybeans.")
    } else if (vitamin_type == 'Vitamin B2') {
        conv.ask("Sources:B2 ")
    } 
})
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

【问题讨论】:

标签: dialogflow-es actions-on-google


【解决方案1】:

错误 500 通常表示您的程序由于某种原因崩溃了,尽管不查看日志,很难确切地知道原因。

我的猜测是在部分

const vitamin_type = conv.parameters[VITAMINS_ENTITY].toLowerCase();

您没有名为“维生素”的参数。参数名称区分大小写,通常都是小写。所以conv.parameters[VITAMINS_ENTITY] 的计算结果为undefined,而undefined 没有函数.toLowerCase()

此外,您的代码中至少存在一个逻辑问题。线

const vitamin_type = conv.parameters[VITAMINS_ENTITY].toLowerCase();

确保字符串vitamin_type 是小写的。所以诸如“维生素a”之类的值。

但是当你测试这些值时,你会使用诸如

之类的比较
if (vitamin_type == 'Vitamin A') {

您将其与“维生素 A”等值进行比较。所以这些值永远不会匹配。

由于没有任何值匹配,您将退出函数而无需调用conv.ask(),这将产生错误。 (虽然不是错误 500。)

【讨论】:

    猜你喜欢
    • 2018-01-02
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多