yaai icon indicating copy to clipboard operation
yaai copied to clipboard

outgoing call not picked up -> no new record in calls_contacts

Open bubuka opened this issue 12 years ago • 6 comments

Hello.

I have problem with unanswered outgoing calls.

In normal state i make outbound call and if picked up everithyng is ok.

  • The called number is associated correctly with contact.
  • In popup window i see the contact name correctly and the account name also.
  • In sugar "calls" table there is a new record with correct data in "contact_id" field.
  • In sugar "calls_contacts" also appear the new record with correct datas.

But, if make outbound call and it not picked (not answered)

  • The called number is associated correctly with contact.
  • In popup window i see the contact name correctly and the account name also.
  • In sugar "calls" table there is a new record with correct data in "contact_id" field.
  • BUT NO RECORD CREATED IN "calls_contacts"

What could be the problem? I see no difference betwen the two call in asterisk_log table. (only in second case the 'timestampLink' field is NULL, nothing else.)

Where is creating the new record to calls_contacts?

Thank You!

bubuka avatar Aug 07 '12 08:08 bubuka

Here's the deal. All the logic for the chat window is done in callListener so that's why everything looks the same.

It's in asteriskLogger Dial Event + Hangup where the contact gets associated with the call. For some reason the end event must not be happening when noone answers.

What version of asterisk are you using?

blak3r avatar Aug 07 '12 15:08 blak3r

Here are some snippets from the manual you may find useful...


asteriskLogger.php registers itself as a client to Asterisk's Manager API, so it receives notifications on Asterisk's activities. Most notably, the events we are interested in are Dial, NewcallerID, Hangup and Bridge. It uses the information received from these events for two purposes:

Maintain the state of current calling activity in database table "asterisk_log". The information held in asterisk_log is used by SugarCRMs GUI (dialin.js/callListener.php) to display call notifications in a popup. On receiving the "Hangup" event, a record is created in SugarCRM's Calls module, providing information about the callers ID, date and time of the call, duration, etc.


How are multiple matching contacts handled?

When the user doesn't intervene (by selecting from a list of matching contacts or manually relating), the first matching contact found in the database is picked. This happens when the hangup action occurs.

Desired behavior:

If phone number matches an account phone number, log it to account only. If it matches multiple contacts and each of them is from the same account, then log it to account only. If it matches multiple contacts and the account name differs... We don't really have a good person to log this to... this behavior is undefined. If the user is currently logged into sugar and they have call notification enabled, when there are multiple matching contacts the user can select the contact by clicking on a radio button. Once selected, setContactId ajax call is triggered which updates the contact_id column. As long as this is done before the call is hung up, asteriskLogger will check to see if the user selected the contact before picking one as outlined above. You may be asking yourself... why is there logic in two places? There is contact matching logic in both callListener and asteriskLogger. Well, asteriskLogger is necessary because that logs calls even when the user isn't logged into sugarcrm at all. CallListener needs logic as that is what displays the screen pops to the user and provides additional features to help user resolve multiple contact matching. As a result, we have similar logic in two places.

blak3r avatar Aug 07 '12 15:08 blak3r

Hello!

I use asterisk 1.8.11.

Yes, i have made some modifícation in findSugarObjectByPhoneNumber() and now its working the contact assign.

I found out, if i'm not logged in sugar or the call is not answered, then not the callistener assign the phone callerId to contact or account. In this case findSugarObjectByPhoneNumber() make the job.

But in findSugarObjectByPhoneNumber() there is a part, detection of multiple accounts. And in these part of code if the $account_id is empty its a problem.

I put an if statement into the code, let's see:

if( !isSoapResultAnError($soapResult)) { $resultDecoded = decode_name_value_list($soapResult['entry_list'][0]['name_value_list']);

    if( count($soapResult['entry_list']) > 1 ) {
        $foundMultipleAccounts = FALSE;
        $account_id = $resultDecoded['$account_id'];
        //-------------------------------if the $account_id is empty then left because its contact not an account-------------------//
        if ($account_id !="") {
        //-----------------------------------------------------------------//
           logLine("TTL: $account_id\n");
        // TODO I had 43 entries returned for 2 contacts with matching number... need better distinct support.  Apparently, no way to do this via soap... probably need to create a new service
        for($i=1; $i<count($soapResult['entry_list']); $i++ ) {
            $resultDecoded = decode_name_value_list($soapResult['entry_list'][$i]['name_value_list']);
            if( $account_id != $resultDecoded['account_id'] ) {
                $foundMultipleAccounts = TRUE;
            }
        }
        if( !$foundMultipleAccounts )
        {
            $result = array();
            $result['id'] = $account_id;
            logLine("Found multiple contacts -- all belong to same account, associating call with ID:  account.\n");
            return array( 'type' => 'Accounts', 'values' => $result );
        }
        else {
            logLine("Multiple contacts matched multiple accounts, Not associating\n");
            return FALSE;
        }
        } //------------------------ endif-----------------------------------------------------------------//
    }

    #print "--- Decoded get_entry_list() FOR GET CONTACT --------------------------------------\n";
    #var_dump($resultDecoded);
    #print "-----------------------------------------------------------------------------\n";
    return array(
        'type' => 'Contacts',
        'values' => $resultDecoded
    );

Sorry for a bad english.

I hope you undestand me. :)

Regards

bubuka avatar Aug 07 '12 16:08 bubuka

I do. Ironically, I noticed that case this weekend.

I don't think your code is right though because I think it'll hit the:

if( !$foundMultipleAccounts ) { $result = array(); $result['id'] = $account_id; logLine("Found multiple contacts -- all belong to same account, associating call with ID: account.\n"); return array( 'type' => 'Accounts', 'values' => $result ); }

case which isn't what you want...

you want it to return a contact instead.

Also, you probably need to handle the case where one contact does have an account assigned and one of them doesn't. I suppose in that case the behavior is undefined. So, assigning it to the first returned would work.

You'll notice in the lastest master I added some additional notes related to this bug.

~blake

On Tue, Aug 7, 2012 at 12:54 PM, bubuka [email protected] wrote:

Hello!

I use asterisk 1.8.11.

Yes, i have made some modifícation in findSugarObjectByPhoneNumber() and now its working the contact assign.

I found out, if i'm not logged in sugar or the call is not answered, then not the callistener assign the phone callerId to contact or account. In this case findSugarObjectByPhoneNumber() make the job.

But in findSugarObjectByPhoneNumber() there is a part, detection of multiple accounts. And in these part of code if the $account_id is empty its a problem.

I put an if statement into the code, let's see:

if( !isSoapResultAnError($soapResult)) { $resultDecoded = decode_name_value_list($soapResult['entry_list'][0]['name_value_list']);

if( count($soapResult['entry_list']) > 1 ) {
    $foundMultipleAccounts = FALSE;
    $account_id = $resultDecoded['$account_id'];
    //-------------------------------if the $account_id is empty then left because its contact not an account-------------------//
    if ($account_id !="") {
    //-----------------------------------------------------------------//
       logLine("TTL: $account_id\n");
    // TODO I had 43 entries returned for 2 contacts with matching number... need better distinct support.  Apparently, no way to do this via soap... probably need to create a new service
    for($i=1; $i<count($soapResult['entry_list']); $i++ ) {
        $resultDecoded = decode_name_value_list($soapResult['entry_list'][$i]['name_value_list']);
        if( $account_id != $resultDecoded['account_id'] ) {
            $foundMultipleAccounts = TRUE;
        }
    }
    if( !$foundMultipleAccounts )
    {
        $result = array();
        $result['id'] = $account_id;
        logLine("Found multiple contacts -- all belong to same account, associating call with ID:  account.\n");
        return array( 'type' => 'Accounts', 'values' => $result );
    }
    else {
        logLine("Multiple contacts matched multiple accounts, Not associating\n");
        return FALSE;
    }
    } //------------------------ endif-----------------------------------------------------------------//
}

#print "--- Decoded get_entry_list() FOR GET CONTACT --------------------------------------\n";
#var_dump($resultDecoded);
#print "-----------------------------------------------------------------------------\n";
return array(
    'type' => 'Contacts',
    'values' => $resultDecoded
);

Sorry for a bad english.

I hope you undestand me. :)

Regards

— Reply to this email directly or view it on GitHubhttps://github.com/blak3r/yaai/issues/53#issuecomment-7559578.

blak3r avatar Aug 07 '12 19:08 blak3r

@bubuka can you send me an email to the email in my github account. I'd like to create a list of users I could survey for how they use the app from time to time.

blak3r avatar Aug 08 '12 05:08 blak3r

@bubuka where does this issue stand? Did you ever completely solve this? Can you post your changes.

blak3r avatar Aug 20 '12 17:08 blak3r