I'm building a simple Guess Who skill game for Alexa. I have two intents right now: GenderIntent and HairColorIntent.
GenderIntent has a custom slot to handle gender and related synonyms such as mapping "boy" and "man" to "Male". This is working great. It returns a resolution within the slot. Exactly what I need.
HairColorIntent has a predefined Amazon slot, AMAZON.Color. This is not working great as it never returns a resolution regardless of the color supplied.
Here is my model for GenderIntent and HairColorIntent:
{
"name": "GenderIntent",
"samples": [
"are you a {Gender}"
],
"slots": [
{
"name": "Gender",
"type": "GENDER_TYPES",
"samples": []
}
]
},
{
"name": "HairColorIntent",
"samples": [
"is your hair {HairColor}",
"do you have {HairColor} hair"
],
"slots": [
{
"name": "HairColor",
"type": "AMAZON.Color"
}
]
}
GenderIntent returns the following slot WITH resolutions:
{
"Gender": {
"name": "Gender",
"value": "male",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.2ed972f4-1c5a-4cc1-8fd7-3f440f5b8968.GENDER_TYPES",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Male",
"id": "63889cfb9d3cbe05d1bd2be5cc9953fd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
HairColorIntent returns the following WITHOUT resolutions:
{
"HairColor": {
"name": "HairColor",
"value": "brown",
"confirmationStatus": "NONE",
"source": "USER"
}
}
I'd like HairColorIntent's HairColor slot to return the resolution. What am I doing wrong?
Resolution is only returned if you use synonyms in your slot type.
Not exactly sure how you handle it in your code, for example Node.js would be:
handlerInput.requestEnvelope.request.intent.slots.Gender.resolutions.resolutionPerAuthority[0].values[0].value.name
If you do not use synonyms (for example for the HairColor slot), you can get the value simply by handlerInput.requestEnvelope.request.intent.slots.HairColor.value
Working with predefined slot types this should work well with your code. If you want custom slot types to also return resolution whether you actually use synonyms or not, you can always just simply give the value as a synonym and it should return the full resolution tree.
Hope that answered your question.
My published skill can be invoked by "Alexa, open Mighty Righty," but it won't work if a user says "Alexa, ask Mighty Righty who is right, me or my husband," how to do that?
https://www.amazon.com/dp/B07SGBR24G/
This is the link to the working published skill.
#------------------------------Part1--------------------------------
# In this part we define a list that contains the player names, and
# a dictionary with player biographies
Player_LIST = ["me or my wife", "me or my husband", "me or you"]
Player_BIOGRAPHY = {"me or my wife": ["She is. Do as she says, and you'll be OK.", "You", "Of course, your wife", "No doubt, it's you"],
"me or my husband": ["He is", "You are right", "He is not right", "Your husband. He is always right."],
"me or you": ["me", "You are, ... I mean... you are wrong, of course", "of course me", "It's me, don't you know that, my friend?", "you yourself, what do you think? Of course it's me", "I always know who is right, me or not me, so, it's me", "what do you think? I am Mighty Righty, so I am RIGHT"]}
#------------------------------Part2--------------------------------
# Here we define our Lambda function and configure what it does when
# an event with a Launch, Intent and Session End Requests are sent. # The Lambda function responses to an event carrying a particular
# Request are handled by functions such as on_launch(event) and
# intent_scheme(event).
def lambda_handler(event, context):
if event['session']['new']:
on_start()
if event['request']['type'] == "LaunchRequest":
return on_launch(event)
elif event['request']['type'] == "IntentRequest":
return intent_scheme(event)
elif event['request']['type'] == "SessionEndedRequest":
return on_end()
#------------------------------Part3--------------------------------
# Here we define the Request handler functions
def on_start():
print("Session Started.")
def on_launch(event):
onlunch_MSG = "Hi, start with the word. Me. For example: who is right, me or my husband?"
reprompt_MSG = "you can say, who is right, me or my wife?"
card_TEXT = "Who is right, me or... ?."
card_TITLE = "Choose your question."
return output_json_builder_with_reprompt_and_card(onlunch_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)
def on_end():
print("Session Ended.")
#-----------------------------Part3.1-------------------------------
# The intent_scheme(event) function handles the Intent Request.
# Since we have a few different intents in our skill, we need to
# configure what this function will do upon receiving a particular
# intent. This can be done by introducing the functions which handle
# each of the intents.
def intent_scheme(event):
intent_name = event['request']['intent']['name']
if intent_name == "playerBio":
return player_bio(event)
elif intent_name in ["AMAZON.NoIntent", "AMAZON.StopIntent", "AMAZON.CancelIntent"]:
return stop_the_skill(event)
elif intent_name == "AMAZON.HelpIntent":
return assistance(event)
elif intent_name == "AMAZON.FallbackIntent":
return fallback_call(event)
#---------------------------Part3.1.1-------------------------------
# Here we define the intent handler functions
import random # this can be at the top of the file too
def player_bio(event):
name=event['request']['intent']['slots']['player']['value']
player_list_lower=[w.lower() for w in Player_LIST]
if name.lower() in player_list_lower:
reprompt_MSG = "Try to say something like. who is right me or them"
card_TEXT = "You've picked " + name.lower()
card_TITLE = "You've picked " + name.lower()
return output_json_builder_with_reprompt_and_card(random.choice(Player_BIOGRAPHY[name.lower()]), card_TEXT, card_TITLE, reprompt_MSG, False)
else:
wrongname_MSG = "Some questions may not yet be present in my database. Try to rephrase your sentence."
reprompt_MSG = "For example, who is right, me or my wife?"
card_TEXT = "Use the full question."
card_TITLE = "Wrong question."
return output_json_builder_with_reprompt_and_card(wrongname_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)
def stop_the_skill(event):
stop_MSG = "Bye for now and feel free to ask mighty righty who is right"
reprompt_MSG = "next time just tell me. Open Mighty righty"
card_TEXT = "Bye."
card_TITLE = "Bye Bye."
return output_json_builder_with_reprompt_and_card(stop_MSG, card_TEXT, card_TITLE, reprompt_MSG, True)
def assistance(event):
assistance_MSG = "start with the word. Me."
reprompt_MSG = "For example, who is right me or him"
card_TEXT = "You've asked for help."
card_TITLE = "Help"
return output_json_builder_with_reprompt_and_card(assistance_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)
def fallback_call(event):
fallback_MSG = "Try to say, for example, who is right, me or him?"
reprompt_MSG = "Certain answers may not yet be in my database. Use personal pronouns, for example: me, or her, me, or him, me, or them. They can cover pretty much everybody"
card_TEXT = "You've asked a wrong question."
card_TITLE = "Wrong question."
return output_json_builder_with_reprompt_and_card(fallback_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)
#------------------------------Part4--------------------------------
# The response of our Lambda function should be in a json format.
# That is why in this part of the code we define the functions which
# will build the response in the requested format. These functions
# are used by both the intent handlers and the request handlers to
# build the output.
def plain_text_builder(text_body):
text_dict = {}
text_dict['type'] = 'PlainText'
text_dict['text'] = text_body
return text_dict
def reprompt_builder(repr_text):
reprompt_dict = {}
reprompt_dict['outputSpeech'] = plain_text_builder(repr_text)
return reprompt_dict
def card_builder(c_text, c_title):
card_dict = {}
card_dict['type'] = "Simple"
card_dict['title'] = c_title
card_dict['content'] = c_text
return card_dict
def response_field_builder_with_reprompt_and_card(outputSpeach_text, card_text, card_title, reprompt_text, value):
speech_dict = {}
speech_dict['outputSpeech'] = plain_text_builder(outputSpeach_text)
speech_dict['card'] = card_builder(card_text, card_title)
speech_dict['reprompt'] = reprompt_builder(reprompt_text)
speech_dict['shouldEndSession'] = value
return speech_dict
def output_json_builder_with_reprompt_and_card(outputSpeach_text, card_text, card_title, reprompt_text, value):
response_dict = {}
response_dict['version'] = '1.0'
response_dict['response'] = response_field_builder_with_reprompt_and_card(outputSpeach_text, card_text, card_title, reprompt_text, value)
return response_dict
This Is the JSON file. It might be slightly different, because I tried to shorten the file as much as possible for the purpose of this question, but it doesn't matter because the main components here - are present in the current working app:
{
"interactionModel": {
"languageModel": {
"invocationName": "mighty righty",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "playerBio",
"slots": [
{
"name": "player",
"type": "playerNames"
}
],
"samples": [
"who is right {player}"
]
},
{
"name": "AMAZON.NoIntent",
"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
}
],
"types": [
{
"name": "playerNames",
"values": [
{
"name": {
"value": "me or you",
"synonyms": [
"you or me"
]
}
},
{
"name": {
"value": "me or them",
"synonyms": [
"I am or they are",
"I am or them",
"I am or they",
"I or they are",
"I or them",
"me or they are",
"me or they"
]
}
},
{
"name": {
"value": "me or him",
"synonyms": [
"I or him",
"I or he",
"I'm or he is",
"I'm or him",
"me or he is",
"me or he's"
]
}
},
{
"name": {
"value": "me or her",
"synonyms": [
"I'm or she's",
"I am or she is",
"I'm or she",
"I'm or her",
"me or she is",
"me or she"
]
}
},
{
"name": {
"value": "me or my wife",
"synonyms": [
"me or my wifey"
]
}
},
{
"name": {
"value": "me or my husband",
"synonyms": [
"my husband"
]
}
}
]
}
]
}
}
}
By the way, as you can see there are synonyms, but Alexa won't use them. Very good example:
Alexa, who is right, me or you? (works)
Alexa, who is right, you or me? (won't work)
But in the JSON it says:
"value": "me or you",
"synonyms": [
"you or me"
]
But I think for that I need to ask another question...
I went to Alexa Developer Console, Test tab, wrote:
"alexa, ask mighty righty who is right, me or my husband"
She said:
Hmm, I don't know that.
Nothing in JSON input and output windows, but I found this line in device logs:
[21:11:35:676] - Event: Text.TextMessage
I clicked there and it opened this (if this is what is needed):
{
"event": {
"header": {
"namespace": "Text",
"name": "TextMessage",
"messageId": "messageId",
"dialogRequestId": "numbers-and-letters-separated-with-sashes-that-i-deletedxxxxxxxxxxxxxxxxxxxxxxxxxxx506"
},
"payload": {
"textMessage": "alexa, ask mighty righty who is right, me or my husband"
}
},
"context": [
{
"header": {
"namespace": "System",
"name": "SettingsState",
"payloadVersion": "1"
},
"payload": {
"settings": [
{
"key": "com.amazon.alexa.characteristics.viewport.experiences",
"value": "[{\"arcMinuteWidth\":\"246\",\"arcMinuteHeight\":\"144\",\"canRotate\":\"false\",\"canResize\":\"false\"}]"
},
{
"key": "com.amazon.alexa.characteristics.viewport.shape",
"value": "RECTANGLE"
},
{
"key": "com.amazon.alexa.characteristics.viewport.pixelWidth",
"value": "1024"
},
{
"key": "com.amazon.alexa.characteristics.viewport.pixelHeight",
"value": "600"
},
{
"key": "com.amazon.alexa.characteristics.viewport.dpi",
"value": "160"
},
{
"key": "com.amazon.alexa.characteristics.viewport.currentPixelWidth",
"value": "1024"
},
{
"key": "com.amazon.alexa.characteristics.viewport.currentPixelHeight",
"value": "600"
},
{
"key": "com.amazon.alexa.characteristics.viewport.touch",
"value": "[\"SINGLE\"]"
},
{
"key": "com.amazon.alexa.characteristics.viewport.video",
"value": "{\"codecs\": [\"H_264_42\",\"H_264_41\"]}"
}
]
}
},
{
"header": {
"namespace": "SpeechSynthesizer",
"name": "SpeechState"
},
"payload": {
"token": "amzn1.as-ct.v1.ThirdPartySdkSpeechlet#ACRI#ValidatedSpeakDirective_amzn1.ask.skill.some-kind-of-numbers-and-letters-here-i-deleted-it_they-are-seperated-with-dashes-and-1-underscore-in-the-middlexxxxxxxxxxxxxxxxxxxxxxxx",
"offsetInMilliseconds": 1000,
"playerActivity": "FINISHED"
}
},
{
"header": {
"namespace": "AudioPlayer",
"name": "PlaybackState"
},
"payload": {
"token": "",
"offsetInMilliseconds": 0,
"playerActivity": "IDLE"
}
},
{
"header": {
"namespace": "Alerts",
"name": "AlertsState"
},
"payload": {
"activeAlerts": [],
"allAlerts": []
}
},
{
"header": {
"namespace": "AudioFocusManager",
"name": "AudioFocusState"
},
"payload": {
"dialog": {
"component": "SpeechSynthesizer",
"idleTimeInMilliseconds": 0
}
}
}
]
}
After that the next log
[21:11:36:703] - Directive: SkillDebugger.CaptureDebuggingInfo
It says
{
"header": {
"namespace": "SkillDebugger",
"name": "CaptureDebuggingInfo",
"messageId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx38"
},
"payload": {
"skillId": null,
"timestamp": "2019-06-02T01:11:34.189Z",
"dialogRequestId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx506",
"skillRequestId": null,
"type": "ConsideredIntents",
"content": {
"intents": [
{
"name": "<IntentForDifferentSkill>",
"confirmationStatus": null,
"slots": null
},
{
"name": "<IntentForDifferentSkill>",
"confirmationStatus": null,
"slots": null
},
{
"name": "<IntentForDifferentSkill>",
"confirmationStatus": null,
"slots": null
}
]
}
}
}
the next one [21:11:36:932] - Directive: SpeechSynthesizer.Speak:
{
"header": {
"namespace": "SpeechSynthesizer",
"name": "Speak",
"messageId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"dialogRequestId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx506",
"keys": {
"isBlocking": true,
"channel": "audio"
}
},
"payload": {
"caption": "Hmm, I don't know that.",
"url": "https://tinytts.amazon.com/path to file here/resource.mp3",
"format": "AUDIO_MPEG",
"token": "amzn1.as-ct.v1.Domain:Global:Fallback#ACRI#DeviceTTSRendererV4_xxxxxxxxx5c",
"ssml": "<speak><prosody volume=\"x-loud\">Hmm, I don't know that.</prosody><metadata><promptMetadata><promptId>NotUnderstood</promptId><namespace>SmartDJ.MusicQA</namespace><locale>en_US</locale><overrideId>default</overrideId><variant>2017_Variant 5</variant><condition/><weight>1</weight><stageVersion>Adm-xxxxxxxxxxxxxx</stageVersion></promptMetadata></metadata></speak>"
}
}
and a couple of more of these logs and that's it, that's what I found.
Expected result:
Alexa, ask Mighty Righty who is right, me or my wife?
your wife
(or another random response from Player_BIOGRAPHY "me or my wife")
Actual result:
Alexa, open Mighty Righty.
Hi, you can say ......
Who is right, me or my wife?
your wife
(or another random response from Player_BIOGRAPHY "me or my wife")
As you can see, the way to get to the response is much longer (depending on Mighty Righty's welcome response)
Please, help! (I am not a coder, I just followed a tutorial)
This error message of "Hmm, I don't know that" is delivered when Alexa cannot understand the input outside of a skill, and so does not recognize what you are asking or what skill to use. So it shouldn't be an error with the slots or intents.
When Alexa captures voice input, it does not insert any punctuation, and the punctuation such as commas seem to break Alexa's ability to understand the input.
So when using the Alexa Console test chat, do not write any punctuation into the text input.
And when testing with voice, pronounce your input clearly and double check your logs to view how Alexa interpretted the voice. The more you use your skill, the better Alexa should learn to capture the key words correctly.
I have been working on a Mongo database for a while. The database has some visits that have this form:
[
{
"isPaid": false,
"_id": "5c12bc3dcea46f9d3658ca98",
"clientId": "5c117f2d1d6b9f9182182ae4",
"came_by": "Twitter Ad",
"reason": "Some reason",
"doctor_services": "Some service",
"doctor": "Dr. Michael",
"service": "Special service",
"payments": [
{
"date": "2018-12-13T21:23:05.424Z",
"_id": "5c12cdb9b236c59e75fe8190",
"sum": 345,
"currency": "$",
"note": "First Payment"
},
{
"date": "2018-12-13T21:23:07.954Z",
"_id": "5c12cdbbb236c59e75fe8191",
"sum": 100,
"currency": "$",
"note": "Second payment"
},
{
"date": "2018-12-13T21:23:16.767Z",
"_id": "5c12cdc4b236c59e75fe8192",
"sum": 5,
"currency": "$",
"note": "Third Payment"
}
],
"price": 500,
"createdAt": "2018-12-13T20:08:29.425Z",
"updatedAt": "2018-12-13T21:42:21.559Z",
}
]
I need to find some query to update some field of a single payment based on the _id of the visit and _id of the payment that is inside of nested array. Also when you update a payment's sum to some number so that the sum of all payments is greater than or equal to price the field isPaid is automatically updated to true.
I have tried some queries in mongoose to achieve the first part but none of them seem to work:
let paymentId = req.params.paymentId;
let updatedFields = req.body;
Visit.update(
{ "payments._id": paymentId },
{
$set: {
"visits.$": updatedFields
}
}
).exec((err, visit) => {
if (err) {
return res.status(500).send("Couldn't update payment");
}
return res.status(200).send("Updated payment");
});
As for the second part of the question I haven't really come up with anything so I would appreciate at least giving some direction on how to approach it.
Ex.
"docs": [
{
"id": "f37914",
"index_id": "some_index",
"field_1": [
{
"Some value",
"boost": 20.
}
]
},
]
If 'field_1' is matched, then boost by corresponding 'boost' field.
Boost what? the document? the specific field? you can do any of them.
Anyway the way to do it is to user Function Queries:
https://lucene.apache.org/solr/guide/6_6/function-queries.html#FunctionQueries-AvailableFunctions
For example if you want to boost the document (and assuming if the value doesn't match then the score is 0) then you can do something like that:
q:_val_:"if(query($q1), field(boost), 0)"&q1=field_1:"Some Value"
_val_ is just a hook into Solr function query, query returns true if q1 matches, field is a simple function that just return the value of the field it self and if allows us to join the two together.
So what I ended up doing is using lucence payloads and solr 6.6 new DelimitedPayloadTokenFilter feature.
First I created a terms field with the following configuration:
{
"add-field-type": {
"name": "terms",
"stored": "true",
"class": "solr.TextField",
"positionIncrementGap": "100",
"indexAnalyzer": {
"tokenizer": {
"class": "solr.KeywordTokenizerFactory"
},
"filters": [
{
"class": "solr.LowerCaseFilterFactory"
},
{
"class": "solr.DelimitedPayloadTokenFilterFactory",
"encoder": "float",
"delimiter": "|"
}
]
},
"queryAnalyzer": {
"tokenizer": {
"class": "solr.KeywordTokenizerFactory"
},
"filters": [
{
"class": "solr.LowerCaseFilterFactory"
},
{
"class": "solr.SynonymGraphFilterFactory",
"ignoreCase": "true",
"expand": "false",
"tokenizerFactory": "solr.KeywordTokenizerFactory",
"synonyms": "synonyms.txt"
}
]
}
},
"add-field" : {
"name":"terms",
"type":"terms",
"stored": "true",
"multiValued": "true"
}
}
I indexed my documents likes so:
[
{
"id" : "1",
"terms" : [
"some term|10.0",
"another term|60.0"
]
}
,
{
"id" : "2",
"terms" : [
"some term|11.0",
"another term|21.0"
]
}
]
I used solr's functional query support to query for a match on terms and grab the attached boost payload and apply it to the relevancy score:
/solr/payloads/select?indent=on&wt=json&q={!payload_score%20f=ai_terms_wtih_synm_3%20v=$payload_term%20func=max}&fl=id,score&payload_term=some+term
I have 2 intents in 2 different states.
TriviaState.AnswerIntent and StartState.ChooseQuizIntent.
Both intents accept a required slot type of AMAZON.Number
{
"name": "AnswerIntent",
"slots": [
{
"name": "answernum",
"type": "AMAZON.NUMBER",
"samples": [
"number {answernum}",
"answer number {answernum}",
"{answernum}",
"answer {answernum}"
]
}
],
"samples": [
"number {answernum}",
"answer {answernum}",
"{answernum}",
"answer number {answernum}"
]
},
{
"name": "ChooseQuizIntent",
"slots": [
{
"name": "quiznumber",
"type": "AMAZON.NUMBER",
"samples": [
"quiz {quiznumber}",
"{quiznumber}",
"quiz number {quiznumber}",
"{quiznumber} please",
"number {quiznumber}",
"number {quiznumber} please"
]
}
],
"samples": [
"{quiznumber}",
"quiz number {quiznumber}",
"number {quiznumber}",
"I'd like to play number {quiznumber}",
"{quiznumber} please",
"number {quiznumber} please",
"quiz {quiznumber}"
]
},
When in StartState, if the user says 'number 2', StartState.ChooseQuizIntent is called correctly. However, if the user says '2', alexa maps this to the TriviaState.AnswerIntent which results in StartState.unhandled being called.
Conversely, when in the TriviaState, if the user says '2', TriviaState.AnswerIntent is correctly called but if the user says 'number 2', alexa maps it to StartState.ChooseQuizIntent which results in TriviaState.unhandled being called.
I realise both slots are receiving identical inputs from alexa's point of view but I thought that the states would be respected which they clearly are not.