async handle()

in alexa/lambda/lib/functions/aws-sap-alexa-scp-solo/index.js [101:141]


    async handle(handlerInput) {
        var speakOutput = 'Error creating contact. Please check logs'
        try{
            const firstName = handlerInput.requestEnvelope.request.intent.slots.FirstName.value
            const lastName = handlerInput.requestEnvelope.request.intent.slots.LastName.value
            const customer = handlerInput.requestEnvelope.request.intent.slots.Customer.value
            var path = '/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/ContactSet'
            var csrftoken = await getCsrfToken(handlerInput)
            var body = {
                "BusinessPartnerID" : customer,
                "FirstName" : firstName,
                "LastName" : lastName,
                "Sex" : "M",
                "EmailAddress" : "sap-on-aws@amazon.com",
                "PhoneNumber" : "555-555-5555",
	                "Address" : {
		            "Building" : "1800",
		            "Street" : "Terry Avenue",
		            "City" : "Seattle",
		            "PostalCode" : "98101",
		            "Country" : "US",
		            "AddressType" : "02"
	            }
            }
            var path = '/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/ContactSet'
            var response = await getDataFromSAP(handlerInput,path,'POST',body,csrftoken,'application/json')
            console.log('Response contact creation ' , response)
            speakOutput = 'Error creating contact. Please check your logs'
            try{
                var contactGuid = response.d.ContactGuid
                speakOutput = 'Contact successfully created'
            }catch(err){}
        }catch(e){
            console.log('Error is ', e.message)
            speakOutput = 'Error creating contact. Please check logs'
        }
        return handlerInput.responseBuilder
                .speak(speakOutput)
                .reprompt(speakOutput)
                .getResponse();
    }