Dialogflow实现:修复Chatbot响应

时间:2019-01-18 08:09:53

标签: dialogflow actions-on-google

我正在为我的最后一个项目创建一个聊天机器人。我正在使用Dialogflow。一切都很好,但是我的聊天机器人没有说“实现”中的conv.ask语句。它只是重复我使用过的相同实体。这些相同的语句将显示在Dialogflow网站上提供的Web演示和测试控制台中,而不显示在我的应用程序中。

这是实现代码

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

const Minerals_INTENT ='Mineral'
const Minerals_ENTITY ='Minerals'

const app = dialogflow()

app.intent( Minerals_INTENT , (conv) => { 
const mineral_type = conv.parameters[Minerals_ENTITY];
if(mineral_type == "Calcium")
{
     conv.ask("Sources: Green leafy vegetables, legumes, tofu, molasses, 
sardines, okra, perch, trout, Chinese cabbage, rhubarb, sesame seeds")
}
else if(mineral_type == "Phosphorus")
{
    conv.ask("Toxicity: Very rare. May result in soft tissue 
calcification. \n Sources: Legumes, nuts, seeds, whole grains, eggs, 
fish, 
buckwheat, seafood, corn, wild rice")
}
else if(mineral_type == "Potassium")
{
 conv.ask("Sources: Sweet potato, tomato, green leafy vegetables, 
carrots, 
prunes, beans, molasses, squash, fish, bananas, peaches, apricots, melon, 
potatoes, dates, raisins, mushrooms")
}
})

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

这是我的“文本或SSML响应”

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

const Minerals_INTENT ='Mineral'
const Minerals_ENTITY ='Minerals'

const app = dialogflow()

app.intent( Minerals_INTENT , (conv) => { 
const mineral_type = conv.parameters[Minerals_ENTITY];
if(mineral_type == "Calcium")
{
     conv.ask("Sources: Green leafy vegetables, legumes, tofu, molasses, 
sardines, okra, perch, trout, Chinese cabbage, rhubarb, sesame seeds")
}
else if(mineral_type == "Phosphorus")
{
    conv.ask("Toxicity: Very rare. May result in soft tissue 
calcification. \n Sources: Legumes, nuts, seeds, whole grains, eggs, 
fish, 
buckwheat, seafood, corn, wild rice")
}
else if(mineral_type == "Potassium")
{
 conv.ask("Sources: Sweet potato, tomato, green leafy vegetables, 
carrots, 
prunes, beans, molasses, squash, fish, bananas, peaches, apricots, melon, 
potatoes, dates, raisins, mushrooms")
}
})

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

这是我Android Studio的聊天机器人页面上的代码

$Minerals

[App屏幕截图] [1]

[意图,实体和测试控制台屏幕截图] [1]

$Minerals

1 个答案:

答案 0 :(得分:0)

问题是您正在使用Google Actions库来发回信息,但您的Android应用不是Action。因此,它是从响应中读取标准Dialogflow字段,而不是在“ google”有效负载部分中查找。

通常,如果您打算为Assistant以外的平台进行开发,则应使用dialogflow-fulfillment库,而不要使用Google行动,因为它可以为您的平台指定自定义有效负载