I have read the document on Service client and tried to Address via it.
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/wiki/Alexa-Service-Clients
const { requestEnvelope, serviceClientFactory } = handlerInput;
const { deviceId } = requestEnvelope.context.System.device;
const deviceAddressServiceClient = serviceClientFactory.getDeviceAddressServiceClient();
const address = deviceAddressServiceClient.getFullAddress(deviceId);
console.log('Addres: ' + address);
But I got serviceClientFactory was undefined in handlerInput.
As per this below condition, I have to set ApiClient value.
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/fdf4a04c853bbe38dc6aecfe16117a07c4a27948/ask-sdk-core/lib/skill/Skill.ts#L80-L86
For this, I am used withApiClient() of CustomSkillBuilder. So i am used below snippet.
exports.handler = skillBuilder
.addRequestHandlers(...)
.withSkillId(...)
.withApiClient(new ApiClient())
.lambda();
How to solve this issue? Is there anything i missed?
Currently it generate below error:
module initialization error: ReferenceError
at Object.(/var/task/index.js:294:21)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
Unable to obtain address of user, due to serviceClientFactory.
Hi @mehtanilay10, what package do you use? If you want to use default apiClient, you can use StandardSkillBuilder which is in ask-sdk package and you don't need to set anything in StandardSkillBuilder. If you want to use your own apiClient, you can use CustomSkillBuilder which is in ask-sdk-core package. In CustomSkillBuilder, there is a withApiClient() method which allows you to set your apiClient.
I have used v2 packages only. So what should I pass here?
I have found something like below snippet.
@mehtanilay10 Are you using Standard ASK SDK Distribution or Core SDK Module Only in this link.
In your code, what do you import:
import * as Alexa from 'ask-sdk-core';
or
import * as Alexa from 'ask-sdk';
I have used only ask-sdk-core
If you want to use default apiClient, try
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(...)
. withApiClient(new Alexa.DefaultApiClient())
.withSkillId(...)
.lambda();
@TianTXie Thanks for your help.
I have used ApiClient() instead of new Alexa.DefaultApiClient()
can someone post code if you are using the standard skill builder for accessing the apiclient. I'm trying to get the timezone of the device. I need to use the standard skill builder, not the custom one because i use all the helper methods for dynamodb that comes with standard. I have yet to find an example of how to get the device time zone using standard
@dante2365 the code located here will work. When you use .standard() Skill Builder instead of the .custom() one, you don't need to include this line .withApiClient(new Alexa.DefaultApiClient()). The Standard includes it by default.
thank you @franklin-lobb. That worked. Every example I found was with the custom skill builder so when I included the .withApiClient I got the function does not exist error.
Thanks, this solution worked for me too!
Most helpful comment
If you want to use default apiClient, try