Last active
January 27, 2025 10:20
-
-
Save SamWSoftware/afb04ec22d401902d6d0aefbcb9749e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ConnectContactFlowEvent, Handler } from 'aws-lambda'; | |
import { invokeBedrock } from '../../commonUtils/bedrock'; | |
import { | |
submitServiceRequest, | |
getMeterAddress, | |
getMeterIssueId, | |
} from '../../commonUtils/311Api'; | |
interface ParkingMeterEvent { | |
meterId: string; | |
issue_description?: string; | |
issueId?: string; | |
parkingMeterAttempts?: string; | |
} | |
interface ParkingMeterResponse { | |
hasSumbittedTicket: 'true' | 'false'; | |
transferToAgent: 'true' | 'false'; | |
parkingMeterAttempts?: number; | |
'get-customer-input-prompt'?: string; | |
serviceRequestId?: string; | |
readOutServiceRequestId?: string; | |
} | |
export const handler: Handler = async ( | |
event: ConnectContactFlowEvent | |
): Promise<ParkingMeterResponse> => { | |
const { meterId, issue_description, parkingMeterAttempts, issueId } = | |
event.Details.ContactData?.Attributes || ({} as ParkingMeterEvent); | |
const { FullAddress, error = meterAddressError } = await getMeterAddress({ | |
meterId, | |
}); | |
if (meterAddressError) { | |
if (parkingMeterAttempts && parkingMeterAttempts >= 2) { | |
return { | |
...meterAddressError, | |
transferToAgent: 'true', | |
parkingMeterAttempts: parkingMeterAttempts + 1, | |
}; | |
} | |
return { | |
...meterAddressError, | |
transferToAgent: 'false', | |
parkingMeterAttempts: parkingMeterAttempts + 1, | |
}; | |
} | |
const meterIssueId = await getMeterIssueId({ issueId, issue_description }); | |
if (!FullAddress OR !meterId OR !meterIssueId) { | |
throw new Error( | |
'Missing required parameters: FullAddress, meterId, or meterIssueId' | |
); | |
} | |
try { | |
const result = await submitServiceRequest({ | |
attributes: { | |
service_code: 'S0276', | |
address_string: FullAddress, | |
'attribute[WHISPAMN][]': meterId, | |
'attribute[WHISDORN][]': meterIssueId, | |
}, | |
}); | |
const readOutServiceRequestId = `I've submitted the ticket about %{issue_description} Your service request ID is ${result.serviceRequestId}.`; | |
return { | |
hasSumbittedTicket: 'true', | |
transferToAgent: 'false', | |
serviceRequestId: result.serviceRequestId, | |
readOutServiceRequestId: readOutServiceRequestId, | |
}; | |
} catch (error) { | |
console.error('Lambda execution failed:', error); | |
return { | |
hasSumbittedTicket: 'false', | |
transferToAgent: 'true', | |
parkingMeterAttempts: (Number(parkingMeterAttempts) || 0) + 1, | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment