Notifications.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:jessy 作者: jessy-project 项目源码 文件源码
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 = facebook.GraphAPI(oauth_access_token)

    try:
        results = graph.request("me/notifications")
    except facebook.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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号