这是一个相当广泛的问题,因此我将尝试关注使用 Dialogflow 聊天机器人启动应用程序的具体细节。如果您还没有在 Pepper 上运行的 QiSDK Dialogflow 聊天机器人,这里有一个很好的教程,详细介绍了整个过程。如果您已经实现了聊天机器人,我希望以下步骤足够通用,您可以将其应用于您的项目。
这个聊天机器人只返回文本结果供 Pepper 说,因此您需要进行一些修改以允许启动特定操作。
修改 DialogflowDataSource
本教程此页面上的第 2 步详细介绍了如何向 Dialogflow 发送文本查询并获取文本响应。您需要修改它以返回完整的响应对象(包括操作),而不仅仅是文本。定义一个名为detectIntentFullResponse
例如的新函数。
// Change this
return response.queryResult.fulfillmentText
// to this
return response.queryResult
修改 DialogflowChatbot
本页的第 2 步展示了如何实现 QiSDK 聊天机器人。添加一些逻辑来检查replyTo
函数中的操作。
var response: DetectIntentResponse? = null
// ...
response = dataSource.detectIntentFullResponse(input, dialogflowSessionId, language)
// ...
return if (reponse.action != null) {
StandardReplyReaction(
ActionReaction(qiContext, response), ReplyPriority.NORMAL
)
} else if (reponse.answer != null) {
StandardReplyReaction(
SimpleSayReaction(qiContext, reponse.answer), ReplyPriority.NORMAL
)
} else {
StandardReplyReaction(
EmptyChatbotReaction(qiContext), ReplyPriority.FALLBACK
)
}
现在创建一个新类,ActionReaction
. 请注意,以下内容不完整,但应作为如何确定要运行的操作的示例(如果您需要其他操作)。查看SimpleSayReaction
更多实现细节。
class ActionReaction internal constructor(context: QiContext, private val response: DetectIntentResponse) :
BaseChatbotReaction(context) {
override fun runWith(speechEngine: SpeechEngine) {
if (response.action == "launch-app") {
var appID = response.parameters.app.toString()
// launch app at appID
}
}
}
至于启动应用程序,其他问题中详细介绍了各种方法,例如此处。可以扩展此方法以执行其他操作,例如运行或检索在线数据。