Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const upsInterceptor={
async process(handlerInput){
let { requestEnvelope, serviceClientFactory, attributesManager} = handlerInput;
let {deviceId} = requestEnvelope.context.System.device;
const upsServiceClient = serviceClientFactory.getUpsServiceClient();
const usertimeZone = await upsServiceClient.getSystemTimeZone(deviceId);
const requestAttributes = attributesManager.getRequestAttributes();
requestAttributes.timeZone = usertimeZone;
attributesManager.setRequestAttributes(requestAttributes);
console.log(JSON.stringify(attributesManager.getRequestAttributes()));
}
};
@rmtuckerphx

This comment has been minimized.

Copy link

rmtuckerphx commented Aug 22, 2018

Great! How about a sample using Moment Timezone library that tells you the time in the timezone of the device?

@rmtuckerphx

This comment has been minimized.

Copy link

rmtuckerphx commented Aug 22, 2018

Here I go answering my own request:

// Handler

const moment = require('moment-timezone');

const requestAttributes = attributesManager.getRequestAttributes();

const now = moment.utc();
const localTime = now.tz(requestAttributes.timeZone).format('ddd, MMM D, YYYY [at] h:mma');
const speech = `Your local time is ${localTime}`;
@mlescaille

This comment has been minimized.

Copy link

mlescaille commented Aug 23, 2018

Thanks!

@darianbjohnson

This comment has been minimized.

Copy link

darianbjohnson commented Aug 24, 2018

trying to get this example to work, but getting the following error "TypeError: upsServiceClient.getSystemTimeZone is not a function". Thoughts?

@darianbjohnson

This comment has been minimized.

Copy link

darianbjohnson commented Aug 25, 2018

I forgot to upgrade to the latest version. :(

@rakolock1

This comment has been minimized.

Copy link

rakolock1 commented Sep 29, 2018

i am getting the same error that darianbjohnson got. Unfortunately, I'm not sure what I need to update or how to do it. A little help would be appreciated. Thanks!

@memodoring

This comment has been minimized.

Copy link
Owner Author

memodoring commented Nov 8, 2018

i am getting the same error that darianbjohnson got. Unfortunately, I'm not sure what I need to update or how to do it. A little help would be appreciated. Thanks!

Hey rakolock1, you need to make sure you have the latest ask-sdk in your node_modules folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.