diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-03-30 16:03:44 -0400 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-03-30 16:03:44 -0400 |
| commit | d31fabf8cff5dae02e3fc759a4203bd374dddc99 (patch) | |
| tree | 888ec4e6d98154f862a3b9cd17a3394b657bc02e /client/modules/Notifications.py | |
| parent | 4182b5e096e081158dddd4ad5d031af94fcc63de (diff) | |
| download | jasper-client-d31fabf8cff5dae02e3fc759a4203bd374dddc99.tar.gz jasper-client-d31fabf8cff5dae02e3fc759a4203bd374dddc99.zip | |
Initial commit
Diffstat (limited to 'client/modules/Notifications.py')
| -rw-r--r-- | client/modules/Notifications.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/client/modules/Notifications.py b/client/modules/Notifications.py new file mode 100644 index 0000000..fc91da1 --- /dev/null +++ b/client/modules/Notifications.py @@ -0,0 +1,55 @@ +import re +from facebook import * + + +WORDS = ["FACEBOOK", "NOTIFICATION"] + + +def handle(text, mic, profile): + """ + Responds to user-input, typically speech text, with a summary of + the user's Facebook notifications, including a count and details + related to each individual notification. + + Arguments: + text -- user-input, typically transcribed speech + mic -- used to interact with the user (for both input and output) + profile -- contains information related to the user (e.g., phone number) + """ + oauth_access_token = profile['keys']['FB_TOKEN'] + + graph = GraphAPI(oauth_access_token) + + try: + results = graph.request("me/notifications") + except GraphAPIError: + mic.say( + "I have not been authorized to query your Facebook. If you would like to check your notifications in the future, please visit the Jasper dashboard.") + return + except: + mic.say( + "I apologize, there's a problem with that service at the moment.") + + if not len(results['data']): + mic.say("You have no Facebook notifications. ") + return + + updates = [] + for notification in results['data']: + updates.append(notification['title']) + + count = len(results['data']) + mic.say("You have " + str(count) + + " Facebook notifications. " + " ".join(updates) + ". ") + + return + + +def isValid(text): + """ + Returns True if the input is related to Facebook notifications. + + Arguments: + text -- user-input, typically transcribed speech + """ + return bool(re.search(r'\bnotification|Facebook\b', text, re.IGNORECASE)) |
