Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serviceClientFactory was undefined #356

Closed
mehtanilay10 opened this issue Apr 21, 2018 · 10 comments
Closed

serviceClientFactory was undefined #356

mehtanilay10 opened this issue Apr 21, 2018 · 10 comments

Comments

@mehtanilay10
Copy link

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.

serviceClientFactory : this.apiClient
? new ServiceClientFactory({
apiClient : this.apiClient,
apiEndpoint : requestEnvelope.context.System.apiEndpoint,
authorizationValue : requestEnvelope.context.System.apiAccessToken,
})
: undefined,

For this, I am used withApiClient() of CustomSkillBuilder. So i am used below snippet.

exports.handler = skillBuilder
	.addRequestHandlers(...)
	.withSkillId(...)
	.withApiClient(new ApiClient())
	.lambda();

Expected Behavior

How to solve this issue? Is there anything i missed?

Current Behavior

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)

Context

Unable to obtain address of user, due to serviceClientFactory.

Your Environment

  • ASK SDK for Node.js used: 2.0
  • Operating System and version: Windows 10 v1703

Node.js and NPM Info

  • Node.js version used for development:7.2.0
  • NPM version used for development:3.10.9
@TianTXie
Copy link
Contributor

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.

@mehtanilay10
Copy link
Author

I have used v2 packages only. So what should I pass here?
I have found something like below snippet.

skillBuilder.addRequestHandlers(new Handler(this), ...this.v2RequestHandlers)
.addRequestInterceptors(new CopySessionAttributesInterceptor())
.withPersistenceAdapter(dynamoDbPersistenceAdapter)
.withApiClient(new DefaultApiClient())
.withCustomUserAgent(`${packageInfo.name}/${packageInfo.version}`)

@TianTXie
Copy link
Contributor

TianTXie commented Apr 21, 2018

@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';

@mehtanilay10
Copy link
Author

I have used only ask-sdk-core

@TianTXie
Copy link
Contributor

TianTXie commented Apr 21, 2018

If you want to use default apiClient, try

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
	.addRequestHandlers(...)
       . withApiClient(new Alexa.DefaultApiClient())
	.withSkillId(...)
	.lambda();

@mehtanilay10
Copy link
Author

@TianTXie Thanks for your help.
I have used ApiClient() instead of new Alexa.DefaultApiClient()

@ghost
Copy link

ghost commented Nov 15, 2018

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

@franklin-lobb
Copy link

@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.

@ghost
Copy link

ghost commented Nov 16, 2018

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.

@nnnayan
Copy link

nnnayan commented Dec 12, 2019

Thanks, this solution worked for me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants