Alexa, What Do You Want From Me?

Invention is a struggle. It begins innocently enough.

I invented a game called Guess the Sum that involves at least two players. Each player thinks of a number within a given range, say from 0 to 10. Then the players take turns guessing the sum of all of the secret numbers. In a given round, each guess has to be unique. The player who is closest to the sum wins. It is possible to tie, with one player higher and the other lower than the sum by the same amount.

So let’s say you and I are playing. I might think of the number 8, and you might think of the number 2. You can go first. For your guess, you should say a number from 0 to 20. That’s the full range of possible sums of two numbers between 0 and 10. Make sense?

Say you guess 14. That means you think (or hope) my number is 6. Based on your guess and the fact that I know my number is 2, there is no way the sum can be 14. So I might guess 12, the highest possible sum. When we reveal our secret numbers, we learn that the sum is 10. I win.

For the next round, we would rotate who guesses first. That would keep things fair in terms of any first-guesser advantage.

Picking or changing your number after the other person guesses is a way to cheat. To avoid “accidents” where a player fails to think of a number first, having a way to secretly record the numbers makes sense. Slips of paper could do the trick.

Or a computer might help with that. I have considered hosting a Guess-the-Sum app, where people could sit around the same virtual table and guess their way through 10 or 20 rounds, chatting with each other on the side and having a grand ole time.

If you can trust your opponent, Guess the Sum can be played entirely by voice. That’s how I played with my daughter for years.

Coincidentally, last week the AWS Loft in San Francisco hosted Alexa Day. Amazon sponsors developer days to encourage people to write code that runs in their cloud and on their devices. For me, it’s usually a good chance to learn and see what is possible.

We were told to think of a useful skill to program. Instead, I decided to teach Alexa how to play Guess the Sum. That way, avid players would always have a willing opponent. I would make Alexa trustworthy by keeping the player’s secret number out of the guessing algorithm. Seemed like a good idea.

echo-dot-2937627_640

Echo Dot from Amazon

So I dusted off my Echo Dot, fired up my coding environment (VS Code), and made my first attempt at programming an Alexa skill. Three days of effort later, I am still trying to get the coding life cycle to work.

To give you a sense of the problem, imagine that someone gives you a jigsaw puzzle for your birthday. The box sports an eye-catching picture, and you anticipate the joy of putting it together. You clear off a table and dump out the pieces.

After about 10 minutes of flipping and sorting, you get the feeling that something is not quite right. While some of the pieces look like the picture on the box, some look like they are part of a different picture. A fair number of pieces are blank.

After 30 minutes, it’s pretty clear that you are dealing with two puzzles, along with a handful of mystery pieces that don’t seem to fit anywhere. You throw up your hands and walk away.

That’s kind of the feeling I’ve gotten so far with Alexa skill development. While the “getting started” tutorials are fine as far as they go, I have not quite figured out the right incantation to get beyond the first few steps on a skill of my own.

Apparently there are a few ways to go about this. Each starts out simply enough. One approach starts at the developer console.

  1. Create the skill in the developer console.
  2. Give the skill the invocation name: “guess the sum.”
  3. Add an intent. The skill needs at least one thing it can do to be activated for testing. In my case, I have two intents: learn the rules, and play the game.
  4. Create a Lambda function to handles intent requests. I am using Node 8.10, the latest Node that is available on Lambda.
  5. While creating the function, assign or create a role to the function, something that authorizes Lambda execution and write access to CloudWatch (for logging). Keeping things secure is a good idea.
  6. One last step is to connect the skill to the Lambda function and vice versa. Skill IDs and ARNs are copied back and forth, and that should do it.

Even the simplest Alexa skill handler uses modules, so writing JavaScript in the console is not going to work, as far as I know. That pushes me into my local IDE. Here’s where things start to unravel along this path. Nevertheless, I make my code changes, zip them up and upload using the AWS console.

Testing the Lambda function directly works fine. When I switch to the Test window of the developer console, nothing happens. Technically, something happens. A chat-like message bubble wags an in-progress dot at me, floating back and forth indefinitely while nothing is happening.

Alexa, what gives?

Also, the fact that I have to manually upload the zip whenever I change my code is going to be a problem. Better to solve that right away before I waste a ton of time.

If you know about dramatic irony, your literary antennae should be tingling. The phrase “before I waste a ton of time” is a classic bit of developer irony that means the developer is about to waste a ton of time figuring out how not to waste time.

That’s where my Friday went. And then my Saturday. I was heartily “saving time” by “getting things right.” In the end, nothing I tried worked entirely.

I quickly switched to an alternate path for programming a skill, which relies on the Ask command-line interface (ask-cli). This handy little tool seems to have everything a wily developer would need to create and deploy a skill. Super.

  1. Installed as a global NPM package, “ask” runs in a command prompt or terminal window. No mouse clicks required.
  2. You start with ask init, to set up the environment, including developer credentials. This command takes you through a login screen in the browser where you authenticate as ‘default.’ Now, is that my root user or my authorized developer profile? Or is it my separate developer login? Just keep moving.
  3. Then ask new creates a new project for your skill. If you know what you want to name your skill, the --skill-name parameter let’s you dictate it. Same goes for the name of the lambda function. Otherwise, the tool is happy to supply defaults.
  4. At this point, you should be able to issue ask deploy and have everything created for you in the cloud.

For me, this is where things get a bit slippery. Maybe it has to do with how much I have changed by the time I deploy.

Sometimes ask-cli tells me I does not have permission. Sometimes it tries setting up a Lambda function in the wrong zone (us-east-1 when I am clearly working in us-west-2) and complains that Lambda needs to be in the same zone as the skill. Sure, ask-cli, go ahead.

The documentation is plentiful and looks sufficient until you want to know why things aren’t working.

Alexa, stop teasing me.

Not one to give up too quickly, I pivoted to a hybrid approach.

  1. Start a skill in the developer console, going as far as setting up and connecting the Lambda function.
  2. On the command line, use the handy ask clone command to make a local copy of the skill model and associate code.
  3. Set up my handler with the required ask modules.
  4. Try ask deploy to update the code in the cloud.

At this point, something else goes wrong. It seems that the differences between what’s in the cloud and what’s on my computer are too much for Ask-cli, which mumbles something vague and gives up.

A few more pivots left me with a pile of false starts. I suppose I learned some things, but the one thing I didn’t figure out yet is how to set up the project environment so that it works from beginning to end.

Alexa, please work.

Despite my initial frustration, I believe this can work. After all, people have coded hundreds of thousands of skills to date for everything from daily horoscopes to auto-piloting submarines. Okay, I might have made that up. But from the hype, you would think that everyone is coding Alexa apps for anything you can imagine doing with your voice.

Oh, and now Amazon has new Alexa-powered devices that have screens. What the what?!? I thought the point was to interact with your ears and voice. Apparently vision is still one of the important senses.

Okay, deep breath. Just ignore that for now. I have to code Guess the Sum for voice only. That path is complicated enough.

Once my skill is working and tested by me, I’ll need to submit it for beta testing so I can load it into my little Dot and share it with my kids. After all, this is all about impressing my kids.

And once my kids are impressed, I need to apply to share my skill with the world. I think I can get money if people play it enough. And with some enhancements, I might be able to include in-skill purchases.

Yeah, that’s right. I can be making real money with my Alexa skills. Probably enough to fuel an entire business.

Now, where was I? Oh yeah, saving time setting up my development environment. This is gonna be good, I can tell.

Alexa, show me the money.

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s