nnja / friendhotline.com

A code of conduct hotline for every one
https://conducthotline.com
Apache License 2.0
6 stars 3 forks source link

If no one picks up, play a message before hanging up. #15

Open nnja opened 4 years ago

nnja commented 4 years ago

Currently, the phone will just play the busy music for forever, even if no one picks up and the call isn't connected.

Detect this case, play a message, and drop the call.

Detecting if the call goes to voicemail may be a necessary prerequisite. References #3

Maybe by modifying the telephony event handler to catch hangups. If no one is left on a call, send a message and disconnect.

nnja commented 4 years ago

Unfortunately, this isn't as straightforward as I originally hoped. Made some progress investigating this after talking to @alphacentauri82 and pairing with @theacodes

What we tried:

  1. Creating a conversation through the Conversations API and using that as our conversation id for outbound calls.

    Doesn't work because despite specifying this new Conversation ID in our "connect" NCCO it seems to transfer to a new, unknown conversation UUID. The new, unknown one has the members, but only the members that answer the call.

  2. Checking the conversation status when telephony events arrive.

    Doesn't work because the new, unknown conversation id only has members that have answered in it. So we can't trace that back to the conversation ID that has the active members in it, so we can't hangup the call.

What might work:

  1. Track the calls using the database: create an entry for the "call session" that has the uuid of the call that the inbound caller is in and the uuids of all of the outbound calls.
  2. Update the list when someone answers, hangs up, or an error occurs. (from telephony events)
  3. End the conversation if all calls fail or everyone hangs up except one person.
  4. Make sure the call stays active in the caller hangs up and there are other members still in the conversation.
  5. Using this approach, if a verified member calls into the hotline while there's an active call going on, we'll be able to join them into the call.

Using the conversations API manually

import hotline.config      
hotline.config.load()                                                                                                                                    
import hotline.injector     
import hotline.telephony.lowlevel

client = hotline.injector.get("nexmo.client")     
client._jwt_signed_get("/beta2/conversations")    
client._jwt_signed_get(f"/beta2/conversations/{conversation_uuid}")      
client._jwt_signed_get(f"/beta2/conversations/{conversation_uuid}/members")    
client._jwt_signed_get(f"/beta2/conversations/{conversation_uuid}/members/{member_id}")

# Hanging up
client.update_call(f"{conversation_leg_id}", {"action": "hangup"})
nnja commented 4 years ago

Investigate how to fetch in progress calls that might have a status of ringing