in lambda_functions/queue_immediate.py [0:0]
def queue_message(intent, session):
card_title = intent['name']
session_attributes = {}
should_end_session = False
reprompt_text = 'Excuse me?'
if 'person' in intent['slots'] and 'message' in intent['slots']:
if 'voice' in intent['slots']:
voice = str(intent['slots']['voice']['value'])
else:
voice = 'Joanna'
person = str(intent['slots']['person']['value']).lower()
name = intent['slots']['message']['value']
dt = arrow.utcnow()
pm = PersonManager()
p = pm.get_person(person)
lm = LibraryManager()
m = lm.get_message(Name=name)
if not p:
logging.error('{} does not have an entry in the '
'Person table . . .'.format(person))
speech_output = "Sorry, I don't know the name {}" \
.format(person)
should_end_session = True
elif not m:
logging.error('There is no message named {}'.format(name))
speech_output = "Sorry, I don't have a message named {}" \
.format(name)
should_end_session = True
elif p.all_available_count(dt) == 0:
logging.error('No locations are available for {}'.format(person))
speech_output = "Sorry, there are no locations for {}" \
.format(name)
should_end_session = True
else:
active_window = p.all_available(dt)[0]
mm = MessageManager(LocationName=active_window.location_name)
speech_output = "Got it. Publishing message {} to {} at " \
"location {}".format(name,
person,
active_window.location_name)
mm.publish_message(Body=m['message'],
PersonName=person,
Voice=voice)
should_end_session = True
else:
logging.error('Missing person or message')
speech_output = 'Person or message name is missing. Please try again'
should_end_session = True
return build_response(session_attributes, build_speechlet_response(
card_title, speech_output, reprompt_text, should_end_session))