Friday, February 26, 2016

alexa, tell mom i'm home

I got my Alexa for Christmas from my kids this year and had set it up to use IFTTT. You can read more about that set up here. Mostly texting recipes for notifying them when dinner is done, etc. I really hated using "unnatural" language though.

"Alexa - trigger dinner is ready."

I set up a IFTTT recipe for my daughter to notify me when she gets home from school.

"Alexa - trigger mom I'm home."

See? Unnatural.

So I've been learning how to use AWS Lambda function using an Alexa Skill event. Here's the GitHub link to the completed source code. 

Here's what I struggled the most with ...

Testing - It's not the greatest trying to debug issues.

Sometimes you'll get an invalid response and have no clue what's wrong. You can also use CloudWatch along with some strategically placed console.logs to eventually figure out what happened.

I really struggled with SNS. The function would complete successfully but the text message was never sent. What I found was because the calls are asynchronous - the context object was being marked as done before the method completed. Moving the callback inside the publish method worked great. Like this ...

sns.publish(params, function (err, data) {
            if (err) console.log(err, err.stack); // an error occurred
                 if ("good" === day)
                        speechOutput = "I'm glad to know you had a good day! " +
                        "I will inform your mom so she can raise the roof with her hands like your dad does. ";
                    else if ("bad" === day)
                        speechOutput = "I'm sorry you had a bad day. " +
                        "I will inform your mom so she can sympathize with you when she gets home. ";
                var sessionAttributes = {};
                var speechOutput = speechOutput + "Ok, the message was sent.";
                var repromptText = "";
                var shouldEndSession = true;
            buildSpeechletResponse(speechOutput, repromptText, shouldEndSession));

So now .... it's.

"Alexa, tell Mom I'm home."

This project really helped me too.  Mihai Galos was really helpful in getting me to this point - so thanks Mihai! It demonstrates a http request for Twilio, which will be really helpful for future integration with a rest api. But .... I didn't want to use Twilio - I wanted to implement SNS.

Again, check out my Github for the entire project. Already looking for my next project. Maybe adding a database entry to record the time of day she gets off the bus. :) Maybe we won't tell Holly about that part. hehe

No comments:

Post a Comment