def handle_inbound_call( reporter_number: str, event_number: str, conversation_uuid: str, call_uuid: str, host: str, client: nexmo.Client, ) -> List[dict]: # Get the event. If there's no event, tell the user that something went # wrong. event = db.get_event_by_number(event_number) if event is None: error_ncco = [{"action": "talk", "text": common_text.voice_no_event}] return error_ncco # Make sure the number isn't blocked. if db.check_if_blocked(event=event, number=reporter_number): error_ncco = [{"action": "talk", "text": common_text.voice_blocked}] return error_ncco # Get the members for the event. If there are no members, tell the user. :( event_members = list(db.get_verified_event_members(event)) if not event_members: error_ncco = [{"action": "talk", "text": common_text.voice_no_members}] return error_ncco # Make sure that the user is a verified member of this hotline. # If not, bounce them. if not db.get_verified_member_for_event_by_number(event, reporter_number): error_ncco = [{"action": "talk", "text": common_text.voice_non_member}] return error_ncco # Great, we have an event. Greet the user. if event.voice_greeting is not None and event.voice_greeting.strip(): greeting = event.voice_greeting else: greeting = common_text.voice_default_greeting.format(event=event) # NCCOs to be given to the caller. reporter_nccos: List[dict] = [] # Greet the reporter. reporter_nccos.append({"action": "talk", "text": greeting}) # Start a "conversation" (conference call) reporter_nccos.append({ "action": "conversation", "name": conversation_uuid, "eventMethod": "POST", "musicOnHoldUrl": [HOLD_MUSIC], "endOnExit": False, "startOnEnter": False, }) # Add all of the event members to the conference call. for member in event_members: client.create_call({ "to": [{ "type": "phone", "number": member.number }], "from": { "type": "phone", "number": event.primary_number }, "answer_url": [ f"https://{host}/telephony/connect-to-conference/{conversation_uuid}/{call_uuid}" ], "answer_method": "POST", }) # TODO NZ: log name instead of number. # Last four digits of number is {reporter_number[-4:]} audit_log.log( audit_log.Kind.VOICE_CONVERSATION_STARTED, description= f"A new voice conversation was started. UUID is {conversation_uuid[-12:]}.", event=event, reporter_number=reporter_number, ) return reporter_nccos
def handle_inbound_call( event_number: str, conversation_uuid: str, call_uuid: str, host: str, client: nexmo.Client, ) -> List[dict]: # Get the event. If there's no event, tell the user that something went # wrong. event = db.get_event_by_number(event_number) if event is None: error_ncco = [{ "action": "talk", "text": "No event was found for this number. Please reach out to the event staff directly for assistance.", }] return error_ncco # Get the members for the event. If there are no members, tell the user. :( event_members = list(db.get_verified_event_members(event)) if not event_members: error_ncco = [{ "action": "talk", "text": ("Unfortunately, there are no verified members for this event's hotline. " "Please reach out to the event staff directly for assistance."), }] return error_ncco # Great, we have an event. Greet the user. greeting = ( f"Thank you for calling the Code of Conduct hotline for {event.name}. This will dial all " f"of the hotline members and put you on hold until one is able to answer." ) # NCCOs to be given to the caller. reporter_nccos: List[dict] = [] # Greet the reporter. reporter_nccos.append({"action": "talk", "text": greeting}) # Start a "conversation" (conference call) reporter_nccos.append({ "action": "conversation", "name": conversation_uuid, "eventMethod": "POST", "musicOnHoldUrl": [HOLD_MUSIC], "endOnExit": False, "startOnEnter": False, }) # Add all of the event members to the conference call. for member in event_members: client.create_call({ "to": [{ "type": "phone", "number": member.number }], "from": { "type": "phone", "number": event.primary_number }, "answer_url": [ f"https://{host}/telephony/connect-to-conference/{conversation_uuid}/{call_uuid}" ], "answer_method": "POST", }) audit_log.log( audit_log.Kind.VOICE_CONVERSATION_STARTED, description= f"A new voice conversation was started, uuid is {conversation_uuid}", event=event, ) return reporter_nccos