Ejemplo n.º 1
0
def deal_with_it(intent_request):
    logger.info(intent_request)

    response = unirest.get(SENTIMENT_ANALYSIS_API.format(
        urllib.quote_plus(intent_request['inputTranscript'])),
                           headers={
                               'X-Mashape-Key': os.environ['MASHAPE_API_KEY'],
                               'Accept': 'application/json'
                           })
    sentiment_type = response.body['type']
    if sentiment_type == 'positive':
        return close_with_response_card(
            intent_request['sessionAttributes'], 'Fulfilled',
            'And, you, YOU are amazing!', '<3 <3 <3', None,
            'https://s3.amazonaws.com/shakirachatbot/gifs/dealwithit_p.gif',
            'https://s3.amazonaws.com/shakirachatbot/gifs/dealwithit_p.gif')
    elif sentiment_type == 'neutral':
        return close(intent_request['sessionAttributes'], 'Fulfilled',
                     'Bah, ok, whatever ;)')
    elif sentiment_type == 'negative':
        return close_with_response_card(
            intent_request['sessionAttributes'], 'Fulfilled',
            'That\'s a pity :/ ...nah, I KNOW I\'m pretty amazing!',
            '#DealWithIt', None,
            'https://s3.amazonaws.com/shakirachatbot/gifs/dealwithit_n.gif',
            'https://s3.amazonaws.com/shakirachatbot/gifs/dealwithit_n.gif')
Ejemplo n.º 2
0
def about_song(intent_request):
    logger.info(intent_request)

    slots = get_slots(intent_request)
    song_slot = slots['song']

    if song_slot is None:
        return elicit_slot(intent_request['sessionAttributes'],
                           intent_request['currentIntent']['name'], slots,
                           'song', 'About what song do you want to know?')

    song = [s for s in fetch_songs() if song_slot.lower() in s.lower()][0]
    output_session_attributes = intent_request[
        'sessionAttributes'] if intent_request[
            'sessionAttributes'] is not None else {}
    album_name = find_album_by_song(song)
    album = find_album_by_name(album_name)
    response = song + ' is part of the album ' + album_name + ' which was released on ' + album[
        'release_date'].strftime('%A %d of %B of %Y') + '.'
    output_session_attributes['song'] = song
    return close(output_session_attributes, 'Fulfilled', response)
Ejemplo n.º 3
0
def when_concert(intent_request):
    logger.info(intent_request)

    slots = get_slots(intent_request)
    location_slot = slots['location']

    if location_slot is None:
        return elicit_slot(intent_request['sessionAttributes'],
                           intent_request['currentIntent']['name'], slots,
                           'location', 'In which city / venue?')

    locations = [
        s for s in fetch_concert_locations()
        if location_slot.lower() in s.lower()
    ]
    response = format_concerts(location_slot, locations)
    if 'ElicitSlot' in response:
        return elicit_slot(intent_request['sessionAttributes'],
                           intent_request['currentIntent']['name'], slots,
                           'location', response['ElicitSlot'])
    elif 'Close' in response:
        return close(intent_request['sessionAttributes'], 'Fulfilled',
                     response['Close'])
Ejemplo n.º 4
0
def about_album(intent_request):
    logger.info(intent_request)

    slots = get_slots(intent_request)
    album_slot = slots['album']

    if album_slot is None:
        return elicit_slot(
            intent_request['sessionAttributes'],
            intent_request['currentIntent']['name'], slots, 'album',
            'Ok, of what album do you want me to enlighten you?')
    albums = [s for s in fetch_albums() if album_slot.lower() in s.lower()]

    if len(albums) == 0:
        response = 'I\'m so sorry, I don\'t think she has an album ' + str(
            album_slot) + '.'
    else:
        album_name = albums[0]
        album = find_album_by_name(album_name)
        response = album_name + ' was released on ' + album[
            'release_date'].strftime(
                '%A %d of %B of %Y') + '. Its songs are: \n* ' + '\n* '.join(
                    album['songs'])
    return close(intent_request['sessionAttributes'], 'Fulfilled', response)
Ejemplo n.º 5
0
def thanks(intent_request):
    logger.info(intent_request)

    return close(intent_request['sessionAttributes'], 'Fulfilled',
                 'Anytime gorgeous! :3')
Ejemplo n.º 6
0
def helper(intent_request):
    logger.info(intent_request)

    return close(intent_request['sessionAttributes'], 'Fulfilled',
                 secure_random.choice(HELPER_RESPONSES))
Ejemplo n.º 7
0
def greeting(intent_request):
    logger.info(intent_request)

    return close(intent_request['sessionAttributes'], 'Fulfilled',
                 'Hello! :D, if in doubt on what to ask, type: examples')