├── .DS_Store ├── Localization ├── .DS_Store ├── UK │ ├── controller.py │ └── voice.py ├── Canada │ ├── controller.py │ └── voice.py ├── India │ ├── controller.py │ └── voice.py └── Australia │ ├── controller.py │ └── voice.py ├── Voice_assets ├── .DS_Store ├── intent_schema.json └── sample_utterances.txt ├── Screenshots ├── IMG_0546.PNG ├── depression ai.png ├── architecturediagram2.png └── depression_ai_logo_small.png ├── Dockerfile ├── LICENSE ├── requirements.txt ├── Privacy Policy ├── README.md ├── controller.py └── voice.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/.DS_Store -------------------------------------------------------------------------------- /Localization/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/Localization/.DS_Store -------------------------------------------------------------------------------- /Voice_assets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/Voice_assets/.DS_Store -------------------------------------------------------------------------------- /Screenshots/IMG_0546.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/Screenshots/IMG_0546.PNG -------------------------------------------------------------------------------- /Screenshots/depression ai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/Screenshots/depression ai.png -------------------------------------------------------------------------------- /Screenshots/architecturediagram2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/Screenshots/architecturediagram2.png -------------------------------------------------------------------------------- /Screenshots/depression_ai_logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jflick58/DepressionAI/HEAD/Screenshots/depression_ai_logo_small.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | # Dockerfile 3 | # Using the official Python 3.6 image 4 | FROM python:3.6 5 | # Set the Work Directory 6 | WORKDIR /usr/src 7 | # Copy over the requirements.txt file 8 | COPY ./requirements.txt /usr/src/requirements.txt 9 | # Install the project's dependencies 10 | RUN pip install -r requirements.txt 11 | # Copy the project codes into the Work Directory 12 | COPY . /usr/src/app 13 | # Expose port so that it's accessible to external connections 14 | EXPOSE 5000 15 | # Run the Flask-ASK application 16 | CMD ["python", "./voice.py"] 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Justin Flick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | alabaster==0.7.12 2 | aniso8601==4.1.0 3 | argcomplete==1.9.4 4 | asn1crypto==0.24.0 5 | awscli==1.16.99 6 | Babel==2.6.0 7 | base58==1.0.3 8 | boto3==1.9.89 9 | botocore==1.12.89 10 | certifi==2018.11.29 11 | cffi==1.11.5 12 | cfn-flip==1.1.0.post1 13 | chardet==3.0.4 14 | click==7.0 15 | colorama==0.4.1 16 | decorator==4.3.2 17 | docutils==0.14 18 | durationpy==0.5 19 | Flask==1.0.2 20 | Flask-Ask==0.9.8 21 | future==0.17.1 22 | geocoder==1.38.1 23 | gunicorn==19.9.0 24 | hjson==3.0.1 25 | idna==2.8 26 | imagesize==1.1.0 27 | itsdangerous==1.1.0 28 | Jinja2==2.10 29 | jmespath==0.9.3 30 | kappa==0.7.0 31 | lambda-packages==0.20.0 32 | MarkupSafe==1.1.0 33 | placebo==0.8.2 34 | pyasn1==0.4.5 35 | pycparser==2.19 36 | Pygments==2.3.1 37 | pyOpenSSL==19.0.0 38 | python-dateutil==2.8.0 39 | python-slugify==2.0.1 40 | pytz==2018.9 41 | PyYAML==4.2b4 42 | ratelim==0.1.6 43 | requests==2.21.0 44 | rsa==4.0 45 | s3transfer==0.2.0 46 | six==1.12.0 47 | snowballstemmer==1.2.1 48 | Sphinx==1.8.4 49 | sphinxcontrib-websupport==1.1.0 50 | toml==0.10.0 51 | tqdm==4.30.0 52 | troposphere==2.4.2 53 | Unidecode==1.0.23 54 | urllib3==1.24.1 55 | Werkzeug==0.14.1 56 | wsgi-request-logger==0.4.6 57 | zappa==0.47.1 58 | -------------------------------------------------------------------------------- /Voice_assets/intent_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "intents": [ 3 | { 4 | "intent": "AMAZON.StopIntent" 5 | }, 6 | { 7 | "intent": "AMAZON.CancelIntent" 8 | }, 9 | { 10 | "intent": "AMAZON.HelpIntent" 11 | }, 12 | { 13 | "intent": "AMAZON.NoIntent" 14 | }, 15 | { 16 | "intent": "AMAZON.YesIntent" 17 | }, 18 | { 19 | "intent": "AMAZON.PreviousIntent" 20 | }, 21 | { 22 | "intent": "AMAZON.StartOverIntent" 23 | }, 24 | { 25 | "intent": "PositiveFeeling" 26 | }, 27 | { 28 | "intent": "NegativeFeeling" 29 | }, 30 | { 31 | "intent": "BedYes" 32 | }, 33 | { 34 | "intent": "BedNo" 35 | }, 36 | { 37 | "intent": "AteYes" 38 | }, 39 | { 40 | "intent": "AteNo" 41 | }, 42 | { 43 | "intent": "ShowerYes" 44 | }, 45 | { 46 | "intent": "ShowerNo" 47 | }, 48 | { 49 | "intent": "DressedYes" 50 | }, 51 | { 52 | "intent": "OutsideYes" 53 | }, 54 | { 55 | "intent": "StartReport" 56 | }, 57 | { 58 | "intent": "OutsideNo" 59 | }, 60 | { 61 | "intent": "SuggestIdea" 62 | }, 63 | { 64 | "intent": "HotLine" 65 | }, 66 | { 67 | "intent": "FindTherapist" 68 | }, 69 | { 70 | "intent": "Name", 71 | "slots":[ 72 | { 73 | "name": "person_name", 74 | "type": "AMAZON.Person" 75 | } 76 | ] 77 | }, 78 | { 79 | "intent": "Email", 80 | "slots":[ 81 | { 82 | "name": "email_address", 83 | "type": "AMAZON.LITERAL" 84 | } 85 | ] 86 | } 87 | ] 88 | } -------------------------------------------------------------------------------- /Privacy Policy: -------------------------------------------------------------------------------- 1 | This privacy policy discloses the privacy practices for: 2 | 3 | DepressionAI Alexa Skill 4 | 5 | 6 | 7 | This privacy policy applies solely to information collected by this software. 8 | 9 | It will notify you of the following: 10 | 11 | What personally identifiable information is collected from you through the web site, how it is used and with whom it may be shared. 12 | 13 | 14 | What choices are available to you regarding the use of your data. 15 | 16 | 17 | The security procedures in place to protect the misuse of your information. 18 | 19 | 20 | How you can correct any inaccuracies in the information. 21 | 22 | 23 | Information Collection, Use, and Sharing 24 | We are the sole owners of the information collected by this skill. We only have access to/collect information that you voluntarily give us via the use of this skill or other direct contact from you. We will not sell or rent this information to anyone. 25 | 26 | We will use your information to respond to you within the skill session. We will not share your information with any third party outside of our organization, other than as necessary to fulfill your request, e.g. with Amazon. 27 | 28 | Your Access to and Control Over Information 29 | You may opt out of any future interactions from us at any time. You can do the following at any time by de-listing the Alexa skill from all of your devices. 30 | 31 | Security 32 | We take precautions to protect your information. When you submit sensitive information via the Alexa service, your information is protected both online and offline. 33 | 34 | While we use encryption to protect sensitive information transmitted online, we also protect your information offline. Only employees who need the information to perform a specific job (for example, billing or customer service) are granted access to personally identifiable information. The computers/servers in which we store personally identifiable information are kept in a secure environment. 35 | 36 | Updates 37 | Our Privacy Policy may change from time to time and all updates will be posted on this page. 38 | 39 | If you feel that we are not abiding by this privacy policy, you should contact us immediately via Github. 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![Alexa Skill Cards](https://github.com/Jflick58/DepressionAI/blob/master/Screenshots/depression%20ai.png) 3 | 4 | VALLEY HACKATHON 2018 WINNER!!! (https://valleyhackathon.com/teams) Alexa skill for people suffering with depression. 5 | 6 | Now available in the Alexa skills store in US, UK, Canada, India, and Australia. Google Home coming soon. 7 | 8 | # Description 9 | According to Psychology Today, 71% of people who make their bed in the morning report feeling happy. This was the inspiration behind DepressionAI. The aim behind this skill is to encourage people to perform daily activities that become very difficult when one is depressed. The skill detects positive and negative moods. If the user is having a bad day, it asks them a series of questions about what they have done that day (e.g. "Have you gotten out of bed?") and if they haven't, it encourages them to do so. 10 | 11 | This tool does not provide medical advice, and is for informational and educational purposes only, and is not a substitute for professional medical advice, treatment or diagnosis. Call your doctor to receive medical advice. If you think you may have a medical emergency, please dial your local emergency response phone number. 12 | 13 | # Features 14 | - Mood evaluation by a highly empathetic Alexa bot 15 | - Suicidal intention detection and prevention attempt 16 | - Location-based therapy reccomendations 17 | - Suggestions for small activites to improve the user's mood 18 | - Displays informative cards in the Alexa app 19 | 20 | # Sample Phrases 21 | 22 | - "Alexa, check on me." 23 | - "I feel down." 24 | - "I haven't got out of bed today." 25 | - "Help me feel better." 26 | - "Help me find a therapist" 27 | 28 | # Screenshot 29 | 30 | ![Alexa Skill Cards](https://github.com/Jflick58/DepressionAI/blob/master/Screenshots/IMG_0546.PNG) 31 | 32 | # Architecture 33 | ![Architecture Diagram](https://github.com/Jflick58/DepressionAI/blob/master/Screenshots/architecturediagram2.png) 34 | 35 | # Roadmap 36 | - Add unittests 37 | - Add docs 38 | - Add reporting feature 39 | - Port to Google Home 40 | 41 | # Contributing 42 | Feel free to fork and add a pull request. I welcome all contributions to this open-source project. I've added a Dockerfile and a virtual environment. 43 | 44 | # Media 45 | 46 | - Featured on Python Bytes Episode 74 https://pythonbytes.fm/episodes/show/74/contributing-to-open-source-effectively 47 | -------------------------------------------------------------------------------- /Localization/UK/controller.py: -------------------------------------------------------------------------------- 1 | import random 2 | import requests 3 | from flask_ask import context 4 | 5 | def get_alexa_location(): 6 | """This functions gets the location of the User's Alexa device, if they have granted location permissions. """ 7 | URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \ 8 | "/address".format(context.System.device.deviceId) 9 | TOKEN = context.System.user.permissions.consentToken 10 | HEADER = {'Accept': 'application/json', 11 | 'Authorization': 'Bearer {}'.format(TOKEN)} 12 | r = requests.get(URL, headers=HEADER) 13 | if r.status_code == 200: 14 | alexa_location = r.json() 15 | address = "{} {}".format(alexa_location["addressLine1"], 16 | alexa_location["city"]) 17 | return address 18 | 19 | def welcome(): 20 | """This function generates welcome messages that voice.py functions use to welcome the user.""" 21 | greetings = [ 22 | 'Hi,', 23 | 'Hello,', 24 | 'Good day,', 25 | 'Hola,', 26 | 'Howdy,', 27 | ] 28 | 29 | inquires = [ 30 | "How's it going?", 31 | "How are you doing?", 32 | "How are you feeling today?", 33 | "How are you feeling?", 34 | "How are you?", 35 | "How are you doing today?", 36 | "How is your day going?", 37 | "How have you been?", 38 | "How have you been feeling?", 39 | "How have you been today?", 40 | "How have you been feeling today?" 41 | ] 42 | 43 | welcome = ((random.choice(greetings)) + " " + (random.choice(inquires))) 44 | 45 | print(welcome) 46 | 47 | return (welcome) 48 | 49 | def re(): 50 | """This generates the re-prompt phrases that the skill uses if a user has not responded. """ 51 | reprompts = [ 52 | 'Are you still there?', 53 | 'Did you leave?', 54 | 'Did you still want me to check in on you?', 55 | 'Hello?', 56 | 'Are you there?' 57 | ] 58 | 59 | help_message = "Say 'help' if you need assistance" 60 | print((random.choice(reprompts)) + " " + (help_message)) 61 | return ((random.choice(reprompts)) + " " + (help_message)) 62 | 63 | def condolences(): 64 | """This function generates the condolences used by the voice.py functions when a user responds with something negative""" 65 | condolences = [ 66 | "I'm sorry to hear that.", 67 | "I'm sorry you aren't feeling good.", 68 | "I'm so sorry you feel like that.", 69 | "I'm sorry, it's going to get better.", 70 | "Well that's not ideal.", 71 | "That's too bad", 72 | "Your emotions are important during this time, and I’m happy to help you shoulder them.", 73 | "I promise it gets better. ", 74 | "I'm sorry, but I am here for you." 75 | ] 76 | print(random.choice(condolences)) 77 | return (random.choice(condolences)) 78 | 79 | def ideas(): 80 | 81 | """This is the function that generates the idea for mood improvement that is offered by various voice.py functions""" 82 | 83 | ideas = [ 84 | "Go for a walk.", 85 | "Complete one chore.", 86 | "Play your favorite video game.", 87 | "Play with your pet.", 88 | "Watch a movie.", 89 | "Look at pictures from your last vacation.", 90 | "Put on a fancy outfit.", 91 | "Go thrifting.", 92 | "Work on your hobby.", 93 | "Go to the gym.", 94 | "Exercise.", 95 | "Do 10 push-ups.", 96 | "Wear a funky hat.", 97 | "Cook a delicious meal.", 98 | "Go window shopping.", 99 | "Do some Yoga.", 100 | "Put on 'Staying Alive' by the Bee Gees and dance!", 101 | "Repair something around your house.", 102 | "Watch a funny Youtube video.", 103 | "Go for a bike ride.", 104 | "Doodle.", 105 | "Paint a picture.", 106 | "Call a friend and hang out.", 107 | "Go to your favorite coffee shop.", 108 | "Go for a scenic drive.", 109 | "Get a new haircut.", 110 | "Read Reddit.", 111 | "Listen to your favorite music.", 112 | "Go fishing.", 113 | "Gaze at the starts.", 114 | "Meditate.", 115 | "Vist a museum.", 116 | "Watch a video of baby pugs.", 117 | "Do a puzzle.", 118 | "Re-arrange the furniture in a room in your house.", 119 | "Clean your house.", 120 | "Do laundry.", 121 | "Eat chocolate cake.", 122 | "Make a to-do list for this week.", 123 | "Prep your lunch for tomorrow.", 124 | "Look in a mirror and tell yourself that you are awesome.", 125 | ] 126 | 127 | return (random.choice(ideas)) 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Localization/Canada/controller.py: -------------------------------------------------------------------------------- 1 | import random 2 | import requests 3 | from flask_ask import context 4 | 5 | def get_alexa_location(): 6 | """This functions gets the location of the User's Alexa device, if they have granted location permissions. """ 7 | URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \ 8 | "/address".format(context.System.device.deviceId) 9 | TOKEN = context.System.user.permissions.consentToken 10 | HEADER = {'Accept': 'application/json', 11 | 'Authorization': 'Bearer {}'.format(TOKEN)} 12 | r = requests.get(URL, headers=HEADER) 13 | if r.status_code == 200: 14 | alexa_location = r.json() 15 | address = "{} {}".format(alexa_location["addressLine1"], 16 | alexa_location["city"]) 17 | return address 18 | 19 | def welcome(): 20 | """This function generates welcome messages that voice.py functions use to welcome the user.""" 21 | greetings = [ 22 | 'Hi,', 23 | 'Hello,', 24 | 'Good day,', 25 | 'Hola,', 26 | 'Howdy,', 27 | ] 28 | 29 | inquires = [ 30 | "How's it going?", 31 | "How are you doing?", 32 | "How are you feeling today?", 33 | "How are you feeling?", 34 | "How are you?", 35 | "How are you doing today?", 36 | "How is your day going?", 37 | "How have you been?", 38 | "How have you been feeling?", 39 | "How have you been today?", 40 | "How have you been feeling today?" 41 | ] 42 | 43 | welcome = ((random.choice(greetings)) + " " + (random.choice(inquires))) 44 | 45 | print(welcome) 46 | 47 | return (welcome) 48 | 49 | def re(): 50 | """This generates the re-prompt phrases that the skill uses if a user has not responded. """ 51 | reprompts = [ 52 | 'Are you still there?', 53 | 'Did you leave?', 54 | 'Did you still want me to check in on you?', 55 | 'Hello?', 56 | 'Are you there?' 57 | ] 58 | 59 | help_message = "Say 'help' if you need assistance" 60 | print((random.choice(reprompts)) + " " + (help_message)) 61 | return ((random.choice(reprompts)) + " " + (help_message)) 62 | 63 | def condolences(): 64 | """This function generates the condolences used by the voice.py functions when a user responds with something negative""" 65 | condolences = [ 66 | "I'm sorry to hear that.", 67 | "I'm sorry you aren't feeling good.", 68 | "I'm so sorry you feel like that.", 69 | "I'm sorry, it's going to get better.", 70 | "Well that's not ideal.", 71 | "That's too bad", 72 | "Your emotions are important during this time, and I’m happy to help you shoulder them.", 73 | "I promise it gets better. ", 74 | "I'm sorry, but I am here for you." 75 | ] 76 | print(random.choice(condolences)) 77 | return (random.choice(condolences)) 78 | 79 | def ideas(): 80 | 81 | """This is the function that generates the idea for mood improvement that is offered by various voice.py functions""" 82 | 83 | ideas = [ 84 | "Go for a walk.", 85 | "Complete one chore.", 86 | "Play your favorite video game.", 87 | "Play with your pet.", 88 | "Watch a movie.", 89 | "Look at pictures from your last vacation.", 90 | "Put on a fancy outfit.", 91 | "Go thrifting.", 92 | "Work on your hobby.", 93 | "Go to the gym.", 94 | "Exercise.", 95 | "Do 10 push-ups.", 96 | "Wear a funky hat.", 97 | "Cook a delicious meal.", 98 | "Go window shopping.", 99 | "Do some Yoga.", 100 | "Put on 'Staying Alive' by the Bee Gees and dance!", 101 | "Repair something around your house.", 102 | "Watch a funny Youtube video.", 103 | "Go for a bike ride.", 104 | "Doodle.", 105 | "Paint a picture.", 106 | "Call a friend and hang out.", 107 | "Go to your favorite coffee shop.", 108 | "Go for a scenic drive.", 109 | "Get a new haircut.", 110 | "Read Reddit.", 111 | "Listen to your favorite music.", 112 | "Go fishing.", 113 | "Gaze at the starts.", 114 | "Meditate.", 115 | "Vist a museum.", 116 | "Watch a video of baby pugs.", 117 | "Do a puzzle.", 118 | "Re-arrange the furniture in a room in your house.", 119 | "Clean your house.", 120 | "Do laundry.", 121 | "Eat chocolate cake.", 122 | "Make a to-do list for this week.", 123 | "Prep your lunch for tomorrow.", 124 | "Look in a mirror and tell yourself that you are awesome.", 125 | ] 126 | 127 | return (random.choice(ideas)) 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Localization/India/controller.py: -------------------------------------------------------------------------------- 1 | import random 2 | import requests 3 | from flask_ask import context 4 | 5 | def get_alexa_location(): 6 | """This functions gets the location of the User's Alexa device, if they have granted location permissions. """ 7 | URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \ 8 | "/address".format(context.System.device.deviceId) 9 | TOKEN = context.System.user.permissions.consentToken 10 | HEADER = {'Accept': 'application/json', 11 | 'Authorization': 'Bearer {}'.format(TOKEN)} 12 | r = requests.get(URL, headers=HEADER) 13 | if r.status_code == 200: 14 | alexa_location = r.json() 15 | address = "{} {}".format(alexa_location["addressLine1"], 16 | alexa_location["city"]) 17 | return address 18 | 19 | def welcome(): 20 | """This function generates welcome messages that voice.py functions use to welcome the user.""" 21 | greetings = [ 22 | 'Hi,', 23 | 'Hello,', 24 | 'Good day,', 25 | 'Hola,', 26 | 'Howdy,', 27 | ] 28 | 29 | inquires = [ 30 | "How's it going?", 31 | "How are you doing?", 32 | "How are you feeling today?", 33 | "How are you feeling?", 34 | "How are you?", 35 | "How are you doing today?", 36 | "How is your day going?", 37 | "How have you been?", 38 | "How have you been feeling?", 39 | "How have you been today?", 40 | "How have you been feeling today?" 41 | ] 42 | 43 | welcome = ((random.choice(greetings)) + " " + (random.choice(inquires))) 44 | 45 | print(welcome) 46 | 47 | return (welcome) 48 | 49 | def re(): 50 | """This generates the re-prompt phrases that the skill uses if a user has not responded. """ 51 | reprompts = [ 52 | 'Are you still there?', 53 | 'Did you leave?', 54 | 'Did you still want me to check in on you?', 55 | 'Hello?', 56 | 'Are you there?' 57 | ] 58 | 59 | help_message = "Say 'help' if you need assistance" 60 | print((random.choice(reprompts)) + " " + (help_message)) 61 | return ((random.choice(reprompts)) + " " + (help_message)) 62 | 63 | def condolences(): 64 | """This function generates the condolences used by the voice.py functions when a user responds with something negative""" 65 | condolences = [ 66 | "I'm sorry to hear that.", 67 | "I'm sorry you aren't feeling good.", 68 | "I'm so sorry you feel like that.", 69 | "I'm sorry, it's going to get better.", 70 | "Well that's not ideal.", 71 | "That's too bad", 72 | "Your emotions are important during this time, and I’m happy to help you shoulder them.", 73 | "I promise it gets better. ", 74 | "I'm sorry, but I am here for you." 75 | ] 76 | print(random.choice(condolences)) 77 | return (random.choice(condolences)) 78 | 79 | def ideas(): 80 | 81 | """This is the function that generates the idea for mood improvement that is offered by various voice.py functions""" 82 | 83 | ideas = [ 84 | "Go for a walk.", 85 | "Complete one chore.", 86 | "Play your favorite video game.", 87 | "Play with your pet.", 88 | "Watch a movie.", 89 | "Look at pictures from your last vacation.", 90 | "Put on a fancy outfit.", 91 | "Go thrifting.", 92 | "Work on your hobby.", 93 | "Go to the gym.", 94 | "Exercise.", 95 | "Do 10 push-ups.", 96 | "Wear a funky hat.", 97 | "Cook a delicious meal.", 98 | "Go window shopping.", 99 | "Do some Yoga.", 100 | "Put on 'Staying Alive' by the Bee Gees and dance!", 101 | "Repair something around your house.", 102 | "Watch a funny Youtube video.", 103 | "Go for a bike ride.", 104 | "Doodle.", 105 | "Paint a picture.", 106 | "Call a friend and hang out.", 107 | "Go to your favorite coffee shop.", 108 | "Go for a scenic drive.", 109 | "Get a new haircut.", 110 | "Read Reddit.", 111 | "Listen to your favorite music.", 112 | "Go fishing.", 113 | "Gaze at the starts.", 114 | "Meditate.", 115 | "Vist a museum.", 116 | "Watch a video of baby pugs.", 117 | "Do a puzzle.", 118 | "Re-arrange the furniture in a room in your house.", 119 | "Clean your house.", 120 | "Do laundry.", 121 | "Eat chocolate cake.", 122 | "Make a to-do list for this week.", 123 | "Prep your lunch for tomorrow.", 124 | "Look in a mirror and tell yourself that you are awesome.", 125 | ] 126 | 127 | return (random.choice(ideas)) 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Localization/Australia/controller.py: -------------------------------------------------------------------------------- 1 | import random 2 | import requests 3 | from flask_ask import context 4 | 5 | def get_alexa_location(): 6 | """This functions gets the location of the User's Alexa device, if they have granted location permissions. """ 7 | URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \ 8 | "/address".format(context.System.device.deviceId) 9 | TOKEN = context.System.user.permissions.consentToken 10 | HEADER = {'Accept': 'application/json', 11 | 'Authorization': 'Bearer {}'.format(TOKEN)} 12 | r = requests.get(URL, headers=HEADER) 13 | if r.status_code == 200: 14 | alexa_location = r.json() 15 | address = "{} {}".format(alexa_location["addressLine1"], 16 | alexa_location["city"]) 17 | return address 18 | 19 | def welcome(): 20 | """This function generates welcome messages that voice.py functions use to welcome the user.""" 21 | greetings = [ 22 | 'Hi,', 23 | 'Hello,', 24 | 'Good day,', 25 | 'Hola,', 26 | 'Howdy,', 27 | ] 28 | 29 | inquires = [ 30 | "How's it going?", 31 | "How are you doing?", 32 | "How are you feeling today?", 33 | "How are you feeling?", 34 | "How are you?", 35 | "How are you doing today?", 36 | "How is your day going?", 37 | "How have you been?", 38 | "How have you been feeling?", 39 | "How have you been today?", 40 | "How have you been feeling today?" 41 | ] 42 | 43 | welcome = ((random.choice(greetings)) + " " + (random.choice(inquires))) 44 | 45 | print(welcome) 46 | 47 | return (welcome) 48 | 49 | def re(): 50 | """This generates the re-prompt phrases that the skill uses if a user has not responded. """ 51 | reprompts = [ 52 | 'Are you still there?', 53 | 'Did you leave?', 54 | 'Did you still want me to check in on you?', 55 | 'Hello?', 56 | 'Are you there?' 57 | ] 58 | 59 | help_message = "Say 'help' if you need assistance" 60 | print((random.choice(reprompts)) + " " + (help_message)) 61 | return ((random.choice(reprompts)) + " " + (help_message)) 62 | 63 | def condolences(): 64 | """This function generates the condolences used by the voice.py functions when a user responds with something negative""" 65 | condolences = [ 66 | "I'm sorry to hear that.", 67 | "I'm sorry you aren't feeling good.", 68 | "I'm so sorry you feel like that.", 69 | "I'm sorry, it's going to get better.", 70 | "Well that's not ideal.", 71 | "That's too bad", 72 | "Your emotions are important during this time, and I’m happy to help you shoulder them.", 73 | "I promise it gets better. ", 74 | "I'm sorry, but I am here for you." 75 | ] 76 | print(random.choice(condolences)) 77 | return (random.choice(condolences)) 78 | 79 | def ideas(): 80 | 81 | """This is the function that generates the idea for mood improvement that is offered by various voice.py functions""" 82 | 83 | ideas = [ 84 | "Go for a walk.", 85 | "Complete one chore.", 86 | "Play your favorite video game.", 87 | "Play with your pet.", 88 | "Watch a movie.", 89 | "Look at pictures from your last vacation.", 90 | "Put on a fancy outfit.", 91 | "Go thrifting.", 92 | "Work on your hobby.", 93 | "Go to the gym.", 94 | "Exercise.", 95 | "Do 10 push-ups.", 96 | "Wear a funky hat.", 97 | "Cook a delicious meal.", 98 | "Go window shopping.", 99 | "Do some Yoga.", 100 | "Put on 'Staying Alive' by the Bee Gees and dance!", 101 | "Repair something around your house.", 102 | "Watch a funny Youtube video.", 103 | "Go for a bike ride.", 104 | "Doodle.", 105 | "Paint a picture.", 106 | "Call a friend and hang out.", 107 | "Go to your favorite coffee shop.", 108 | "Go for a scenic drive.", 109 | "Get a new haircut.", 110 | "Read Reddit.", 111 | "Listen to your favorite music.", 112 | "Go fishing.", 113 | "Gaze at the starts.", 114 | "Meditate.", 115 | "Vist a museum.", 116 | "Watch a video of baby pugs.", 117 | "Do a puzzle.", 118 | "Re-arrange the furniture in a room in your house.", 119 | "Clean your house.", 120 | "Do laundry.", 121 | "Eat chocolate cake.", 122 | "Make a to-do list for this week.", 123 | "Prep your lunch for tomorrow.", 124 | "Look in a mirror and tell yourself that you are awesome.", 125 | ] 126 | 127 | return (random.choice(ideas)) 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /controller.py: -------------------------------------------------------------------------------- 1 | import random 2 | import requests 3 | import logging 4 | import os 5 | from flask_ask import context 6 | 7 | logging.getLogger('flask_ask').setLevel(logging.DEBUG) 8 | 9 | def get_alexa_location(): 10 | """This functions gets the location of the User's Alexa device, if they have granted location permissions. """ 11 | URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \ 12 | "/address".format(context.System.device.deviceId) 13 | TOKEN = context.System.user.permissions.consentToken 14 | HEADER = {'Accept': 'application/json', 15 | 'Authorization': 'Bearer {}'.format(TOKEN)} 16 | r = requests.get(URL, headers=HEADER, verify=False) 17 | try: 18 | #if r.status_code == 200: 19 | alexa_location = r.json() 20 | logging.info(r.json()) 21 | address = "{} {}".format(alexa_location["addressLine1"], 22 | alexa_location["city"]) 23 | except: 24 | logging.error('COULD NOT LOCATION FROM API') 25 | logging.debug(r.json()) 26 | address = NULL 27 | return address 28 | 29 | def welcome(): 30 | """This function generates welcome messages that voice.py functions use to welcome the user.""" 31 | greetings = [ 32 | 'Hi,', 33 | 'Hello,', 34 | 'Good day,', 35 | 'Hola,', 36 | 'Howdy,', 37 | ] 38 | 39 | inquires = [ 40 | "How's it going?", 41 | "How are you doing?", 42 | "How are you feeling today?", 43 | "How are you feeling?", 44 | "How are you?", 45 | "How are you doing today?", 46 | "How is your day going?", 47 | "How have you been?", 48 | "How have you been feeling?", 49 | "How have you been today?", 50 | "How have you been feeling today?" 51 | ] 52 | 53 | welcome = ((random.choice(greetings)) + " " + (random.choice(inquires))) 54 | 55 | print(welcome) 56 | 57 | return (welcome) 58 | 59 | def re(): 60 | """This generates the re-prompt phrases that the skill uses if a user has not responded. """ 61 | reprompts = [ 62 | 'Are you still there?', 63 | 'Did you leave?', 64 | 'Did you still want me to check in on you?', 65 | 'Hello?', 66 | 'Are you there?' 67 | ] 68 | 69 | help_message = "Say 'help' if you need assistance" 70 | print((random.choice(reprompts)) + " " + (help_message)) 71 | return ((random.choice(reprompts)) + " " + (help_message)) 72 | 73 | def condolences(): 74 | """This function generates the condolences used by the voice.py functions when a user responds with something negative""" 75 | condolences = [ 76 | "I'm sorry to hear that.", 77 | "I'm sorry you aren't feeling good.", 78 | "I'm so sorry you feel like that.", 79 | "I'm sorry, it's going to get better.", 80 | "Well that's not ideal.", 81 | "That's too bad", 82 | "Your emotions are important during this time, and I’m happy to help you shoulder them.", 83 | "I promise it gets better. ", 84 | "I'm sorry, but I am here for you." 85 | ] 86 | print(random.choice(condolences)) 87 | return (random.choice(condolences)) 88 | 89 | def ideas(): 90 | 91 | """This is the function that generates the idea for mood improvement that is offered by various voice.py functions""" 92 | 93 | ideas = [ 94 | "Go for a walk.", 95 | "Complete one chore.", 96 | "Play your favorite video game.", 97 | "Play with your pet.", 98 | "Watch a movie.", 99 | "Look at pictures from your last vacation.", 100 | "Put on a fancy outfit.", 101 | "Go thrifting.", 102 | "Work on your hobby.", 103 | "Go to the gym.", 104 | "Exercise.", 105 | "Do 10 push-ups.", 106 | "Cook a delicious meal.", 107 | "Go window shopping.", 108 | "Do some Yoga.", 109 | "Repair something around your house.", 110 | "Go for a bike ride.", 111 | "Doodle.", 112 | "Paint a picture.", 113 | "Call a friend and hang out.", 114 | "Go to your favorite coffee shop.", 115 | "Go for a scenic drive.", 116 | "Get a new haircut.", 117 | "Listen to your favorite music.", 118 | "Go fishing.", 119 | "Gaze at the stars.", 120 | "Meditate.", 121 | "Vist a museum.", 122 | "Watch a video of baby pugs.", 123 | "Do a puzzle.", 124 | "Re-arrange the furniture in a room in your house.", 125 | "Clean your house.", 126 | "Do laundry.", 127 | "Make a to-do list for this week.", 128 | "Prep your lunch for tomorrow.", 129 | "Look in a mirror and tell yourself that you are awesome.", 130 | ] 131 | 132 | return (random.choice(ideas)) 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /Voice_assets/sample_utterances.txt: -------------------------------------------------------------------------------- 1 | PositiveFeeling I feel good 2 | PositiveFeeling I feel ok 3 | PositiveFeeling I feel great 4 | PositiveFeeling I feel alright 5 | PositiveFeeling I feel awesome 6 | PositiveFeeling awesome 7 | PositiveFeeling I'm doing alright 8 | PositiveFeeling I'm just chillin 9 | PositiveFeeling Pretty good 10 | PositiveFeeling pretty dang good 11 | PositiveFeeling I'm on top of the world 12 | PositiveFeeling ok 13 | PositiveFeeling fine 14 | PositiveFeeling great 15 | PositiveFeeling okay 16 | PositiveFeeling not bad 17 | 18 | FindTherapist help me find a therapist 19 | FindTherapist I would like therapy 20 | FindTherapist can you find me a therapist 21 | FindTherapist can you find me a psychologist 22 | FindTherapist can you find me a counselor 23 | FindTherapist help me find a therapist 24 | FindTherapist help me find a counselor 25 | FindTherapist help me find a psychologist 26 | FindTherapist please find me a therapist 27 | FindTherapist please find me a counselor 28 | FindTherapist please find me a psychologist 29 | FindTherapist locate a therapist 30 | FindTherapist locate therapy 31 | 32 | NegativeFeeling I feel bad 33 | NegativeFeeling I feel down 34 | NegativeFeeling feel like shit 35 | NegativeFeeling bad 36 | NegativeFeeling crappy 37 | NegativeFeeling shitty 38 | NegativeFeeling I've felt better 39 | NegativeFeeling I've had better days 40 | NegativeFeeling I feel awful 41 | NegativeFeeling I feel terrible 42 | NegativeFeeling terrible 43 | NegativeFeeling really bad 44 | NegativeFeeling really down 45 | NegativeFeeling pretty bad 46 | NegativeFeeling kinda bad 47 | NegativeFeeling kinda down 48 | NegativeFeeling pretty bad 49 | 50 | BedYes Yes I got out of bed 51 | BedYes I've gotten out of bed today 52 | BedYes I'm out of bed 53 | BedYes I got up 54 | BedYes I'm up 55 | 56 | BedNo I haven't got up yet 57 | BedNo I haven't gotten up yet 58 | BedNo I'm still in bed 59 | BedNo I just woke up 60 | BedNo it's too hard 61 | BedNo I don't want to get out of bed 62 | BedNo I'm laying in bed 63 | 64 | 65 | AteYes I ate today 66 | AteYes I had breakfast 67 | AteYes I had lunch 68 | AteYes I had dinner 69 | AteYes I had brunch 70 | AteYes I ate something today 71 | AteYes I have eaten 72 | AteYes I ate 73 | 74 | 75 | AteNo I haven't eaten 76 | AteNo I wasn't hungry 77 | AteNo I don't want to eat 78 | AteNo Food doesn't sound good. 79 | AteNo I aint ate nothing 80 | AteNo I tried 81 | AteNo I'm not hungry 82 | 83 | ShowerYes I took a shower 84 | ShowerYes I showered 85 | ShowerYes I showered last night 86 | ShowerYes I took a shower before bed 87 | ShowerYes I took a shower last night 88 | ShowerYes I took a bath 89 | ShowerYes I bathed 90 | ShowerYes I took a hot shower 91 | 92 | ShowerNo I have not showered 93 | ShowerNo I have not taken a shower 94 | ShowerNo I I haven't showered 95 | ShowerNo I haven't taken a shower 96 | ShowerNo I haven't took a shower 97 | ShowerNo I don't want to 98 | 99 | DressedYes I'm dressed 100 | DressedYes I got dressed 101 | DressedYes I put some clothes on 102 | DressedYes I changed earlier 103 | DressedYes I changed 104 | DressedYes I threw on some clothes 105 | DressedYes I have gotten dressed 106 | DressedYes I put on clothes 107 | 108 | OutsideYes I have been outside 109 | OutsideYes I went outside earlier 110 | OutsideYes I went outside 111 | OutsideYes I've been outside 112 | OutsideYes I went out 113 | OutsideYes I was out for a minute 114 | OutsideYes I was out 115 | OutsideYes I went for a walk 116 | OutsideYes I went for a bike ride 117 | OutsideYes I walked my dog 118 | 119 | OutsideNo I have not been outside 120 | OutsideNo I haven't gone outside 121 | OutsideNo I have not gone outside 122 | OutsideNo I haven't been out 123 | OutsideNo I'm still inside 124 | OutsideNo I ain't gone out 125 | OutsideNo I have not been out 126 | 127 | SuggestIdea give me ideas 128 | SuggestIdea how can I improve my mood 129 | SuggestIdea what should I do 130 | SuggestIdea any idea what to do 131 | SuggestIdea help me improve my mood 132 | SuggestIdea tell me ways to feel better 133 | SuggestIdea tell me a way to cheer up 134 | SuggestIdea give me ideas on how to cheer up 135 | SuggestIdea suggest things I could do to feel better 136 | SuggestIdea help me feel better 137 | SuggestIdea I want to feel better 138 | SuggestIdea tell me how to improve my mood 139 | SuggestIdea improve my mood 140 | SuggestIdea give me ideas to improve my mood 141 | 142 | HotLine I'm going to kill myself 143 | HotLine I'm going to end it 144 | HotLine I don't feel like living 145 | HotLine I don't want to be alive anymore 146 | HotLine I want to kill myself 147 | HotLine I want to die 148 | HotLine Kill me 149 | HotLine I'm going to jump off of a bridge 150 | HotLine I'm going to jump off a bridge 151 | HotLine I'm going to die 152 | HotLine I'm going to take a bunch of pills 153 | HotLine I am going to commit suicide 154 | HotLine I want to commit suicide 155 | HotLine I'm going to jump 156 | HotLine I'm going to kill myself and others 157 | HotLine I want to kill everyone 158 | 159 | StartReport can you send a report for me 160 | StartReport send report 161 | StartReport send a report 162 | StartReport send my daily report 163 | StartReport can you send someone a report of my mood today 164 | StartReport can you send the report 165 | StartReport report 166 | 167 | Name {person_name} 168 | 169 | Email {example at gmail dot com | email_address} 170 | 171 | -------------------------------------------------------------------------------- /Localization/Canada/voice.py: -------------------------------------------------------------------------------- 1 | #### Credit to Cookiecutter Flask Ask for built-in intent functions 2 | 3 | from flask import Flask 4 | from flask_ask import Ask, statement, question, session 5 | from controller import welcome, re, condolences,ideas, get_alexa_location 6 | import geocoder 7 | import random 8 | import requests 9 | 10 | app = Flask(__name__) 11 | ask = Ask(app, '/') 12 | 13 | """ These functions handle what are essentially the beginning and end of the main use case of the skill.""" 14 | @ask.launch 15 | def start_session(): 16 | """ This function is what initializes the application. It calls the welcome() method from controller.py 17 | to generate a different welcome message each time """ 18 | welcome_text = welcome() 19 | welcome_re_text = re() 20 | 21 | return question(welcome_text).reprompt(welcome_re_text) 22 | 23 | 24 | def evaluate_answers(): 25 | """This function evaluates the user's answers to the questions the skill poses if "NegativeFeeling" is called. 26 | It evaluates the functions in order of usual routine. """ 27 | if session.attributes["Bed"] == "No": 28 | return "Okay, well let's start by getting out of bed. You can do it!" 29 | elif session.attributes["Eaten"] == "No": 30 | return "That's okay, but you should try to eat. You got this!" 31 | elif session.attributes["Showered"] == "No": 32 | return "Hmmm. Maybe you should take a nice, hot shower. It will help you feel better." 33 | elif session.attributes["Dressed"] == "No": 34 | return "Alright. Well let's try getting dressed. You can do it!" 35 | elif session.attributes["Outside"] == "No": 36 | return "Well let's try going outside. It might elate you. " 37 | else: 38 | return "Good job doing all those things. When you're depressed, those little things can be the most difficult" 39 | 40 | 41 | """These functions handle intent logic for the voice interface. """ 42 | 43 | # @ask.intent('StartReport') 44 | # def start_reporting(): 45 | # try: 46 | # if session.attributes['State'] == 'Startedreport': 47 | # return question("""Okay, please tell me the email address you would like the report sent to""") 48 | # elif session.attributes["State"] == "Question 0 Answered": 49 | # return question("""Okay, please tell me the email address you would like the report sent to""") 50 | # elif session.attributes["State"] == "Question 1 Answered": 51 | # return question("""Okay, please tell me the email address you would like the report sent to""") 52 | # else: 53 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 54 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 55 | # except: 56 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 57 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 58 | 59 | # @ask.intent('Email') 60 | # def get_name(email_address): 61 | # session.attributes["Email"] = email_address 62 | # return question("Okay, and what is your name?") 63 | # 64 | # @ask.intent('Name') 65 | # def finish_report(person_name): 66 | # message = "Okay, I've sent a report to {} about your day. Is there anything else I can do?" 67 | # return question(message) 68 | 69 | @ask.intent('PositiveFeeling') 70 | def user_feels_good(): 71 | """This function is triggered if the PositiveFeeling intent is detected. """ 72 | congrats = [ 73 | 'That is so good to hear!', 74 | 'I am happy you feel good today', 75 | 'I am glad to hear that.', 76 | 'Oh happy day!', 77 | 'Awesome.', 78 | 'Good to hear!', 79 | 'Wonderful!', 80 | 'Great!', 81 | 'I am so happy about that!' 82 | ] 83 | 84 | session.attributes["feeling"] = "Good" 85 | session.attributes["State"] = "Question 0 Answered" 86 | return question((random.choice(congrats)) + ' ' + 'Is there anything else you need? Want me to recommend a therapist?') 87 | 88 | @ask.intent('NegativeFeeling') 89 | def user_feels_bad(): 90 | """This function is triggered if the NegativeFeeling intent is detected. This also kicks off the question to guage 91 | whether the user has perfomed daily activities.""" 92 | condolence = condolences() 93 | session.attributes["feeling"] = "Down" 94 | session.attributes["State"] = "Question 1 Answered" 95 | return question(condolence + " " + "Have you gotten out of bed today?") 96 | 97 | """ The following functions are called depending on the user's answers.""" 98 | @ask.intent('BedYes') 99 | def out_of_bed(): 100 | message = random.choice([ 101 | 'Awesome.', 102 | 'Good to hear!', 103 | 'Wonderful!', 104 | 'Great!', 105 | ]) 106 | session.attributes["Bed"] = "Yes" 107 | session.attributes["State"] = "Question 2 Answered" 108 | return question (message + " " + "Have you eaten today?") 109 | 110 | @ask.intent('BedNo') 111 | def not_out_of_bed(): 112 | 113 | message = random.choice([ 114 | "That's too bad.", 115 | "That's okay, we all have days like that.", 116 | "I'm sorry. ", 117 | "That's too bad", 118 | "It's okay." 119 | ]) 120 | 121 | session.attributes["State"] = "Question 2 Answered" 122 | session.attributes["Bed"] = "No" 123 | return question(message + " " + "Have you eaten today?") 124 | 125 | 126 | @ask.intent('AteYes') 127 | def eaten(): 128 | message = random.choice([ 129 | 'Awesome.', 130 | 'Good to hear!', 131 | 'Wonderful!', 132 | 'Great!', 133 | ]) 134 | session.attributes["Eaten"] = "Yes" 135 | session.attributes["State"] = "Question 3 Answered" 136 | return question(message + " " + "Have you showered today?") 137 | 138 | @ask.intent('AteNo') 139 | def not_eaten(): 140 | message = random.choice([ 141 | "That's too bad.", 142 | "That's okay, we all have days like that.", 143 | "I'm sorry. ", 144 | "That's not good.", 145 | "It's okay." 146 | ]) 147 | 148 | session.attributes["Eaten"] = "No" 149 | session.attributes["State"] = "Question 3 Answered" 150 | return question(message + " " + "Have you showered today?") 151 | 152 | @ask.intent('ShowerYes') 153 | def showered(): 154 | message = random.choice([ 155 | 'Awesome.', 156 | 'Good to hear!', 157 | 'Wonderful!', 158 | 'Great!', 159 | ]) 160 | 161 | session.attributes["Showered"] = "Yes" 162 | session.attributes["State"] = "Question 4 Answered" 163 | return question(message + " " + "Have you gotten dressed?") 164 | 165 | @ask.intent('ShowerNo') 166 | def not_showered(): 167 | message = random.choice([ 168 | "That's too bad.", 169 | "That's okay, we all have days like that.", 170 | "I'm sorry. ", 171 | "That's not good.", 172 | "It's okay." 173 | ]) 174 | 175 | session.attributes["Showered"] = "No" 176 | session.attributes["State"] = "Question 4 Answered" 177 | return question(message + " " + "Have you gotten dressed?") 178 | 179 | @ask.intent('DressedYes') 180 | def dressed(): 181 | message = random.choice([ 182 | 'Awesome.', 183 | 'Good to hear!', 184 | 'Wonderful!', 185 | 'Great!', 186 | ]) 187 | 188 | session.attributes["Dressed"] = "Yes" 189 | session.attributes["State"] = "Question 5 Answered" 190 | return question(message + " " + "Have you gone outside at all today?") 191 | 192 | 193 | @ask.intent('DressedNo') 194 | def not_dressed(): 195 | message = random.choice([ 196 | "That's too bad.", 197 | "That's okay, we all have days like that.", 198 | "I'm sorry. ", 199 | "That's not good.", 200 | "It's okay." 201 | ]) 202 | 203 | session.attributes["Dressed"] = "No" 204 | session.attributes["State"] = "Question 5 Answered" 205 | return question(message + " " + "Have you gone outside at all today?") 206 | 207 | @ask.intent('OutsideYes') 208 | def outside(): 209 | message = random.choice([ 210 | 'Awesome.', 211 | 'Good to hear!', 212 | 'Wonderful!', 213 | 'Great!', 214 | ]) 215 | 216 | session.attributes["Outside"] = "Yes" 217 | session.attributes["State"] = "Suggested" 218 | response = evaluate_answers() 219 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 220 | suggestion_inquiry = "Let's try something else to improve your mood." 221 | else: 222 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 223 | idea = ideas() 224 | 225 | return statement(message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 226 | 227 | @ask.intent('OutsideNo') 228 | def not_outside(): 229 | message = random.choice([ 230 | "That's too bad.", 231 | "That's okay, we all have days like that.", 232 | "I'm sorry. ", 233 | "That's not good.", 234 | "It's okay." 235 | ]) 236 | 237 | session.attributes["Outside"] = "No" 238 | session.attributes["State"] = "Suggested" 239 | response = evaluate_answers() 240 | suggestion_inquiry = "Let's also try something else to improve your mood." 241 | idea = ideas() 242 | return question(message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 243 | 244 | """ The following functions handle the built-in Amazon intents based on the session state. """ 245 | @ask.intent('AMAZON.NoIntent') 246 | def handle_no(): 247 | try: 248 | if session.attributes["State"] == "Question 0 Answered": 249 | return statement("Okay. Check in with me again later!") 250 | elif session.attributes["State"] == "Question 1 Answered": 251 | message = random.choice([ 252 | "That's too bad.", 253 | "That's okay, we all have days like that.", 254 | "I'm sorry. ", 255 | "That's too bad", 256 | "It's okay." 257 | ]) 258 | 259 | session.attributes["State"] = "Question 2 Answered" 260 | session.attributes["Bed"] = "No" 261 | return question(message + " " + "Have you eaten today?") 262 | elif session.attributes["State"] == "Question 2 Answered": 263 | message = random.choice([ 264 | "That's too bad.", 265 | "That's okay, we all have days like that.", 266 | "I'm sorry. ", 267 | "That's not good.", 268 | "It's okay." 269 | ]) 270 | 271 | session.attributes["Eaten"] = "No" 272 | session.attributes["State"] = "Question 3 Answered" 273 | return question(message + " " + "Have you showered today?") 274 | elif session.attributes["State"] == "Question 3 Answered": 275 | message = random.choice([ 276 | "That's too bad.", 277 | "That's okay, we all have days like that.", 278 | "I'm sorry. ", 279 | "That's not good.", 280 | "It's okay." 281 | ]) 282 | 283 | session.attributes["Showered"] = "No" 284 | session.attributes["State"] = "Question 4 Answered" 285 | return question(message + " " + "Have you gotten dressed?") 286 | elif session.attributes["State"] == "Question 4 Answered": 287 | message = random.choice([ 288 | "That's too bad.", 289 | "That's okay, we all have days like that.", 290 | "I'm sorry. ", 291 | "That's not good.", 292 | "It's okay." 293 | ]) 294 | 295 | session.attributes["Dressed"] = "No" 296 | session.attributes["State"] = "Question 5 Answered" 297 | return question(message + " " + "Have you gone outside at all today?") 298 | elif session.attributes["State"] == "Question 5 Answered": 299 | message = random.choice([ 300 | "That's too bad.", 301 | "That's okay, we all have days like that.", 302 | "I'm sorry. ", 303 | "That's not good.", 304 | "It's okay." 305 | ]) 306 | 307 | session.attributes["Outside"] = "No" 308 | session.attributes["State"] = "Suggested" 309 | response = evaluate_answers() 310 | suggestion_inquiry = "Let's also try something else to improve your mood." 311 | idea = ideas() 312 | return question( 313 | message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Anything else I can do?") 314 | elif session.attributes["State"] == "Suggested": 315 | session.attributes["State"] = "AnythingElse" 316 | return question("Okay, I hope that helped. Anything else I can do for you?") 317 | elif session.attributes["State"] == "AnythingElse": 318 | return question("No problem. Check in with me later. Goodbye") 319 | else: 320 | return question("I'm sorry, I didn't get that. How are you feeling? ") 321 | except: 322 | return question("I'm sorry, I didn't get that. How are you feeling?") 323 | 324 | @ask.intent('AMAZON.YesIntent') 325 | def handle_yes(): 326 | try: 327 | if session.attributes["State"] == "Question 0 Answered": 328 | return question("Okay. What can I do for you?") 329 | 330 | elif session.attributes["State"] == "Question 1 Answered": 331 | message = random.choice([ 332 | 'Awesome.', 333 | 'Good to hear!', 334 | 'Wonderful!', 335 | 'Great!', 336 | ]) 337 | session.attributes["Bed"] = "Yes" 338 | session.attributes["State"] = "Question 2 Answered" 339 | return question(message + " " + "Have you eaten today?") 340 | 341 | elif session.attributes["State"] == "Question 2 Answered": 342 | message = random.choice([ 343 | 'Awesome.', 344 | 'Good to hear!', 345 | 'Wonderful!', 346 | 'Great!', 347 | ]) 348 | session.attributes["Eaten"] = "Yes" 349 | session.attributes["State"] = "Question 3 Answered" 350 | return question(message + " " + "Have you showered today?") 351 | 352 | elif session.attributes["State"] == "Question 3 Answered": 353 | message = random.choice([ 354 | 'Awesome.', 355 | 'Good to hear!', 356 | 'Wonderful!', 357 | 'Great!', 358 | ]) 359 | 360 | session.attributes["Showered"] = "Yes" 361 | session.attributes["State"] = "Question 4 Answered" 362 | return question(message + " " + "Have you gotten dressed?") 363 | 364 | elif session.attributes["State"] == "Question 4 Answered": 365 | message = random.choice([ 366 | 'Awesome.', 367 | 'Good to hear!', 368 | 'Wonderful!', 369 | 'Great!', 370 | ]) 371 | 372 | session.attributes["Dressed"] = "Yes" 373 | session.attributes["State"] = "Question 5 Answered" 374 | return question(message + " " + "Have you gone outside at all today?") 375 | 376 | elif session.attributes["State"] == "Question 5 Answered": 377 | message = random.choice([ 378 | 'Awesome.', 379 | 'Good to hear!', 380 | 'Wonderful!', 381 | 'Great!', 382 | ]) 383 | 384 | session.attributes["Outside"] = "Yes" 385 | session.attributes["State"] = "Suggested" 386 | response = evaluate_answers() 387 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 388 | suggestion_inquiry = "Let's try something else to improve your mood." 389 | else: 390 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 391 | idea = ideas() 392 | session.attributes["State"] = "AnythingElse" 393 | return question( 394 | message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Is there anything else I can do?") 395 | elif session.attributes["State"] == "Suggested": 396 | message = "Okay, here's another idea. " 397 | idea = ideas() 398 | session.attributes["State"] = "Suggested" 399 | return question( 400 | message + " " + idea + " " + "Would you like another suggestion?") 401 | elif session.attributes["State"] == "AnythingElse": 402 | return question("Okay, I love to help. What can I do for you? Say help if you would like to learn about my other capabilities.") 403 | else: 404 | return question("I'm sorry, I didn't get that. How are you feeling? ") 405 | except: 406 | return question("I'm sorry, I didn't get that. How are you feeling? ") 407 | 408 | """ The following functions handle the additional use cases of recommending a therapist, detecting and preventing suicide, and 409 | giving ideas on how to improve the user's mood.""" 410 | 411 | @ask.intent('SuggestIdea') 412 | def suggest_ideas(): 413 | suggestion_inquiry = "Okay. Here's an idea for an extra way to improve your mood." 414 | idea = ideas() 415 | session.attributes["State"] = "Suggested" 416 | return question(suggestion_inquiry + " " + idea + " " + "Would you like another suggestion?") 417 | 418 | @ask.intent('HotLine') 419 | def hot_line(): 420 | return statement("""Please don't hurt yourself or anyone else. I may just be a robot, but I 421 | was created by a person who wants to help you and thinks you are worth it. Please call the National Suicide 422 | Prevention Hotline at 1-800-273-8255. They are available to talk to you 24 hours a day, 7 days a week. 423 | I've placed their number on a card in your Alexa app for reference.""") \ 424 | .standard_card(title='National Suicide Prevention Hot Line', text='Call Now 1-800-273-8255 ', large_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Lifelinelogo.svg/1200px-Lifelinelogo.svg.png' ) 425 | 426 | @ask.intent('FindTherapist') 427 | def find_therapist(): 428 | """This function uses the Google Places API to recommend a therapist based on the user's location. """ 429 | keyword = "counseling OR therapist OR psychiatrist" 430 | try: 431 | address = get_alexa_location() 432 | pass 433 | except: 434 | return statement("""Hmm. It appears that I can't find your location. Please allow access to your " 435 | location in the Alexa app and try again """).consent_card("read::alexa:device:all:address") 436 | g = geocoder.google(address) 437 | latlng = g.latlng 438 | location = "{},{}".format(latlng[0], latlng[1]) 439 | print(location) 440 | key = "AIzaSyA1yY-DOHIun0v_7kTwa_U5Ah6Am-kcjCM" 441 | URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(location,keyword,key) 442 | print(URL2) 443 | r2 = requests.get(URL2) 444 | if r2.status_code == 200: 445 | first_output = r2.json() 446 | else: 447 | return "Sorry, I'm having trouble doing that right now. Please try again later." 448 | results = first_output['results'] 449 | idnum = (results[1]['place_id']) 450 | name = (results[1]['name']) 451 | # print(results[1]) 452 | # print(idnum) 453 | URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(idnum, key) 454 | r3 = requests.get(URL3) 455 | if r3.status_code == 200: 456 | second_output = r3.json() 457 | phone = (second_output['result'])['international_phone_number'] 458 | # print(second_output) 459 | # print(phone) 460 | session.attributes["State"] = "Null" 461 | message = """I've found a therapist near you. Their name is: {}, and their number is: {}. I've added their 462 | contact info to a card in the Alexa app. Is there anything else I can do?""".format(name,phone) 463 | card = "Name:{} \n Phone:{}".format(name,phone) 464 | return question(message).standard_card(title="I've found you a possible therapist", 465 | text=card, 466 | large_image_url="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80") 467 | else: 468 | return statement("Sorry, I'm having trouble doing that right now. Please try again later.") 469 | 470 | 471 | @ask.intent('AMAZON.StopIntent') 472 | def handle_stop(): 473 | """ 474 | This handles the 'stop' built-in intention. 475 | """ 476 | farewell_text = "Have a good day. I hope to hear from you soon." 477 | return statement(farewell_text) 478 | 479 | 480 | @ask.intent('AMAZON.CancelIntent') 481 | def handle_cancel(): 482 | """ 483 | This handles the 'cancel' built-in intention. 484 | """ 485 | farewell_text = "Goodbye" 486 | return statement(farewell_text) 487 | 488 | 489 | @ask.intent('AMAZON.HelpIntent') 490 | def handle_help(): 491 | """ 492 | This handles the 'help' built-in intention. 493 | 494 | """ 495 | 496 | help_text = """There's a few things I can do to help. I can recommend a therapist or offer a suggestion for 497 | a way to improve your mood. I also possess the capability to detect suicidal intentions, 498 | but I really hope that you won't need me to do that. """ 499 | return question(help_text) 500 | 501 | 502 | if __name__ == '__main__': 503 | app.run(debug=True, port=5000) 504 | -------------------------------------------------------------------------------- /Localization/India/voice.py: -------------------------------------------------------------------------------- 1 | #### Credit to Cookiecutter Flask Ask for built-in intent functions 2 | 3 | from flask import Flask 4 | from flask_ask import Ask, statement, question, session 5 | from controller import welcome, re, condolences,ideas, get_alexa_location 6 | import geocoder 7 | import random 8 | import requests 9 | 10 | app = Flask(__name__) 11 | ask = Ask(app, '/') 12 | 13 | """ These functions handle what are essentially the beginning and end of the main use case of the skill.""" 14 | @ask.launch 15 | def start_session(): 16 | """ This function is what initializes the application. It calls the welcome() method from controller.py 17 | to generate a different welcome message each time """ 18 | welcome_text = welcome() 19 | welcome_re_text = re() 20 | 21 | return question(welcome_text).reprompt(welcome_re_text) 22 | 23 | 24 | def evaluate_answers(): 25 | """This function evaluates the user's answers to the questions the skill poses if "NegativeFeeling" is called. 26 | It evaluates the functions in order of usual routine. """ 27 | if session.attributes["Bed"] == "No": 28 | return "Okay, well let's start by getting out of bed. You can do it!" 29 | elif session.attributes["Eaten"] == "No": 30 | return "That's okay, but you should try to eat. You got this!" 31 | elif session.attributes["Showered"] == "No": 32 | return "Hmmm. Maybe you should take a nice, hot shower. It will help you feel better." 33 | elif session.attributes["Dressed"] == "No": 34 | return "Alright. Well let's try getting dressed. You can do it!" 35 | elif session.attributes["Outside"] == "No": 36 | return "Well let's try going outside. It might elate you. " 37 | else: 38 | return "Good job doing all those things. When you're depressed, those little things can be the most difficult" 39 | 40 | 41 | """These functions handle intent logic for the voice interface. """ 42 | 43 | # @ask.intent('StartReport') 44 | # def start_reporting(): 45 | # try: 46 | # if session.attributes['State'] == 'Startedreport': 47 | # return question("""Okay, please tell me the email address you would like the report sent to""") 48 | # elif session.attributes["State"] == "Question 0 Answered": 49 | # return question("""Okay, please tell me the email address you would like the report sent to""") 50 | # elif session.attributes["State"] == "Question 1 Answered": 51 | # return question("""Okay, please tell me the email address you would like the report sent to""") 52 | # else: 53 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 54 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 55 | # except: 56 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 57 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 58 | 59 | # @ask.intent('Email') 60 | # def get_name(email_address): 61 | # session.attributes["Email"] = email_address 62 | # return question("Okay, and what is your name?") 63 | # 64 | # @ask.intent('Name') 65 | # def finish_report(person_name): 66 | # message = "Okay, I've sent a report to {} about your day. Is there anything else I can do?" 67 | # return question(message) 68 | 69 | @ask.intent('PositiveFeeling') 70 | def user_feels_good(): 71 | """This function is triggered if the PositiveFeeling intent is detected. """ 72 | congrats = [ 73 | 'That is so good to hear!', 74 | 'I am happy you feel good today', 75 | 'I am glad to hear that.', 76 | 'Oh happy day!', 77 | 'Awesome.', 78 | 'Good to hear!', 79 | 'Wonderful!', 80 | 'Great!', 81 | 'I am so happy about that!' 82 | ] 83 | 84 | session.attributes["feeling"] = "Good" 85 | session.attributes["State"] = "Question 0 Answered" 86 | return question((random.choice(congrats)) + ' ' + 'Is there anything else you need? Want me to recommend a therapist?') 87 | 88 | @ask.intent('NegativeFeeling') 89 | def user_feels_bad(): 90 | """This function is triggered if the NegativeFeeling intent is detected. This also kicks off the question to guage 91 | whether the user has perfomed daily activities.""" 92 | condolence = condolences() 93 | session.attributes["feeling"] = "Down" 94 | session.attributes["State"] = "Question 1 Answered" 95 | return question(condolence + " " + "Have you gotten out of bed today?") 96 | 97 | """ The following functions are called depending on the user's answers.""" 98 | @ask.intent('BedYes') 99 | def out_of_bed(): 100 | message = random.choice([ 101 | 'Awesome.', 102 | 'Good to hear!', 103 | 'Wonderful!', 104 | 'Great!', 105 | ]) 106 | session.attributes["Bed"] = "Yes" 107 | session.attributes["State"] = "Question 2 Answered" 108 | return question (message + " " + "Have you eaten today?") 109 | 110 | @ask.intent('BedNo') 111 | def not_out_of_bed(): 112 | 113 | message = random.choice([ 114 | "That's too bad.", 115 | "That's okay, we all have days like that.", 116 | "I'm sorry. ", 117 | "That's too bad", 118 | "It's okay." 119 | ]) 120 | 121 | session.attributes["State"] = "Question 2 Answered" 122 | session.attributes["Bed"] = "No" 123 | return question(message + " " + "Have you eaten today?") 124 | 125 | 126 | @ask.intent('AteYes') 127 | def eaten(): 128 | message = random.choice([ 129 | 'Awesome.', 130 | 'Good to hear!', 131 | 'Wonderful!', 132 | 'Great!', 133 | ]) 134 | session.attributes["Eaten"] = "Yes" 135 | session.attributes["State"] = "Question 3 Answered" 136 | return question(message + " " + "Have you showered today?") 137 | 138 | @ask.intent('AteNo') 139 | def not_eaten(): 140 | message = random.choice([ 141 | "That's too bad.", 142 | "That's okay, we all have days like that.", 143 | "I'm sorry. ", 144 | "That's not good.", 145 | "It's okay." 146 | ]) 147 | 148 | session.attributes["Eaten"] = "No" 149 | session.attributes["State"] = "Question 3 Answered" 150 | return question(message + " " + "Have you showered today?") 151 | 152 | @ask.intent('ShowerYes') 153 | def showered(): 154 | message = random.choice([ 155 | 'Awesome.', 156 | 'Good to hear!', 157 | 'Wonderful!', 158 | 'Great!', 159 | ]) 160 | 161 | session.attributes["Showered"] = "Yes" 162 | session.attributes["State"] = "Question 4 Answered" 163 | return question(message + " " + "Have you gotten dressed?") 164 | 165 | @ask.intent('ShowerNo') 166 | def not_showered(): 167 | message = random.choice([ 168 | "That's too bad.", 169 | "That's okay, we all have days like that.", 170 | "I'm sorry. ", 171 | "That's not good.", 172 | "It's okay." 173 | ]) 174 | 175 | session.attributes["Showered"] = "No" 176 | session.attributes["State"] = "Question 4 Answered" 177 | return question(message + " " + "Have you gotten dressed?") 178 | 179 | @ask.intent('DressedYes') 180 | def dressed(): 181 | message = random.choice([ 182 | 'Awesome.', 183 | 'Good to hear!', 184 | 'Wonderful!', 185 | 'Great!', 186 | ]) 187 | 188 | session.attributes["Dressed"] = "Yes" 189 | session.attributes["State"] = "Question 5 Answered" 190 | return question(message + " " + "Have you gone outside at all today?") 191 | 192 | 193 | @ask.intent('DressedNo') 194 | def not_dressed(): 195 | message = random.choice([ 196 | "That's too bad.", 197 | "That's okay, we all have days like that.", 198 | "I'm sorry. ", 199 | "That's not good.", 200 | "It's okay." 201 | ]) 202 | 203 | session.attributes["Dressed"] = "No" 204 | session.attributes["State"] = "Question 5 Answered" 205 | return question(message + " " + "Have you gone outside at all today?") 206 | 207 | @ask.intent('OutsideYes') 208 | def outside(): 209 | message = random.choice([ 210 | 'Awesome.', 211 | 'Good to hear!', 212 | 'Wonderful!', 213 | 'Great!', 214 | ]) 215 | 216 | session.attributes["Outside"] = "Yes" 217 | session.attributes["State"] = "Suggested" 218 | response = evaluate_answers() 219 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 220 | suggestion_inquiry = "Let's try something else to improve your mood." 221 | else: 222 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 223 | idea = ideas() 224 | 225 | return statement(message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 226 | 227 | @ask.intent('OutsideNo') 228 | def not_outside(): 229 | message = random.choice([ 230 | "That's too bad.", 231 | "That's okay, we all have days like that.", 232 | "I'm sorry. ", 233 | "That's not good.", 234 | "It's okay." 235 | ]) 236 | 237 | session.attributes["Outside"] = "No" 238 | session.attributes["State"] = "Suggested" 239 | response = evaluate_answers() 240 | suggestion_inquiry = "Let's also try something else to improve your mood." 241 | idea = ideas() 242 | return question(message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 243 | 244 | """ The following functions handle the built-in Amazon intents based on the session state. """ 245 | @ask.intent('AMAZON.NoIntent') 246 | def handle_no(): 247 | try: 248 | if session.attributes["State"] == "Question 0 Answered": 249 | return statement("Okay. Check in with me again later!") 250 | elif session.attributes["State"] == "Question 1 Answered": 251 | message = random.choice([ 252 | "That's too bad.", 253 | "That's okay, we all have days like that.", 254 | "I'm sorry. ", 255 | "That's too bad", 256 | "It's okay." 257 | ]) 258 | 259 | session.attributes["State"] = "Question 2 Answered" 260 | session.attributes["Bed"] = "No" 261 | return question(message + " " + "Have you eaten today?") 262 | elif session.attributes["State"] == "Question 2 Answered": 263 | message = random.choice([ 264 | "That's too bad.", 265 | "That's okay, we all have days like that.", 266 | "I'm sorry. ", 267 | "That's not good.", 268 | "It's okay." 269 | ]) 270 | 271 | session.attributes["Eaten"] = "No" 272 | session.attributes["State"] = "Question 3 Answered" 273 | return question(message + " " + "Have you showered today?") 274 | elif session.attributes["State"] == "Question 3 Answered": 275 | message = random.choice([ 276 | "That's too bad.", 277 | "That's okay, we all have days like that.", 278 | "I'm sorry. ", 279 | "That's not good.", 280 | "It's okay." 281 | ]) 282 | 283 | session.attributes["Showered"] = "No" 284 | session.attributes["State"] = "Question 4 Answered" 285 | return question(message + " " + "Have you gotten dressed?") 286 | elif session.attributes["State"] == "Question 4 Answered": 287 | message = random.choice([ 288 | "That's too bad.", 289 | "That's okay, we all have days like that.", 290 | "I'm sorry. ", 291 | "That's not good.", 292 | "It's okay." 293 | ]) 294 | 295 | session.attributes["Dressed"] = "No" 296 | session.attributes["State"] = "Question 5 Answered" 297 | return question(message + " " + "Have you gone outside at all today?") 298 | elif session.attributes["State"] == "Question 5 Answered": 299 | message = random.choice([ 300 | "That's too bad.", 301 | "That's okay, we all have days like that.", 302 | "I'm sorry. ", 303 | "That's not good.", 304 | "It's okay." 305 | ]) 306 | 307 | session.attributes["Outside"] = "No" 308 | session.attributes["State"] = "Suggested" 309 | response = evaluate_answers() 310 | suggestion_inquiry = "Let's also try something else to improve your mood." 311 | idea = ideas() 312 | return question( 313 | message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Anything else I can do?") 314 | elif session.attributes["State"] == "Suggested": 315 | session.attributes["State"] = "AnythingElse" 316 | return question("Okay, I hope that helped. Anything else I can do for you?") 317 | elif session.attributes["State"] == "AnythingElse": 318 | return question("No problem. Check in with me later. Goodbye") 319 | else: 320 | return question("I'm sorry, I didn't get that. How are you feeling? ") 321 | except: 322 | return question("I'm sorry, I didn't get that. How are you feeling?") 323 | 324 | @ask.intent('AMAZON.YesIntent') 325 | def handle_yes(): 326 | try: 327 | if session.attributes["State"] == "Question 0 Answered": 328 | return question("Okay. What can I do for you?") 329 | 330 | elif session.attributes["State"] == "Question 1 Answered": 331 | message = random.choice([ 332 | 'Awesome.', 333 | 'Good to hear!', 334 | 'Wonderful!', 335 | 'Great!', 336 | ]) 337 | session.attributes["Bed"] = "Yes" 338 | session.attributes["State"] = "Question 2 Answered" 339 | return question(message + " " + "Have you eaten today?") 340 | 341 | elif session.attributes["State"] == "Question 2 Answered": 342 | message = random.choice([ 343 | 'Awesome.', 344 | 'Good to hear!', 345 | 'Wonderful!', 346 | 'Great!', 347 | ]) 348 | session.attributes["Eaten"] = "Yes" 349 | session.attributes["State"] = "Question 3 Answered" 350 | return question(message + " " + "Have you showered today?") 351 | 352 | elif session.attributes["State"] == "Question 3 Answered": 353 | message = random.choice([ 354 | 'Awesome.', 355 | 'Good to hear!', 356 | 'Wonderful!', 357 | 'Great!', 358 | ]) 359 | 360 | session.attributes["Showered"] = "Yes" 361 | session.attributes["State"] = "Question 4 Answered" 362 | return question(message + " " + "Have you gotten dressed?") 363 | 364 | elif session.attributes["State"] == "Question 4 Answered": 365 | message = random.choice([ 366 | 'Awesome.', 367 | 'Good to hear!', 368 | 'Wonderful!', 369 | 'Great!', 370 | ]) 371 | 372 | session.attributes["Dressed"] = "Yes" 373 | session.attributes["State"] = "Question 5 Answered" 374 | return question(message + " " + "Have you gone outside at all today?") 375 | 376 | elif session.attributes["State"] == "Question 5 Answered": 377 | message = random.choice([ 378 | 'Awesome.', 379 | 'Good to hear!', 380 | 'Wonderful!', 381 | 'Great!', 382 | ]) 383 | 384 | session.attributes["Outside"] = "Yes" 385 | session.attributes["State"] = "Suggested" 386 | response = evaluate_answers() 387 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 388 | suggestion_inquiry = "Let's try something else to improve your mood." 389 | else: 390 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 391 | idea = ideas() 392 | session.attributes["State"] = "AnythingElse" 393 | return question( 394 | message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Is there anything else I can do?") 395 | elif session.attributes["State"] == "Suggested": 396 | message = "Okay, here's another idea. " 397 | idea = ideas() 398 | session.attributes["State"] = "Suggested" 399 | return question( 400 | message + " " + idea + " " + "Would you like another suggestion?") 401 | elif session.attributes["State"] == "AnythingElse": 402 | return question("Okay, I love to help. What can I do for you? Say help if you would like to learn about my other capabilities.") 403 | else: 404 | return question("I'm sorry, I didn't get that. How are you feeling? ") 405 | except: 406 | return question("I'm sorry, I didn't get that. How are you feeling? ") 407 | 408 | """ The following functions handle the additional use cases of recommending a therapist, detecting and preventing suicide, and 409 | giving ideas on how to improve the user's mood.""" 410 | 411 | @ask.intent('SuggestIdea') 412 | def suggest_ideas(): 413 | suggestion_inquiry = "Okay. Here's an idea for an extra way to improve your mood." 414 | idea = ideas() 415 | session.attributes["State"] = "Suggested" 416 | return question(suggestion_inquiry + " " + idea + " " + "Would you like another suggestion?") 417 | 418 | @ask.intent('HotLine') 419 | def hot_line(): 420 | return statement("""Please don't hurt yourself or anyone else. I may just be a robot, but I 421 | was created by a person who wants to help you and thinks you are worth it. Please call the National Suicide 422 | Prevention Hotline at 1-800-273-8255. They are available to talk to you 24 hours a day, 7 days a week. 423 | I've placed their number on a card in your Alexa app for reference.""") \ 424 | .standard_card(title='National Suicide Prevention Hot Line', text='Call Now 1-800-273-8255 ', large_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Lifelinelogo.svg/1200px-Lifelinelogo.svg.png' ) 425 | 426 | @ask.intent('FindTherapist') 427 | def find_therapist(): 428 | """This function uses the Google Places API to recommend a therapist based on the user's location. """ 429 | keyword = "counseling OR therapist OR psychiatrist" 430 | try: 431 | address = get_alexa_location() 432 | pass 433 | except: 434 | return statement("""Hmm. It appears that I can't find your location. Please allow access to your " 435 | location in the Alexa app and try again """).consent_card("read::alexa:device:all:address") 436 | g = geocoder.google(address) 437 | latlng = g.latlng 438 | location = "{},{}".format(latlng[0], latlng[1]) 439 | print(location) 440 | key = "AIzaSyA1yY-DOHIun0v_7kTwa_U5Ah6Am-kcjCM" 441 | URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(location,keyword,key) 442 | print(URL2) 443 | r2 = requests.get(URL2) 444 | if r2.status_code == 200: 445 | first_output = r2.json() 446 | else: 447 | return "Sorry, I'm having trouble doing that right now. Please try again later." 448 | results = first_output['results'] 449 | idnum = (results[1]['place_id']) 450 | name = (results[1]['name']) 451 | # print(results[1]) 452 | # print(idnum) 453 | URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(idnum, key) 454 | r3 = requests.get(URL3) 455 | if r3.status_code == 200: 456 | second_output = r3.json() 457 | phone = (second_output['result'])['international_phone_number'] 458 | # print(second_output) 459 | # print(phone) 460 | session.attributes["State"] = "Null" 461 | message = """I've found a therapist near you. Their name is: {}, and their number is: {}. I've added their 462 | contact info to a card in the Alexa app. Is there anything else I can do?""".format(name,phone) 463 | card = "Name:{} \n Phone:{}".format(name,phone) 464 | return question(message).standard_card(title="I've found you a possible therapist", 465 | text=card, 466 | large_image_url="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80") 467 | else: 468 | return statement("Sorry, I'm having trouble doing that right now. Please try again later.") 469 | 470 | 471 | @ask.intent('AMAZON.StopIntent') 472 | def handle_stop(): 473 | """ 474 | This handles the 'stop' built-in intention. 475 | """ 476 | farewell_text = "Have a good day. I hope to hear from you soon." 477 | return statement(farewell_text) 478 | 479 | 480 | @ask.intent('AMAZON.CancelIntent') 481 | def handle_cancel(): 482 | """ 483 | This handles the 'cancel' built-in intention. 484 | """ 485 | farewell_text = "Goodbye" 486 | return statement(farewell_text) 487 | 488 | 489 | @ask.intent('AMAZON.HelpIntent') 490 | def handle_help(): 491 | """ 492 | This handles the 'help' built-in intention. 493 | 494 | """ 495 | 496 | help_text = """There's a few things I can do to help. I can recommend a therapist or offer a suggestion for 497 | a way to improve your mood. I also possess the capability to detect suicidal intentions, 498 | but I really hope that you won't need me to do that. """ 499 | return question(help_text) 500 | 501 | 502 | if __name__ == '__main__': 503 | app.run(debug=True, port=5000) 504 | -------------------------------------------------------------------------------- /Localization/UK/voice.py: -------------------------------------------------------------------------------- 1 | #### Credit to Cookiecutter Flask Ask for built-in intent functions 2 | 3 | from flask import Flask 4 | from flask_ask import Ask, statement, question, session 5 | from controller import welcome, re, condolences,ideas, get_alexa_location 6 | import geocoder 7 | import random 8 | import requests 9 | 10 | app = Flask(__name__) 11 | ask = Ask(app, '/') 12 | 13 | """ These functions handle what are essentially the beginning and end of the main use case of the skill.""" 14 | @ask.launch 15 | def start_session(): 16 | """ This function is what initializes the application. It calls the welcome() method from controller.py 17 | to generate a different welcome message each time """ 18 | welcome_text = welcome() 19 | welcome_re_text = re() 20 | 21 | return question(welcome_text).reprompt(welcome_re_text) 22 | 23 | 24 | def evaluate_answers(): 25 | """This function evaluates the user's answers to the questions the skill poses if "NegativeFeeling" is called. 26 | It evaluates the functions in order of usual routine. """ 27 | if session.attributes["Bed"] == "No": 28 | return "Okay, well let's start by getting out of bed. You can do it!" 29 | elif session.attributes["Eaten"] == "No": 30 | return "That's okay, but you should try to eat. You got this!" 31 | elif session.attributes["Showered"] == "No": 32 | return "Hmmm. Maybe you should take a nice, hot shower. It will help you feel better." 33 | elif session.attributes["Dressed"] == "No": 34 | return "Alright. Well let's try getting dressed. You can do it!" 35 | elif session.attributes["Outside"] == "No": 36 | return "Well let's try going outside. It might elate you. " 37 | else: 38 | return "Good job doing all those things. When you're depressed, those little things can be the most difficult" 39 | 40 | 41 | """These functions handle intent logic for the voice interface. """ 42 | 43 | # @ask.intent('StartReport') 44 | # def start_reporting(): 45 | # try: 46 | # if session.attributes['State'] == 'Startedreport': 47 | # return question("""Okay, please tell me the email address you would like the report sent to""") 48 | # elif session.attributes["State"] == "Question 0 Answered": 49 | # return question("""Okay, please tell me the email address you would like the report sent to""") 50 | # elif session.attributes["State"] == "Question 1 Answered": 51 | # return question("""Okay, please tell me the email address you would like the report sent to""") 52 | # else: 53 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 54 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 55 | # except: 56 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 57 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 58 | 59 | # @ask.intent('Email') 60 | # def get_name(email_address): 61 | # session.attributes["Email"] = email_address 62 | # return question("Okay, and what is your name?") 63 | # 64 | # @ask.intent('Name') 65 | # def finish_report(person_name): 66 | # message = "Okay, I've sent a report to {} about your day. Is there anything else I can do?" 67 | # return question(message) 68 | 69 | @ask.intent('PositiveFeeling') 70 | def user_feels_good(): 71 | """This function is triggered if the PositiveFeeling intent is detected. """ 72 | congrats = [ 73 | 'That is so good to hear!', 74 | 'I am happy you feel good today', 75 | 'I am glad to hear that.', 76 | 'Oh happy day!', 77 | 'Awesome.', 78 | 'Good to hear!', 79 | 'Wonderful!', 80 | 'Great!', 81 | 'I am so happy about that!' 82 | ] 83 | 84 | session.attributes["feeling"] = "Good" 85 | session.attributes["State"] = "Question 0 Answered" 86 | return question((random.choice(congrats)) + ' ' + 'Is there anything else you need? Want me to recommend a therapist?') 87 | 88 | @ask.intent('NegativeFeeling') 89 | def user_feels_bad(): 90 | """This function is triggered if the NegativeFeeling intent is detected. This also kicks off the question to guage 91 | whether the user has perfomed daily activities.""" 92 | condolence = condolences() 93 | session.attributes["feeling"] = "Down" 94 | session.attributes["State"] = "Question 1 Answered" 95 | return question(condolence + " " + "Have you gotten out of bed today?") 96 | 97 | """ The following functions are called depending on the user's answers.""" 98 | @ask.intent('BedYes') 99 | def out_of_bed(): 100 | message = random.choice([ 101 | 'Awesome.', 102 | 'Good to hear!', 103 | 'Wonderful!', 104 | 'Great!', 105 | ]) 106 | session.attributes["Bed"] = "Yes" 107 | session.attributes["State"] = "Question 2 Answered" 108 | return question (message + " " + "Have you eaten today?") 109 | 110 | @ask.intent('BedNo') 111 | def not_out_of_bed(): 112 | 113 | message = random.choice([ 114 | "That's too bad.", 115 | "That's okay, we all have days like that.", 116 | "I'm sorry. ", 117 | "That's too bad", 118 | "It's okay." 119 | ]) 120 | 121 | session.attributes["State"] = "Question 2 Answered" 122 | session.attributes["Bed"] = "No" 123 | return question(message + " " + "Have you eaten today?") 124 | 125 | 126 | @ask.intent('AteYes') 127 | def eaten(): 128 | message = random.choice([ 129 | 'Awesome.', 130 | 'Good to hear!', 131 | 'Wonderful!', 132 | 'Great!', 133 | ]) 134 | session.attributes["Eaten"] = "Yes" 135 | session.attributes["State"] = "Question 3 Answered" 136 | return question(message + " " + "Have you showered today?") 137 | 138 | @ask.intent('AteNo') 139 | def not_eaten(): 140 | message = random.choice([ 141 | "That's too bad.", 142 | "That's okay, we all have days like that.", 143 | "I'm sorry. ", 144 | "That's not good.", 145 | "It's okay." 146 | ]) 147 | 148 | session.attributes["Eaten"] = "No" 149 | session.attributes["State"] = "Question 3 Answered" 150 | return question(message + " " + "Have you showered today?") 151 | 152 | @ask.intent('ShowerYes') 153 | def showered(): 154 | message = random.choice([ 155 | 'Awesome.', 156 | 'Good to hear!', 157 | 'Wonderful!', 158 | 'Great!', 159 | ]) 160 | 161 | session.attributes["Showered"] = "Yes" 162 | session.attributes["State"] = "Question 4 Answered" 163 | return question(message + " " + "Have you gotten dressed?") 164 | 165 | @ask.intent('ShowerNo') 166 | def not_showered(): 167 | message = random.choice([ 168 | "That's too bad.", 169 | "That's okay, we all have days like that.", 170 | "I'm sorry. ", 171 | "That's not good.", 172 | "It's okay." 173 | ]) 174 | 175 | session.attributes["Showered"] = "No" 176 | session.attributes["State"] = "Question 4 Answered" 177 | return question(message + " " + "Have you gotten dressed?") 178 | 179 | @ask.intent('DressedYes') 180 | def dressed(): 181 | message = random.choice([ 182 | 'Awesome.', 183 | 'Good to hear!', 184 | 'Wonderful!', 185 | 'Great!', 186 | ]) 187 | 188 | session.attributes["Dressed"] = "Yes" 189 | session.attributes["State"] = "Question 5 Answered" 190 | return question(message + " " + "Have you gone outside at all today?") 191 | 192 | 193 | @ask.intent('DressedNo') 194 | def not_dressed(): 195 | message = random.choice([ 196 | "That's too bad.", 197 | "That's okay, we all have days like that.", 198 | "I'm sorry. ", 199 | "That's not good.", 200 | "It's okay." 201 | ]) 202 | 203 | session.attributes["Dressed"] = "No" 204 | session.attributes["State"] = "Question 5 Answered" 205 | return question(message + " " + "Have you gone outside at all today?") 206 | 207 | @ask.intent('OutsideYes') 208 | def outside(): 209 | message = random.choice([ 210 | 'Awesome.', 211 | 'Good to hear!', 212 | 'Wonderful!', 213 | 'Great!', 214 | ]) 215 | 216 | session.attributes["Outside"] = "Yes" 217 | session.attributes["State"] = "Suggested" 218 | response = evaluate_answers() 219 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 220 | suggestion_inquiry = "Let's try something else to improve your mood." 221 | else: 222 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 223 | idea = ideas() 224 | 225 | return statement(message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 226 | 227 | @ask.intent('OutsideNo') 228 | def not_outside(): 229 | message = random.choice([ 230 | "That's too bad.", 231 | "That's okay, we all have days like that.", 232 | "I'm sorry. ", 233 | "That's not good.", 234 | "It's okay." 235 | ]) 236 | 237 | session.attributes["Outside"] = "No" 238 | session.attributes["State"] = "Suggested" 239 | response = evaluate_answers() 240 | suggestion_inquiry = "Let's also try something else to improve your mood." 241 | idea = ideas() 242 | return question(message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 243 | 244 | """ The following functions handle the built-in Amazon intents based on the session state. """ 245 | @ask.intent('AMAZON.NoIntent') 246 | def handle_no(): 247 | try: 248 | if session.attributes["State"] == "Question 0 Answered": 249 | return statement("Okay. Check in with me again later!") 250 | elif session.attributes["State"] == "Question 1 Answered": 251 | message = random.choice([ 252 | "That's too bad.", 253 | "That's okay, we all have days like that.", 254 | "I'm sorry. ", 255 | "That's too bad", 256 | "It's okay." 257 | ]) 258 | 259 | session.attributes["State"] = "Question 2 Answered" 260 | session.attributes["Bed"] = "No" 261 | return question(message + " " + "Have you eaten today?") 262 | elif session.attributes["State"] == "Question 2 Answered": 263 | message = random.choice([ 264 | "That's too bad.", 265 | "That's okay, we all have days like that.", 266 | "I'm sorry. ", 267 | "That's not good.", 268 | "It's okay." 269 | ]) 270 | 271 | session.attributes["Eaten"] = "No" 272 | session.attributes["State"] = "Question 3 Answered" 273 | return question(message + " " + "Have you showered today?") 274 | elif session.attributes["State"] == "Question 3 Answered": 275 | message = random.choice([ 276 | "That's too bad.", 277 | "That's okay, we all have days like that.", 278 | "I'm sorry. ", 279 | "That's not good.", 280 | "It's okay." 281 | ]) 282 | 283 | session.attributes["Showered"] = "No" 284 | session.attributes["State"] = "Question 4 Answered" 285 | return question(message + " " + "Have you gotten dressed?") 286 | elif session.attributes["State"] == "Question 4 Answered": 287 | message = random.choice([ 288 | "That's too bad.", 289 | "That's okay, we all have days like that.", 290 | "I'm sorry. ", 291 | "That's not good.", 292 | "It's okay." 293 | ]) 294 | 295 | session.attributes["Dressed"] = "No" 296 | session.attributes["State"] = "Question 5 Answered" 297 | return question(message + " " + "Have you gone outside at all today?") 298 | elif session.attributes["State"] == "Question 5 Answered": 299 | message = random.choice([ 300 | "That's too bad.", 301 | "That's okay, we all have days like that.", 302 | "I'm sorry. ", 303 | "That's not good.", 304 | "It's okay." 305 | ]) 306 | 307 | session.attributes["Outside"] = "No" 308 | session.attributes["State"] = "Suggested" 309 | response = evaluate_answers() 310 | suggestion_inquiry = "Let's also try something else to improve your mood." 311 | idea = ideas() 312 | return question( 313 | message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Anything else I can do?") 314 | elif session.attributes["State"] == "Suggested": 315 | session.attributes["State"] = "AnythingElse" 316 | return question("Okay, I hope that helped. Anything else I can do for you?") 317 | elif session.attributes["State"] == "AnythingElse": 318 | return question("No problem. Check in with me later. Goodbye") 319 | else: 320 | return question("I'm sorry, I didn't get that. How are you feeling? ") 321 | except: 322 | return question("I'm sorry, I didn't get that. How are you feeling?") 323 | 324 | @ask.intent('AMAZON.YesIntent') 325 | def handle_yes(): 326 | try: 327 | if session.attributes["State"] == "Question 0 Answered": 328 | return question("Okay. What can I do for you?") 329 | 330 | elif session.attributes["State"] == "Question 1 Answered": 331 | message = random.choice([ 332 | 'Awesome.', 333 | 'Good to hear!', 334 | 'Wonderful!', 335 | 'Great!', 336 | ]) 337 | session.attributes["Bed"] = "Yes" 338 | session.attributes["State"] = "Question 2 Answered" 339 | return question(message + " " + "Have you eaten today?") 340 | 341 | elif session.attributes["State"] == "Question 2 Answered": 342 | message = random.choice([ 343 | 'Awesome.', 344 | 'Good to hear!', 345 | 'Wonderful!', 346 | 'Great!', 347 | ]) 348 | session.attributes["Eaten"] = "Yes" 349 | session.attributes["State"] = "Question 3 Answered" 350 | return question(message + " " + "Have you showered today?") 351 | 352 | elif session.attributes["State"] == "Question 3 Answered": 353 | message = random.choice([ 354 | 'Awesome.', 355 | 'Good to hear!', 356 | 'Wonderful!', 357 | 'Great!', 358 | ]) 359 | 360 | session.attributes["Showered"] = "Yes" 361 | session.attributes["State"] = "Question 4 Answered" 362 | return question(message + " " + "Have you gotten dressed?") 363 | 364 | elif session.attributes["State"] == "Question 4 Answered": 365 | message = random.choice([ 366 | 'Awesome.', 367 | 'Good to hear!', 368 | 'Wonderful!', 369 | 'Great!', 370 | ]) 371 | 372 | session.attributes["Dressed"] = "Yes" 373 | session.attributes["State"] = "Question 5 Answered" 374 | return question(message + " " + "Have you gone outside at all today?") 375 | 376 | elif session.attributes["State"] == "Question 5 Answered": 377 | message = random.choice([ 378 | 'Awesome.', 379 | 'Good to hear!', 380 | 'Wonderful!', 381 | 'Great!', 382 | ]) 383 | 384 | session.attributes["Outside"] = "Yes" 385 | session.attributes["State"] = "Suggested" 386 | response = evaluate_answers() 387 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 388 | suggestion_inquiry = "Let's try something else to improve your mood." 389 | else: 390 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 391 | idea = ideas() 392 | session.attributes["State"] = "AnythingElse" 393 | return question( 394 | message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Is there anything else I can do?") 395 | elif session.attributes["State"] == "Suggested": 396 | message = "Okay, here's another idea. " 397 | idea = ideas() 398 | session.attributes["State"] = "Suggested" 399 | return question( 400 | message + " " + idea + " " + "Would you like another suggestion?") 401 | elif session.attributes["State"] == "AnythingElse": 402 | return question("Okay, I love to help. What can I do for you? Say help if you would like to learn about my other capabilities.") 403 | else: 404 | return question("I'm sorry, I didn't get that. How are you feeling? ") 405 | except: 406 | return question("I'm sorry, I didn't get that. How are you feeling? ") 407 | 408 | """ The following functions handle the additional use cases of recommending a therapist, detecting and preventing suicide, and 409 | giving ideas on how to improve the user's mood.""" 410 | 411 | @ask.intent('SuggestIdea') 412 | def suggest_ideas(): 413 | suggestion_inquiry = "Okay. Here's an idea for an extra way to improve your mood." 414 | idea = ideas() 415 | session.attributes["State"] = "Suggested" 416 | return question(suggestion_inquiry + " " + idea + " " + "Would you like another suggestion?") 417 | 418 | @ask.intent('HotLine') 419 | def hot_line(): 420 | return statement("""Please don't hurt yourself or anyone else. I may just be a robot, but I 421 | was created by a person who wants to help you and thinks you are worth it. Please call the National Suicide 422 | Prevention Hotline at 1-800-273-8255. They are available to talk to you 24 hours a day, 7 days a week. 423 | I've placed their number on a card in your Alexa app for reference.""") \ 424 | .standard_card(title='National Suicide Prevention Hot Line', text='Call Now 1-800-273-8255 ', large_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Lifelinelogo.svg/1200px-Lifelinelogo.svg.png' ) 425 | 426 | @ask.intent('FindTherapist') 427 | def find_therapist(): 428 | """This function uses the Google Places API to recommend a therapist based on the user's location. """ 429 | keyword = "counseling OR therapist OR psychiatrist" 430 | try: 431 | address = get_alexa_location() 432 | pass 433 | except: 434 | return statement("""Hmm. It appears that I can't find your location. Please allow access to your " 435 | location in the Alexa app and try again """).consent_card("read::alexa:device:all:address") 436 | g = geocoder.google(address) 437 | latlng = g.latlng 438 | location = "{},{}".format(latlng[0], latlng[1]) 439 | print(location) 440 | key = "AIzaSyA1yY-DOHIun0v_7kTwa_U5Ah6Am-kcjCM" 441 | URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(location,keyword,key) 442 | print(URL2) 443 | r2 = requests.get(URL2) 444 | if r2.status_code == 200: 445 | first_output = r2.json() 446 | else: 447 | return "Sorry, I'm having trouble doing that right now. Please try again later." 448 | results = first_output['results'] 449 | idnum = (results[1]['place_id']) 450 | name = (results[1]['name']) 451 | # print(results[1]) 452 | # print(idnum) 453 | URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(idnum, key) 454 | r3 = requests.get(URL3) 455 | if r3.status_code == 200: 456 | second_output = r3.json() 457 | phone = (second_output['result'])['international_phone_number'] 458 | # print(second_output) 459 | # print(phone) 460 | session.attributes["State"] = "Null" 461 | message = """I've found a therapist near you. Their name is: {}, and their number is: {}. I've added their 462 | contact info to a card in the Alexa app. Is there anything else I can do?""".format(name,phone) 463 | card = "Name:{} \n Phone:{}".format(name,phone) 464 | return question(message).standard_card(title="I've found you a possible therapist", 465 | text=card, 466 | large_image_url="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80") 467 | else: 468 | return statement("Sorry, I'm having trouble doing that right now. Please try again later.") 469 | 470 | 471 | @ask.intent('AMAZON.StopIntent') 472 | def handle_stop(): 473 | """ 474 | This handles the 'stop' built-in intention. 475 | """ 476 | farewell_text = "Have a good day. I hope to hear from you soon." 477 | return statement(farewell_text) 478 | 479 | 480 | @ask.intent('AMAZON.CancelIntent') 481 | def handle_cancel(): 482 | """ 483 | This handles the 'cancel' built-in intention. 484 | """ 485 | farewell_text = "Goodbye" 486 | return statement(farewell_text) 487 | 488 | 489 | @ask.intent('AMAZON.HelpIntent') 490 | def handle_help(): 491 | """ 492 | This handles the 'help' built-in intention. 493 | 494 | """ 495 | 496 | help_text = """There's a few things I can do to help. I can recommend a therapist or offer a suggestion for 497 | a way to improve your mood. I also possess the capability to detect suicidal intentions, 498 | but I really hope that you won't need me to do that. """ 499 | return question(help_text) 500 | 501 | 502 | if __name__ == '__main__': 503 | app.run(debug=True, port=5000) 504 | -------------------------------------------------------------------------------- /Localization/Australia/voice.py: -------------------------------------------------------------------------------- 1 | #### Credit to Cookiecutter Flask Ask for built-in intent functions 2 | 3 | from flask import Flask 4 | from flask_ask import Ask, statement, question, session 5 | from controller import welcome, re, condolences,ideas, get_alexa_location 6 | import geocoder 7 | import random 8 | import requests 9 | 10 | app = Flask(__name__) 11 | ask = Ask(app, '/') 12 | 13 | """ These functions handle what are essentially the beginning and end of the main use case of the skill.""" 14 | @ask.launch 15 | def start_session(): 16 | """ This function is what initializes the application. It calls the welcome() method from controller.py 17 | to generate a different welcome message each time """ 18 | welcome_text = welcome() 19 | welcome_re_text = re() 20 | 21 | return question(welcome_text).reprompt(welcome_re_text) 22 | 23 | 24 | def evaluate_answers(): 25 | """This function evaluates the user's answers to the questions the skill poses if "NegativeFeeling" is called. 26 | It evaluates the functions in order of usual routine. """ 27 | if session.attributes["Bed"] == "No": 28 | return "Okay, well let's start by getting out of bed. You can do it!" 29 | elif session.attributes["Eaten"] == "No": 30 | return "That's okay, but you should try to eat. You got this!" 31 | elif session.attributes["Showered"] == "No": 32 | return "Hmmm. Maybe you should take a nice, hot shower. It will help you feel better." 33 | elif session.attributes["Dressed"] == "No": 34 | return "Alright. Well let's try getting dressed. You can do it!" 35 | elif session.attributes["Outside"] == "No": 36 | return "Well let's try going outside. It might elate you. " 37 | else: 38 | return "Good job doing all those things. When you're depressed, those little things can be the most difficult" 39 | 40 | 41 | """These functions handle intent logic for the voice interface. """ 42 | 43 | # @ask.intent('StartReport') 44 | # def start_reporting(): 45 | # try: 46 | # if session.attributes['State'] == 'Startedreport': 47 | # return question("""Okay, please tell me the email address you would like the report sent to""") 48 | # elif session.attributes["State"] == "Question 0 Answered": 49 | # return question("""Okay, please tell me the email address you would like the report sent to""") 50 | # elif session.attributes["State"] == "Question 1 Answered": 51 | # return question("""Okay, please tell me the email address you would like the report sent to""") 52 | # else: 53 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 54 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 55 | # except: 56 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 57 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 58 | 59 | # @ask.intent('Email') 60 | # def get_name(email_address): 61 | # session.attributes["Email"] = email_address 62 | # return question("Okay, and what is your name?") 63 | # 64 | # @ask.intent('Name') 65 | # def finish_report(person_name): 66 | # message = "Okay, I've sent a report to {} about your day. Is there anything else I can do?" 67 | # return question(message) 68 | 69 | @ask.intent('PositiveFeeling') 70 | def user_feels_good(): 71 | """This function is triggered if the PositiveFeeling intent is detected. """ 72 | congrats = [ 73 | 'That is so good to hear!', 74 | 'I am happy you feel good today', 75 | 'I am glad to hear that.', 76 | 'Oh happy day!', 77 | 'Awesome.', 78 | 'Good to hear!', 79 | 'Wonderful!', 80 | 'Great!', 81 | 'I am so happy about that!' 82 | ] 83 | 84 | session.attributes["feeling"] = "Good" 85 | session.attributes["State"] = "Question 0 Answered" 86 | return question((random.choice(congrats)) + ' ' + 'Is there anything else you need? Want me to recommend a therapist?') 87 | 88 | @ask.intent('NegativeFeeling') 89 | def user_feels_bad(): 90 | """This function is triggered if the NegativeFeeling intent is detected. This also kicks off the question to guage 91 | whether the user has perfomed daily activities.""" 92 | condolence = condolences() 93 | session.attributes["feeling"] = "Down" 94 | session.attributes["State"] = "Question 1 Answered" 95 | return question(condolence + " " + "Have you gotten out of bed today?") 96 | 97 | """ The following functions are called depending on the user's answers.""" 98 | @ask.intent('BedYes') 99 | def out_of_bed(): 100 | message = random.choice([ 101 | 'Awesome.', 102 | 'Good to hear!', 103 | 'Wonderful!', 104 | 'Great!', 105 | ]) 106 | session.attributes["Bed"] = "Yes" 107 | session.attributes["State"] = "Question 2 Answered" 108 | return question (message + " " + "Have you eaten today?") 109 | 110 | @ask.intent('BedNo') 111 | def not_out_of_bed(): 112 | 113 | message = random.choice([ 114 | "That's too bad.", 115 | "That's okay, we all have days like that.", 116 | "I'm sorry. ", 117 | "That's too bad", 118 | "It's okay." 119 | ]) 120 | 121 | session.attributes["State"] = "Question 2 Answered" 122 | session.attributes["Bed"] = "No" 123 | return question(message + " " + "Have you eaten today?") 124 | 125 | 126 | @ask.intent('AteYes') 127 | def eaten(): 128 | message = random.choice([ 129 | 'Awesome.', 130 | 'Good to hear!', 131 | 'Wonderful!', 132 | 'Great!', 133 | ]) 134 | session.attributes["Eaten"] = "Yes" 135 | session.attributes["State"] = "Question 3 Answered" 136 | return question(message + " " + "Have you showered today?") 137 | 138 | @ask.intent('AteNo') 139 | def not_eaten(): 140 | message = random.choice([ 141 | "That's too bad.", 142 | "That's okay, we all have days like that.", 143 | "I'm sorry. ", 144 | "That's not good.", 145 | "It's okay." 146 | ]) 147 | 148 | session.attributes["Eaten"] = "No" 149 | session.attributes["State"] = "Question 3 Answered" 150 | return question(message + " " + "Have you showered today?") 151 | 152 | @ask.intent('ShowerYes') 153 | def showered(): 154 | message = random.choice([ 155 | 'Awesome.', 156 | 'Good to hear!', 157 | 'Wonderful!', 158 | 'Great!', 159 | ]) 160 | 161 | session.attributes["Showered"] = "Yes" 162 | session.attributes["State"] = "Question 4 Answered" 163 | return question(message + " " + "Have you gotten dressed?") 164 | 165 | @ask.intent('ShowerNo') 166 | def not_showered(): 167 | message = random.choice([ 168 | "That's too bad.", 169 | "That's okay, we all have days like that.", 170 | "I'm sorry. ", 171 | "That's not good.", 172 | "It's okay." 173 | ]) 174 | 175 | session.attributes["Showered"] = "No" 176 | session.attributes["State"] = "Question 4 Answered" 177 | return question(message + " " + "Have you gotten dressed?") 178 | 179 | @ask.intent('DressedYes') 180 | def dressed(): 181 | message = random.choice([ 182 | 'Awesome.', 183 | 'Good to hear!', 184 | 'Wonderful!', 185 | 'Great!', 186 | ]) 187 | 188 | session.attributes["Dressed"] = "Yes" 189 | session.attributes["State"] = "Question 5 Answered" 190 | return question(message + " " + "Have you gone outside at all today?") 191 | 192 | 193 | @ask.intent('DressedNo') 194 | def not_dressed(): 195 | message = random.choice([ 196 | "That's too bad.", 197 | "That's okay, we all have days like that.", 198 | "I'm sorry. ", 199 | "That's not good.", 200 | "It's okay." 201 | ]) 202 | 203 | session.attributes["Dressed"] = "No" 204 | session.attributes["State"] = "Question 5 Answered" 205 | return question(message + " " + "Have you gone outside at all today?") 206 | 207 | @ask.intent('OutsideYes') 208 | def outside(): 209 | message = random.choice([ 210 | 'Awesome.', 211 | 'Good to hear!', 212 | 'Wonderful!', 213 | 'Great!', 214 | ]) 215 | 216 | session.attributes["Outside"] = "Yes" 217 | session.attributes["State"] = "Suggested" 218 | response = evaluate_answers() 219 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 220 | suggestion_inquiry = "Let's try something else to improve your mood." 221 | else: 222 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 223 | idea = ideas() 224 | 225 | return statement(message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 226 | 227 | @ask.intent('OutsideNo') 228 | def not_outside(): 229 | message = random.choice([ 230 | "That's too bad.", 231 | "That's okay, we all have days like that.", 232 | "I'm sorry. ", 233 | "That's not good.", 234 | "It's okay." 235 | ]) 236 | 237 | session.attributes["Outside"] = "No" 238 | session.attributes["State"] = "Suggested" 239 | response = evaluate_answers() 240 | suggestion_inquiry = "Let's also try something else to improve your mood." 241 | idea = ideas() 242 | return question(message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 243 | 244 | """ The following functions handle the built-in Amazon intents based on the session state. """ 245 | @ask.intent('AMAZON.NoIntent') 246 | def handle_no(): 247 | try: 248 | if session.attributes["State"] == "Question 0 Answered": 249 | return statement("Okay. Check in with me again later!") 250 | elif session.attributes["State"] == "Question 1 Answered": 251 | message = random.choice([ 252 | "That's too bad.", 253 | "That's okay, we all have days like that.", 254 | "I'm sorry. ", 255 | "That's too bad", 256 | "It's okay." 257 | ]) 258 | 259 | session.attributes["State"] = "Question 2 Answered" 260 | session.attributes["Bed"] = "No" 261 | return question(message + " " + "Have you eaten today?") 262 | elif session.attributes["State"] == "Question 2 Answered": 263 | message = random.choice([ 264 | "That's too bad.", 265 | "That's okay, we all have days like that.", 266 | "I'm sorry. ", 267 | "That's not good.", 268 | "It's okay." 269 | ]) 270 | 271 | session.attributes["Eaten"] = "No" 272 | session.attributes["State"] = "Question 3 Answered" 273 | return question(message + " " + "Have you showered today?") 274 | elif session.attributes["State"] == "Question 3 Answered": 275 | message = random.choice([ 276 | "That's too bad.", 277 | "That's okay, we all have days like that.", 278 | "I'm sorry. ", 279 | "That's not good.", 280 | "It's okay." 281 | ]) 282 | 283 | session.attributes["Showered"] = "No" 284 | session.attributes["State"] = "Question 4 Answered" 285 | return question(message + " " + "Have you gotten dressed?") 286 | elif session.attributes["State"] == "Question 4 Answered": 287 | message = random.choice([ 288 | "That's too bad.", 289 | "That's okay, we all have days like that.", 290 | "I'm sorry. ", 291 | "That's not good.", 292 | "It's okay." 293 | ]) 294 | 295 | session.attributes["Dressed"] = "No" 296 | session.attributes["State"] = "Question 5 Answered" 297 | return question(message + " " + "Have you gone outside at all today?") 298 | elif session.attributes["State"] == "Question 5 Answered": 299 | message = random.choice([ 300 | "That's too bad.", 301 | "That's okay, we all have days like that.", 302 | "I'm sorry. ", 303 | "That's not good.", 304 | "It's okay." 305 | ]) 306 | 307 | session.attributes["Outside"] = "No" 308 | session.attributes["State"] = "Suggested" 309 | response = evaluate_answers() 310 | suggestion_inquiry = "Let's also try something else to improve your mood." 311 | idea = ideas() 312 | return question( 313 | message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Anything else I can do?") 314 | elif session.attributes["State"] == "Suggested": 315 | session.attributes["State"] = "AnythingElse" 316 | return question("Okay, I hope that helped. Anything else I can do for you?") 317 | elif session.attributes["State"] == "AnythingElse": 318 | return question("No problem. Check in with me later. Goodbye") 319 | else: 320 | return question("I'm sorry, I didn't get that. How are you feeling? ") 321 | except: 322 | return question("I'm sorry, I didn't get that. How are you feeling?") 323 | 324 | @ask.intent('AMAZON.YesIntent') 325 | def handle_yes(): 326 | try: 327 | if session.attributes["State"] == "Question 0 Answered": 328 | return question("Okay. What can I do for you?") 329 | 330 | elif session.attributes["State"] == "Question 1 Answered": 331 | message = random.choice([ 332 | 'Awesome.', 333 | 'Good to hear!', 334 | 'Wonderful!', 335 | 'Great!', 336 | ]) 337 | session.attributes["Bed"] = "Yes" 338 | session.attributes["State"] = "Question 2 Answered" 339 | return question(message + " " + "Have you eaten today?") 340 | 341 | elif session.attributes["State"] == "Question 2 Answered": 342 | message = random.choice([ 343 | 'Awesome.', 344 | 'Good to hear!', 345 | 'Wonderful!', 346 | 'Great!', 347 | ]) 348 | session.attributes["Eaten"] = "Yes" 349 | session.attributes["State"] = "Question 3 Answered" 350 | return question(message + " " + "Have you showered today?") 351 | 352 | elif session.attributes["State"] == "Question 3 Answered": 353 | message = random.choice([ 354 | 'Awesome.', 355 | 'Good to hear!', 356 | 'Wonderful!', 357 | 'Great!', 358 | ]) 359 | 360 | session.attributes["Showered"] = "Yes" 361 | session.attributes["State"] = "Question 4 Answered" 362 | return question(message + " " + "Have you gotten dressed?") 363 | 364 | elif session.attributes["State"] == "Question 4 Answered": 365 | message = random.choice([ 366 | 'Awesome.', 367 | 'Good to hear!', 368 | 'Wonderful!', 369 | 'Great!', 370 | ]) 371 | 372 | session.attributes["Dressed"] = "Yes" 373 | session.attributes["State"] = "Question 5 Answered" 374 | return question(message + " " + "Have you gone outside at all today?") 375 | 376 | elif session.attributes["State"] == "Question 5 Answered": 377 | message = random.choice([ 378 | 'Awesome.', 379 | 'Good to hear!', 380 | 'Wonderful!', 381 | 'Great!', 382 | ]) 383 | 384 | session.attributes["Outside"] = "Yes" 385 | session.attributes["State"] = "Suggested" 386 | response = evaluate_answers() 387 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 388 | suggestion_inquiry = "Let's try something else to improve your mood." 389 | else: 390 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 391 | idea = ideas() 392 | session.attributes["State"] = "AnythingElse" 393 | return question( 394 | message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Is there anything else I can do?") 395 | elif session.attributes["State"] == "Suggested": 396 | message = "Okay, here's another idea. " 397 | idea = ideas() 398 | session.attributes["State"] = "Suggested" 399 | return question( 400 | message + " " + idea + " " + "Would you like another suggestion?") 401 | elif session.attributes["State"] == "AnythingElse": 402 | return question("Okay, I love to help. What can I do for you? Say help if you would like to learn about my other capabilities.") 403 | else: 404 | return question("I'm sorry, I didn't get that. How are you feeling? ") 405 | except: 406 | return question("I'm sorry, I didn't get that. How are you feeling? ") 407 | 408 | """ The following functions handle the additional use cases of recommending a therapist, detecting and preventing suicide, and 409 | giving ideas on how to improve the user's mood.""" 410 | 411 | @ask.intent('SuggestIdea') 412 | def suggest_ideas(): 413 | suggestion_inquiry = "Okay. Here's an idea for an extra way to improve your mood." 414 | idea = ideas() 415 | session.attributes["State"] = "Suggested" 416 | return question(suggestion_inquiry + " " + idea + " " + "Would you like another suggestion?") 417 | 418 | @ask.intent('HotLine') 419 | def hot_line(): 420 | return statement("""Please don't hurt yourself or anyone else. I may just be a robot, but I 421 | was created by a person who wants to help you and thinks you are worth it. Please call the National Suicide 422 | Prevention Hotline at 1-800-273-8255. They are available to talk to you 24 hours a day, 7 days a week. 423 | I've placed their number on a card in your Alexa app for reference.""") \ 424 | .standard_card(title='National Suicide Prevention Hot Line', text='Call Now 1-800-273-8255 ', large_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Lifelinelogo.svg/1200px-Lifelinelogo.svg.png' ) 425 | 426 | @ask.intent('FindTherapist') 427 | def find_therapist(): 428 | """This function uses the Google Places API to recommend a therapist based on the user's location. """ 429 | keyword = "counseling OR therapist OR psychiatrist" 430 | try: 431 | address = get_alexa_location() 432 | pass 433 | except: 434 | return statement("""Hmm. It appears that I can't find your location. Please allow access to your " 435 | location in the Alexa app and try again """).consent_card("read::alexa:device:all:address") 436 | g = geocoder.google(address) 437 | latlng = g.latlng 438 | location = "{},{}".format(latlng[0], latlng[1]) 439 | print(location) 440 | key = "AIzaSyA1yY-DOHIun0v_7kTwa_U5Ah6Am-kcjCM" 441 | URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(location,keyword,key) 442 | print(URL2) 443 | r2 = requests.get(URL2) 444 | if r2.status_code == 200: 445 | first_output = r2.json() 446 | else: 447 | return "Sorry, I'm having trouble doing that right now. Please try again later." 448 | results = first_output['results'] 449 | idnum = (results[1]['place_id']) 450 | name = (results[1]['name']) 451 | # print(results[1]) 452 | # print(idnum) 453 | URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(idnum, key) 454 | r3 = requests.get(URL3) 455 | if r3.status_code == 200: 456 | second_output = r3.json() 457 | phone = (second_output['result'])['international_phone_number'] 458 | # print(second_output) 459 | # print(phone) 460 | session.attributes["State"] = "Null" 461 | message = """I've found a therapist near you. Their name is: {}, and their number is: {}. I've added their 462 | contact info to a card in the Alexa app. Is there anything else I can do?""".format(name,phone) 463 | card = "Name:{} \n Phone:{}".format(name,phone) 464 | return question(message).standard_card(title="I've found you a possible therapist", 465 | text=card, 466 | large_image_url="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80") 467 | else: 468 | return statement("Sorry, I'm having trouble doing that right now. Please try again later.") 469 | 470 | 471 | @ask.intent('AMAZON.StopIntent') 472 | def handle_stop(): 473 | """ 474 | This handles the 'stop' built-in intention. 475 | """ 476 | farewell_text = "Have a good day. I hope to hear from you soon." 477 | return statement(farewell_text) 478 | 479 | 480 | @ask.intent('AMAZON.CancelIntent') 481 | def handle_cancel(): 482 | """ 483 | This handles the 'cancel' built-in intention. 484 | """ 485 | farewell_text = "Goodbye" 486 | return statement(farewell_text) 487 | 488 | 489 | @ask.intent('AMAZON.HelpIntent') 490 | def handle_help(): 491 | """ 492 | This handles the 'help' built-in intention. 493 | 494 | """ 495 | 496 | help_text = """There's a few things I can do to help. I can recommend a therapist or offer a suggestion for 497 | a way to improve your mood. I also possess the capability to detect suicidal intentions, 498 | but I really hope that you won't need me to do that. """ 499 | return question(help_text) 500 | 501 | 502 | if __name__ == '__main__': 503 | app.run(debug=True, port=5000) 504 | -------------------------------------------------------------------------------- /voice.py: -------------------------------------------------------------------------------- 1 | #### Credit to Cookiecutter Flask Ask for built-in intent functions 2 | 3 | from flask import Flask 4 | from flask_ask import Ask, statement, question, session 5 | from controller import welcome, re, condolences,ideas, get_alexa_location 6 | import geocoder 7 | import traceback 8 | import random 9 | import os 10 | import requests 11 | import logging 12 | 13 | logging.getLogger('flask_ask').setLevel(logging.DEBUG) 14 | 15 | app = Flask(__name__) 16 | ask = Ask(app, '/') 17 | 18 | """ These functions handle what are essentially the beginning and end of the main use case of the skill.""" 19 | @ask.launch 20 | def start_session(): 21 | """ This function is what initializes the application. It calls the welcome() method from controller.py 22 | to generate a different welcome message each time """ 23 | welcome_text = welcome() 24 | welcome_re_text = re() 25 | 26 | return question(welcome_text).reprompt(welcome_re_text) 27 | 28 | 29 | def evaluate_answers(): 30 | """This function evaluates the user's answers to the questions the skill poses if "NegativeFeeling" is called. 31 | It evaluates the functions in order of usual routine. """ 32 | if session.attributes["Bed"] == "No": 33 | return "Okay, well let's start by getting out of bed. You can do it!" 34 | elif session.attributes["Eaten"] == "No": 35 | return "That's okay, but you should try to eat. You got this!" 36 | elif session.attributes["Showered"] == "No": 37 | return "Hmmm. Maybe you should take a nice, hot shower. It will help you feel better." 38 | elif session.attributes["Dressed"] == "No": 39 | return "Alright. Well let's try getting dressed. You can do it!" 40 | elif session.attributes["Outside"] == "No": 41 | return "Well let's try going outside. It might elate you. " 42 | else: 43 | return "Good job doing all those things. When you're depressed, those little things can be the most difficult" 44 | 45 | 46 | """These functions handle intent logic for the voice interface. """ 47 | 48 | # @ask.intent('StartReport') 49 | # def start_reporting(): 50 | # try: 51 | # if session.attributes['State'] == 'Startedreport': 52 | # return question("""Okay, please tell me the email address you would like the report sent to""") 53 | # elif session.attributes["State"] == "Question 0 Answered": 54 | # return question("""Okay, please tell me the email address you would like the report sent to""") 55 | # elif session.attributes["State"] == "Question 1 Answered": 56 | # return question("""Okay, please tell me the email address you would like the report sent to""") 57 | # else: 58 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 59 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 60 | # except: 61 | # return question("""Okay, I can send a report for you. If you haven't told me how you feel, 62 | # tell me after this, otherwise tell me the email address you would like the report sent to""") 63 | 64 | # @ask.intent('Email') 65 | # def get_name(email_address): 66 | # session.attributes["Email"] = email_address 67 | # return question("Okay, and what is your name?") 68 | # 69 | # @ask.intent('Name') 70 | # def finish_report(person_name): 71 | # message = "Okay, I've sent a report to {} about your day. Is there anything else I can do?" 72 | # return question(message) 73 | 74 | @ask.intent('PositiveFeeling') 75 | def user_feels_good(): 76 | """This function is triggered if the PositiveFeeling intent is detected. """ 77 | congrats = [ 78 | 'That is so good to hear!', 79 | 'I am happy you feel good today', 80 | 'I am glad to hear that.', 81 | 'Oh happy day!', 82 | 'Awesome.', 83 | 'Good to hear!', 84 | 'Wonderful!', 85 | 'Great!', 86 | 'I am so happy about that!', 87 | 'That is so great!' 88 | ] 89 | 90 | session.attributes["feeling"] = "Good" 91 | session.attributes["State"] = "Question 0 Answered" 92 | return question((random.choice(congrats)) + ' ' + 'Is there anything else you need? Want me to recommend a therapist?') 93 | 94 | @ask.intent('NegativeFeeling') 95 | def user_feels_bad(): 96 | """This function is triggered if the NegativeFeeling intent is detected. This also kicks off the question to guage 97 | whether the user has perfomed daily activities.""" 98 | condolence = condolences() 99 | session.attributes["feeling"] = "Down" 100 | session.attributes["State"] = "Question 1 Answered" 101 | return question(condolence + " " + "Have you gotten out of bed today?") 102 | 103 | """ The following functions are called depending on the user's answers.""" 104 | @ask.intent('BedYes') 105 | def out_of_bed(): 106 | message = random.choice([ 107 | 'Awesome.', 108 | 'Good to hear!', 109 | 'Wonderful!', 110 | 'Great!', 111 | ]) 112 | session.attributes["Bed"] = "Yes" 113 | session.attributes["State"] = "Question 2 Answered" 114 | return question (message + " " + "Have you eaten today?") 115 | 116 | @ask.intent('BedNo') 117 | def not_out_of_bed(): 118 | 119 | message = random.choice([ 120 | "That's too bad.", 121 | "That's okay, we all have days like that.", 122 | "I'm sorry. ", 123 | "That's too bad", 124 | "It's okay." 125 | ]) 126 | 127 | session.attributes["State"] = "Question 2 Answered" 128 | session.attributes["Bed"] = "No" 129 | return question(message + " " + "Have you eaten today?") 130 | 131 | 132 | @ask.intent('AteYes') 133 | def eaten(): 134 | message = random.choice([ 135 | 'Awesome.', 136 | 'Good to hear!', 137 | 'Wonderful!', 138 | 'Great!', 139 | ]) 140 | session.attributes["Eaten"] = "Yes" 141 | session.attributes["State"] = "Question 3 Answered" 142 | return question(message + " " + "Have you showered today?") 143 | 144 | @ask.intent('AteNo') 145 | def not_eaten(): 146 | message = random.choice([ 147 | "That's too bad.", 148 | "That's okay, we all have days like that.", 149 | "I'm sorry. ", 150 | "That's not good.", 151 | "It's okay." 152 | ]) 153 | 154 | session.attributes["Eaten"] = "No" 155 | session.attributes["State"] = "Question 3 Answered" 156 | return question(message + " " + "Have you showered today?") 157 | 158 | @ask.intent('ShowerYes') 159 | def showered(): 160 | message = random.choice([ 161 | 'Awesome.', 162 | 'Good to hear!', 163 | 'Wonderful!', 164 | 'Great!', 165 | ]) 166 | 167 | session.attributes["Showered"] = "Yes" 168 | session.attributes["State"] = "Question 4 Answered" 169 | return question(message + " " + "Have you gotten dressed?") 170 | 171 | @ask.intent('ShowerNo') 172 | def not_showered(): 173 | message = random.choice([ 174 | "That's too bad.", 175 | "That's okay, we all have days like that.", 176 | "I'm sorry. ", 177 | "That's not good.", 178 | "It's okay." 179 | ]) 180 | 181 | session.attributes["Showered"] = "No" 182 | session.attributes["State"] = "Question 4 Answered" 183 | return question(message + " " + "Have you gotten dressed?") 184 | 185 | @ask.intent('DressedYes') 186 | def dressed(): 187 | message = random.choice([ 188 | 'Awesome.', 189 | 'Good to hear!', 190 | 'Wonderful!', 191 | 'Great!', 192 | ]) 193 | 194 | session.attributes["Dressed"] = "Yes" 195 | session.attributes["State"] = "Question 5 Answered" 196 | return question(message + " " + "Have you gone outside at all today?") 197 | 198 | 199 | @ask.intent('DressedNo') 200 | def not_dressed(): 201 | message = random.choice([ 202 | "That's too bad.", 203 | "That's okay, we all have days like that.", 204 | "I'm sorry. ", 205 | "That's not good.", 206 | "It's okay." 207 | ]) 208 | 209 | session.attributes["Dressed"] = "No" 210 | session.attributes["State"] = "Question 5 Answered" 211 | return question(message + " " + "Have you gone outside at all today?") 212 | 213 | @ask.intent('OutsideYes') 214 | def outside(): 215 | message = random.choice([ 216 | 'Awesome.', 217 | 'Good to hear!', 218 | 'Wonderful!', 219 | 'Great!', 220 | ]) 221 | 222 | session.attributes["Outside"] = "Yes" 223 | session.attributes["State"] = "Suggested" 224 | response = evaluate_answers() 225 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 226 | suggestion_inquiry = "Let's try something else to improve your mood." 227 | else: 228 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 229 | idea = ideas() 230 | 231 | return question(message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 232 | 233 | @ask.intent('OutsideNo') 234 | def not_outside(): 235 | message = random.choice([ 236 | "That's too bad.", 237 | "That's okay, we all have days like that.", 238 | "I'm sorry. ", 239 | "That's not good.", 240 | "It's okay." 241 | ]) 242 | 243 | session.attributes["Outside"] = "No" 244 | session.attributes["State"] = "Suggested" 245 | response = evaluate_answers() 246 | suggestion_inquiry = "Let's also try something else to improve your mood." 247 | idea = ideas() 248 | return question(message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Would you like another suggestion?") 249 | 250 | """ The following functions handle the built-in Amazon intents based on the session state. """ 251 | @ask.intent('AMAZON.NoIntent') 252 | def handle_no(): 253 | try: 254 | if session.attributes["State"] == "Question 0 Answered": 255 | return statement("Okay. Check in with me again later!") 256 | elif session.attributes["State"] == "Question 1 Answered": 257 | message = random.choice([ 258 | "That's too bad.", 259 | "That's okay, we all have days like that.", 260 | "I'm sorry. ", 261 | "That's too bad", 262 | "It's okay." 263 | ]) 264 | 265 | session.attributes["State"] = "Question 2 Answered" 266 | session.attributes["Bed"] = "No" 267 | return question(message + " " + "Have you eaten today?") 268 | elif session.attributes["State"] == "Question 2 Answered": 269 | message = random.choice([ 270 | "That's too bad.", 271 | "That's okay, we all have days like that.", 272 | "I'm sorry. ", 273 | "That's not good.", 274 | "It's okay." 275 | ]) 276 | 277 | session.attributes["Eaten"] = "No" 278 | session.attributes["State"] = "Question 3 Answered" 279 | return question(message + " " + "Have you showered today?") 280 | elif session.attributes["State"] == "Question 3 Answered": 281 | message = random.choice([ 282 | "That's too bad.", 283 | "That's okay, we all have days like that.", 284 | "I'm sorry. ", 285 | "That's not good.", 286 | "It's okay." 287 | ]) 288 | 289 | session.attributes["Showered"] = "No" 290 | session.attributes["State"] = "Question 4 Answered" 291 | return question(message + " " + "Have you gotten dressed?") 292 | elif session.attributes["State"] == "Question 4 Answered": 293 | message = random.choice([ 294 | "That's too bad.", 295 | "That's okay, we all have days like that.", 296 | "I'm sorry. ", 297 | "That's not good.", 298 | "It's okay." 299 | ]) 300 | 301 | session.attributes["Dressed"] = "No" 302 | session.attributes["State"] = "Question 5 Answered" 303 | return question(message + " " + "Have you gone outside at all today?") 304 | elif session.attributes["State"] == "Question 5 Answered": 305 | message = random.choice([ 306 | "That's too bad.", 307 | "That's okay, we all have days like that.", 308 | "I'm sorry. ", 309 | "That's not good.", 310 | "It's okay." 311 | ]) 312 | 313 | session.attributes["Outside"] = "No" 314 | session.attributes["State"] = "Suggested" 315 | response = evaluate_answers() 316 | suggestion_inquiry = "Let's also try something else to improve your mood." 317 | idea = ideas() 318 | return question( 319 | message + " " + response + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Anything else I can do?") 320 | elif session.attributes["State"] == "Suggested": 321 | session.attributes["State"] = "AnythingElse" 322 | return question("Okay, I hope that helped. Anything else I can do for you?") 323 | elif session.attributes["State"] == "AnythingElse": 324 | return statement("No problem. Check in with me later. Goodbye") 325 | else: 326 | return question("I'm sorry, I didn't get that. How are you feeling? ") 327 | except: 328 | return question("I'm sorry, I didn't get that. How are you feeling?") 329 | 330 | @ask.intent('AMAZON.YesIntent') 331 | def handle_yes(): 332 | try: 333 | if session.attributes["State"] == "Question 0 Answered": 334 | return question("Okay. What can I do for you?") 335 | 336 | elif session.attributes["State"] == "Question 1 Answered": 337 | message = random.choice([ 338 | 'Awesome.', 339 | 'Good to hear!', 340 | 'Wonderful!', 341 | 'Great!', 342 | ]) 343 | session.attributes["Bed"] = "Yes" 344 | session.attributes["State"] = "Question 2 Answered" 345 | return question(message + " " + "Have you eaten today?") 346 | 347 | elif session.attributes["State"] == "Question 2 Answered": 348 | message = random.choice([ 349 | 'Awesome.', 350 | 'Good to hear!', 351 | 'Wonderful!', 352 | 'Great!', 353 | ]) 354 | session.attributes["Eaten"] = "Yes" 355 | session.attributes["State"] = "Question 3 Answered" 356 | return question(message + " " + "Have you showered today?") 357 | 358 | elif session.attributes["State"] == "Question 3 Answered": 359 | message = random.choice([ 360 | 'Awesome.', 361 | 'Good to hear!', 362 | 'Wonderful!', 363 | 'Great!', 364 | ]) 365 | 366 | session.attributes["Showered"] = "Yes" 367 | session.attributes["State"] = "Question 4 Answered" 368 | return question(message + " " + "Have you gotten dressed?") 369 | 370 | elif session.attributes["State"] == "Question 4 Answered": 371 | message = random.choice([ 372 | 'Awesome.', 373 | 'Good to hear!', 374 | 'Wonderful!', 375 | 'Great!', 376 | ]) 377 | 378 | session.attributes["Dressed"] = "Yes" 379 | session.attributes["State"] = "Question 5 Answered" 380 | return question(message + " " + "Have you gone outside at all today?") 381 | 382 | elif session.attributes["State"] == "Question 5 Answered": 383 | message = random.choice([ 384 | 'Awesome.', 385 | 'Good to hear!', 386 | 'Wonderful!', 387 | 'Great!', 388 | ]) 389 | 390 | session.attributes["Outside"] = "Yes" 391 | session.attributes["State"] = "Suggested" 392 | response = evaluate_answers() 393 | if response == "Good job doing all those things. When you're depressed, those little things can be the most difficult.": 394 | suggestion_inquiry = "Let's try something else to improve your mood." 395 | else: 396 | suggestion_inquiry = "Here's an idea for an extra way to improve your mood." 397 | idea = ideas() 398 | session.attributes["State"] = "AnythingElse" 399 | return question( 400 | message + " " + suggestion_inquiry + " " + idea + " " + "I hope I could help. Is there anything else I can do?") 401 | elif session.attributes["State"] == "Suggested": 402 | message = "Okay, here's another idea. " 403 | idea = ideas() 404 | session.attributes["State"] = "Suggested" 405 | return question( 406 | message + " " + idea + " " + "Would you like another suggestion?") 407 | elif session.attributes["State"] == "AnythingElse": 408 | return question("Okay, I love to help. What can I do for you? Say help if you would like to learn about my other capabilities.") 409 | else: 410 | return question("I'm sorry, I didn't get that. How are you feeling? ") 411 | except: 412 | return question("I'm sorry, I didn't get that. How are you feeling? ") 413 | 414 | """ The following functions handle the additional use cases of recommending a therapist, detecting and preventing suicide, and 415 | giving ideas on how to improve the user's mood.""" 416 | 417 | @ask.intent('SuggestIdea') 418 | def suggest_ideas(): 419 | suggestion_inquiry = "Okay. Here's an idea for an extra way to improve your mood." 420 | idea = ideas() 421 | session.attributes["State"] = "Suggested" 422 | return question(suggestion_inquiry + " " + idea + " " + "Would you like another suggestion?") 423 | 424 | @ask.intent('HotLine') 425 | def hot_line(): 426 | return statement("""Please don't hurt yourself or anyone else. I may just be a robot, but I 427 | was created by a person who wants to help you and thinks you are worth it. Please call the National Suicide 428 | Prevention Hotline at 1-800-273-8255. They are available to talk to you 24 hours a day, 7 days a week. 429 | I've placed their number on a card in your Alexa app for reference.""") \ 430 | .standard_card(title='National Suicide Prevention Hot Line', text='Call Now 1-800-273-8255 ', large_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Lifelinelogo.svg/1200px-Lifelinelogo.svg.png' ) 431 | 432 | @ask.intent('FindTherapist') 433 | def find_therapist(): 434 | """This function uses the Google Places API to recommend a therapist based on the user's location. """ 435 | keyword = "counseling OR therapist OR psychiatrist" 436 | try: 437 | address = get_alexa_location() 438 | logging.debug(address) 439 | pass 440 | except: 441 | logging.error("COULD NOT GET ALEXA LOCATION") 442 | logging.debug(traceback.format_exc()) 443 | return statement("""Hmm. It appears that I can't find your location. Please allow access to your 444 | location in the Alexa app and try again """).consent_card("read::alexa:device:all:address") 445 | try: 446 | gcodeurl = 'https://maps.googleapis.com/maps/api/geocode/json' 447 | params = {'sensor': 'false', 'address': address} 448 | gc = requests.get(gcodeurl, params=params, verify=False) 449 | results = gc.json()['results'] 450 | location = results[0]['geometry']['location'] 451 | location = "{},{}".format(location['lat'], location['lng']) 452 | except: 453 | logging.error('ERROR using google geocoder') 454 | logging.debug(gc.json()) 455 | return statement("Sorry, I'm having trouble doing that right now. Please try again later.") 456 | print(location) 457 | key = os.environ['GCLOUD_KEY'] 458 | URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(location,keyword,key) 459 | print(URL2) 460 | r2 = requests.get(URL2, verify=False) 461 | if r2.status_code == 200: 462 | first_output = r2.json() 463 | else: 464 | return "Sorry, I'm having trouble doing that right now. Please try again later." 465 | results = first_output['results'] 466 | idnum = (results[1]['place_id']) 467 | name = (results[1]['name']) 468 | # print(results[1]) 469 | # print(idnum) 470 | URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(idnum, key) 471 | r3 = requests.get(URL3, verify=False) 472 | if r3.status_code == 200: 473 | second_output = r3.json() 474 | phone = (second_output['result'])['international_phone_number'] 475 | # print(second_output) 476 | # print(phone) 477 | session.attributes["State"] = "Null" 478 | message = """I've found a therapist near you. 479 | Their name is: {}, and their number is: {}. I've added their contact info to a card in the Alexa app. 480 | Is there anything else I can do?""".format(name,phone) 481 | card = "Name:{} \n Phone:{}".format(name,phone) 482 | return question(message).standard_card(title="I've found you a possible therapist", 483 | text=card, 484 | large_image_url="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80") 485 | else: 486 | return statement("Sorry, I'm having trouble doing that right now. Please try again later.") 487 | 488 | 489 | @ask.intent('AMAZON.StopIntent') 490 | def handle_stop(): 491 | """ 492 | This handles the 'stop' built-in intention. 493 | """ 494 | farewell_text = "Have a good day. I hope to hear from you soon." 495 | return statement(farewell_text) 496 | 497 | 498 | @ask.intent('AMAZON.CancelIntent') 499 | def handle_cancel(): 500 | """ 501 | This handles the 'cancel' built-in intention. 502 | """ 503 | farewell_text = "Goodbye" 504 | return statement(farewell_text) 505 | 506 | 507 | @ask.intent('AMAZON.HelpIntent') 508 | def handle_help(): 509 | """ 510 | This handles the 'help' built-in intention. 511 | 512 | """ 513 | 514 | help_text = """There's a few things I can do to help. I can recommend a therapist or offer a suggestion for 515 | a way to improve your mood. I also possess the capability to detect suicidal intentions, 516 | but I really hope that you won't need me to do that. """ 517 | return question(help_text) 518 | 519 | 520 | if __name__ == '__main__': 521 | app.run(debug=True, port=5000) 522 | --------------------------------------------------------------------------------