npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

echolocate

v1.1.0

Published

Get an Echo device's physical location and timezone using the Alexa API and Geo-location.

Downloads

17

Readme

Echolocate

Echolocate is a function to help you get an Echo device's physical location and timezone using the Alexa and Geo-location API's. It's especially useful when building Alexa skills that return time information. The skill request will only give you GMT times, so you can use this library to help you figure out the timezone of your user's echo device and relay the time correctly.

Usage

In your Alexa Skill:

import echolocate from 'echolocate';

// Get the deviceId and consentToken from the Alexa Skill Request object
const deviceLocation = await echolocate(deviceId, {consentToken})

Or alternatively if you want to use the command-line for whatever reason:

echolocate --device-id "amzn1.ask.device..." --consent-token "Atza|..."

Returns:

{
  deviceId:"amzn1.ask.device....",
  countryCode: "US",
  postalCode: "11215"
  city: "New York",
  country: "United States",
  formattedAddress: "Brooklyn, NY 11215, USA",
  latitude: 40.6986772,
  longitude: -73.9859414,
  timezone:{
    dstOffset: 3600,
    rawOffset: -18000,
    timeZoneId: "America/New_York",
    timeZoneName: "Eastern Daylight Time"
  },
}

Echolocate will use the Alexa API to get the Echo device's location and timezone based on the permissions you have set for you Alexa Skill. To perform an echolocation, you must supply two pieces of information from your Skill's request: the deviceId and the consentToken. The consentToken will only be present if you request location permission in your skill. You can find more information about this on Amazon's Developer Portal

AWS Config

In order to keep the number of geolocation requests to a minimum, you can configure Echolocate to store the location information it retrieves in an AWS Dynamo DB. To do so, create a config file at config/default.js and fill in the required information.

For example:

module.exports = {
  echolocate: {
    awsConfig: {
      accessKeyId: "<AWS ACCESS KEY>",
      secretAccessKey: "<AWS SECRET ACCESS KEY>",
      region: "<AWS REGION>",
    },
    dbTableName: "<DYNAMO DB TABLE NAME>",
  }
};

Echolocate will actually use the config library under the hood so just follow that project's guidelines if you want to customize the config file.

Once set up correctly, Echolocate will store locations for a particular deviceId in the database and will retrieve that if it's available. If not, it will save the values it finds via geolocation to the DB for the next time it's retrieved. This should make subsequent location calls much faster.