actions-on-google-nodejs
actions-on-google-nodejs copied to clipboard
Request: add a DialogflowApp.getLang() method
To write internationalized apps, it is useful to know the language of the request. If the request comes from Google Actions, we have a user
in the originalRequest
field (originalRequest.data.user
) and a corresponding locale
field (originalRequest.data.user.locale
). We can easily get the locale of the user with the method AssistantApp.getUserLocale()
.
However, if the request comes directly from the DialogFlow console (using the try it now field) there is no user from where we can get the locale. It is still possible to get the language of the request using the lang
field of the request. Indeed, I can access the lang
field using app.body_.lang
but I think that it would be "cleaner" to access this field through a dedicated getLang()
method.
note: I would rather call this method lang()
, but to stay consistent with the other methods of DialogflowApp
(getIntent
, getArgument
, ...) I suggest to call this method getLang
Can you please assign me this issue...Also please explain in brief what to do?
@Canain the original issue is a bit outdated, but the spirit of the issue applies.
If I have an intent handler:
app.intent('Default Welcome Intent', conv => {
conv.ask(`User language is ${conv.user.locale}`)
})
The user's locale is passed through when using the AoG simulator.
{
...
"user": {
"locale": "en-US",
"userVerificationStatus": "VERIFIED"
},
}
However, if I use the Dialogflow simulator instead, the JSON request is from a different pathway and is not passed to conv.user.locale
.
{
"responseId": "70e4b740-589e-4ff7-9ddc-b268e78c6bba-2a4c0c5e",
"queryResult": {
"queryText": "hello",
"action": "input.welcome",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Good day! What can I do for you today?",
"fulfillmentMessages": [
{
"text": {
"text": [
"Good day! What can I do for you today?"
]
}
}
],
"intent": {
"name": "projects/user-lang/agent/intents/a31bf099-88ea-4167-8858-9a04549a553a",
"displayName": "Default Welcome Intent"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
},
"originalDetectIntentRequest": {
"payload": {}
},
"session": "projects/user-lang/agent/sessions/218f7fc6-b9da-7d2c-63f8-75ebea3e8835"
}
The goal of this issue is to have at the very least Dialogflow's language passed through to conv.user.locale
if it is not defined already.