我正在为学校开发一项Alexa技能,我的客户希望将Alexa与父母的对话存储在其中,并希望将其显示在学生的仪表板上。 如何将我所有的对话都存储到数据库中?
您可以获取并存储/保存alexa所说的内容,但不能完全获得用户对alexa技能所说的内容 。 但是您可以获得的是用户的意图(即所谓的意图)。 解决您的问题的方法是使用一些数据库并创建一个表,并在每种意图中都执行类似的操作
const HelpIntentHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent'; }, handle(handlerInput) { const speechText = 'You can say hello to me!'; *//write code to add speechText to a table against the intent name/sample utterence with date and time* return handlerInput.responseBuilder .speak(speechText) .reprompt(speechText) .withSimpleCard('Hello World', speechText) .getResponse(); }, };
您将不会获得技能用户的话语或用户所说的话。 但是,利用您从Alexa请求中获得的收益,您可以有点重新创建对话流程。
使用以下信息:
userId
将更改。 SessionEndedRequest
来检查会话何时结束,但这很干净。 intents
您可以确定用户的意图。 这将帮助您猜测用户可能说了什么。 slots
与映射的intents
结合使用,您将获得更多信息。 由于广告位值始终会传递给您,因此您可以坚持执行此操作,并知道用户在其对话中说的确切值。 使用这些信息/过滤器(如果您使用timestamp
对其进行排序),您将了解到特定/所有用户与Alexa的对话。