Things used in this project

Hardware components:
Echo
Amazon Alexa Amazon Echo
Any Alexa enabled device will work.
×1
Software apps and online services:
Screen%20shot%202015 07 20%20at%206.10.26%20pm
Amazon Web Services AWS Lambda
Dp image kit 02
Amazon Alexa Alexa Skills Kit

Code

Lambda Function for Destiny 2 CountdownPython
This is the production Lambda code for the Destiny 2 Countdown Skill
from datetime import datetime
import math
# --------------- Helpers that build all of the responses ----------------------

def build_speechlet_response(title, output, reprompt_text, should_end_session):
    return {
        'outputSpeech': {
            'type': 'PlainText',
            'text': output
        },
        'card': {
            'type': 'Simple',
            'title': title,
            'content': output
        },
        'reprompt': {
            'outputSpeech': {
                'type': 'PlainText',
                'text': reprompt_text
            }
        },
        'shouldEndSession': should_end_session
    }


def build_response(session_attributes, speechlet_response):
    return {
        'version': '1.0',
        'sessionAttributes': session_attributes,
        'response': speechlet_response
    }


# --------------- Functions that control the skill's behavior ------------------

def beta():
    session_attributes = {}
    card_title = "Countdown"
    now = datetime.today()
    target = datetime.strptime('Jul 18 2017  4:00AM', '%b %d %Y %I:%M%p')
    difference = target - now
    days = difference.days
    hours = math.floor(difference.seconds / 3600) % 24
    seconds = difference.seconds % 60
    minutes = math.floor(difference.seconds / 60) % 60
    totalDays = difference.days
    speech_output = "There are " + str(days) + " days, " + str(hours) + " hours, " + str(minutes) + " minutes, and " + str(seconds) + " seconds left until the Early Access Beta will be available on Playstation. 24 Hours later it will be avaiable on Xbox and 48 hours later after Xbox the beta will be open on both consoles. The PC beta date is still unknown."
    reprompt_text = "There are about " + str(totalDays) + " days left."
    should_end_session = True
    return build_response(session_attributes, build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session))
        
def release_countdown():
    session_attributes = {}
    card_title = "Countdown"
    now = datetime.today()
    target = datetime.strptime('Sep 6 2017  4:00AM', '%b %d %Y %I:%M%p')
    difference = target - now
    days = difference.days
    hours = math.floor(difference.seconds / 3600) % 24
    seconds = difference.seconds % 60
    minutes = math.floor(difference.seconds / 60) % 60
    totalDays = difference.days
    speech_output = "There are " + str(days) + " days, " + str(hours) + " hours, " + str(minutes) + " minutes, and " + str(seconds) + " seconds left until Destiny 2 will be released on console. PC will come out 48 days afterwards."
    reprompt_text = "There are about " + str(totalDays) + " days left."
    should_end_session = True
    return build_response(session_attributes, build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session))


def handle_session_end_request():
    card_title = "Thanks for using this skill."
    speech_output = "Thanks for using this skill. For news on new Destiny skills follow @randomrumblegen on Twitter."
    should_end_session = True
    return build_response({}, build_speechlet_response(
        card_title, speech_output, None, should_end_session))

def help():
    card_title = "Help"
    speech_output = "This skill provides a countdown until important Destiny 2 events. You can ask how long is left until the release or the beta."
    should_end_session = False
    return build_response({}, build_speechlet_response(
        card_title, speech_output, speech_output, should_end_session))
        



# --------------- Events ------------------

def on_session_started():
    session_attributes = {}

def on_launch(launch_request, session):
    print(release_countdown())
    return release_countdown()

def on_intent(intent_request, session):
    intent = intent_request['request']['intent']
    intent_name = intent_request['request']['intent']['name']

    if intent_name == "ReleaseCountdownIntent":
        return release_countdown()
    elif intent_name == "BetaCountdownIntent":
        return beta()
    elif intent_name == "AMAZON.HelpIntent":
        return help()
    elif intent_name == "AMAZON.CancelIntent" or intent_name == "AMAZON.StopIntent":
        return handle_session_end_request()
    else:
        raise ValueError("Invalid intent")


def on_session_ended(session_ended_request, session):
    """ Called when the user ends the session.

    Is not called when the skill returns should_end_session=true
    """
    return  handle_session_end_request()
    print("on_session_ended requestId=" + session_ended_request['requestId'] +
          ", sessionId=" + session['sessionId'])
    # add cleanup logic here


# --------------- Main handler ------------------

def lambda_handler(event, context):
    #if event['session']['new']:
     #   return on_launch(event['request'], event['session'])
    #if event['request']['type'] == "LaunchRequest":
     #   return on_launch(event['request'], event['session'])
    if event['request']['type'] == "IntentRequest":
        return on_intent(event, event['session'])
    elif event['request']['type'] == "SessionEndedRequest":
        return on_session_ended(event['request'], event['session'])
    else:
        return release_countdown()
Skill Builder Code for Destiny 2 Countdown SkillJSON
This code is pasted into the new skill builder portal under the code section.
{
  "intents": [
    {
      "name": "AMAZON.CancelIntent",
      "samples": []
    },
    {
      "name": "AMAZON.HelpIntent",
      "samples": [
        "What can you do",
        "Help me",
        "What are your commands",
        "What functions do you have",
        "What can you tell me"
      ]
    },
    {
      "name": "AMAZON.StopIntent",
      "samples": [
        "Don't do that",
        "That's wrong"
      ]
    },
    {
      "name": "BetaCountdownIntent",
      "samples": [
        "How long until the beta",
        "how long until the destiny two beta",
        "when is the beta",
        "time until the beta",
        "how long is left on the beta",
        "beta",
        "How many days until the beta"
      ],
      "slots": []
    },
    {
      "name": "ReleaseCountdownIntent",
      "samples": [
        "How long is left",
        "How long",
        "Time left",
        "Countdown",
        "How long until Destiny two",
        "Destiny two countdown",
        "Destiny two",
        "Destiny two release",
        "Countdown for Destiny two release",
        "Time until release",
        "Release countdown"
      ],
      "slots": []
    }
  ]
}

Credits

Big engram isns8txm7l
Elvis Wolcott

Self-taught app developer and hardware developer, currently working on making the Random Rumble Generator and other voice based solutions

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Iron-Rich Foods!
Easy
  • 49
  • 3

A necessary skill for all people with iron deficiencies. It's always hard to find foods that are rich in iron. Until now. Just ask Alexa!

Movie Quotes Trivia
Easy
  • 18
  • 1

Full instructions

Test your knowledge of great movies by matching five famous movies quotes. It will be great fun activities among famaly and friends.

Wise Quotes
Easy
  • 133
  • 3

Full instructions

More than 100 wise quotes to empower you everyday.

Wildlife Facts Skill
Easy
  • 53
  • 2

Learn more about wildlife animals with more than 200 interesting facts with this Alexa skill.

Compost Helper Alexa Skill
Easy
  • 152
  • 3

Use Alexa to find out if a household item can be added to your compost.

Ferrari Facts
Easy
  • 266
  • 4

Full instructions

learn about the most expensive cars in the world with Ferrari Facts you you will know some interesting facts that you probably didn't hear a

Add projectSign up / Login