Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def order_Tuna(intent_request):
- dynamo = boto3.resource('dynamodb')
- table = dynamo.Table('delivery_order')
- recordId = str(uuid.uuid4())
- location = try_ex(lambda: intent_request['currentIntent']['slots']['address'])
- Tuna = try_ex(lambda: intent_request['currentIntent']['slots']['Fast'])
- quantity = safe_int(try_ex(lambda: intent_request['currentIntent']['slots']['number']))
- uid = try_ex(lambda: intent_request['userId'])
- eid = try_ex(lambda: intent_request['currentIntent']['slots']['email'])
- session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
- # Load confirmation history and track the current reservation.
- reservation = json.dumps({
- 'ReservationType': 'Tuna',
- 'address': location,
- 'number': quantity,
- 'Fast': Tuna,
- 'Email':eid
- })
- session_attributes['currentReservation'] = reservation
- if intent_request['invocationSource'] == 'DialogCodeHook':
- # Validate any slots which have been specified. If any are invalid, re-elicit for their value
- validation_result = validate_Tuna(intent_request['currentIntent']['slots'])
- if not validation_result['isValid']:
- slots = intent_request['currentIntent']['slots']
- slots[validation_result['violatedSlot']] = None
- return elicit_slot(
- session_attributes,
- intent_request['currentIntent']['name'],
- slots,
- validation_result['violatedSlot'],
- validation_result['message'],
- build_response_card(
- 'Specify {}'.format(validation_result['violatedSlot']),
- build_options(validation_result['violatedSlot'], Tuna)
- )
- )
- # Otherwise, let native DM rules determine how to elicit for slots and prompt for confirmation. Pass price
- # back in sessionAttributes once it can be calculated; otherwise clear any setting from sessionAttributes.
- if location and quantity and Tuna :
- price = quantity*11
- session_attributes['currentReservationPrice'] = price
- else:
- try_ex(lambda: session_attributes.pop('currentReservationPrice'))
- session_attributes['currentReservation'] = reservation
- return delegate(session_attributes, intent_request['currentIntent']['slots'])
- logger.debug('orderTuna under={}'.format(reservation))
- try_ex(lambda: session_attributes.pop('currentReservationPrice'))
- try_ex(lambda: session_attributes.pop('currentReservation'))
- session_attributes['lastConfirmedReservation'] = reservation
- DynamoDict = {
- 'id': recordId,
- 'item': Tuna,
- 'quantity': quantity,
- 'address': location,
- 'price': quantity*11,
- 'emailId': eid
- }
- table.put_item(Item=DynamoDict)
- ses = boto3.client('ses')
- email_from = 'bhushansainidss.1@gmail.com'
- email_to = '{}'.format(eid)
- email_cc = 'Email'
- emaiL_subject = 'Subject'
- email_body = 'Body'
- pr='Order Id : {}\nYour order for {} {} of {} dollars at {} has been placed and it will be delivered within 30 mins.\nThanks for ordering your meal.\n Have a nice day.'.format(recordId,quantity,Tuna,quantity*11,location)
- response = ses.send_email(
- Source = email_from,
- Destination={
- 'ToAddresses': [
- email_to,
- ]
- },
- Message={
- 'Subject': {
- 'Data': 'ORDER CONFIRMATION FROM BOT-the-CAFE'
- },
- 'Body': {
- 'Text': {
- 'Data': pr
- }
- }
- }
- )
- return close(
- session_attributes,
- 'Fulfilled',
- {
- 'contentType': 'PlainText',
- 'content': 'Thanks, I have placed your order and your order ID is {}. It will be delivered before 30 minutes. Please let me know if you would like to order some Beverages and if you want to continue with this order then type utterances like : i want some beverages , i am thirsty, i want a drink '.format(
- recordId
- )
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement