这是一个相当广泛的问题,因此我将尝试重点关注使用 Dialogflow 聊天机器人启动应用程序的具体细节。如果您还没有在 Pepper 上运行的 QiSDK Dialogflow 聊天机器人,有一个很好的教程 here 详细介绍了整个过程。如果您已经实现了聊天机器人,我希望以下步骤足够通用,您可以将其应用于您的项目。
此聊天机器人只返回文本结果供 Pepper 说,因此您需要进行一些修改以允许启动特定操作。
修改 DialogflowDataSource
本教程this page 的第 2 步详细介绍了如何向 Dialogflow 发送文本查询并获得文本响应。您需要修改它以返回完整的响应对象(包括操作),而不仅仅是文本。例如,定义一个名为 detectIntentFullResponse 的新函数。
// Change this
return response.queryResult.fulfillmentText
// to this
return response.queryResult
修改 DialogflowChatbot
this page 的第 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
}
}
}
关于启动应用程序,各种方法在其他问题中详述,例如here。可以将此方法扩展为执行其他操作,例如运行或检索在线数据。