Reputation: 4736
I am using actions-on-google ApiAiAssistant node.js library with API.ai for designing my chatbot.
I have created a German API.ai Agent specifically for it. So, I need to get the locale value from the request to webhook to know which locale the request is coming from.
I have seen a method something like ApiAiAssistant.getLocale to get the locale information from the request but I am not able to find the specific one from the documentation.
Is the method deprecated? And how can I get the locale information from API.ai webhook request?
Upvotes: 1
Views: 490
Reputation: 50701
You're probably looking for the getUserLocale()
method. https://developers.google.com/actions/reference/nodejs/AssistantApp#getUserLocale
For example:
const app = new ApiAiApp({request, response});
const locale = app.getUserLocale();
It returns the language/locale combination (such as "en-AU").
If you're just using the JSON object and not the API, you can find the value at originalRequest.data.user.locale
. This is the same value returned by the method.
If you just want a non-standard language field that is returned by API.AI, you can use the lang
field. This isn't available through the API, just by reading the JSON directly, and only contains language information - not locale information. On the other hand, lang
is available if you're using it for multiple platforms, not just Actions on Google. (But if you're using it for other platforms - you probably don't want to be using the actions-on-google node.js library.)
Upvotes: 3