Jump to content
  • 0

Trying to Pull Client Phone Number Locally


Michael K

Question

Hey there, guys!

I'm almost finished integrating Blesta with Intercom, but something is holding me from the finish line. I'm trying to retrieve a client phone number so that I can push it to Intercom and then my phone system can create logs in Intercom based on that phone number. Problem is, I'm not very familiar with APIs or anything, so this one's been bugging me. What's going to be the easiest way to retrieve this information? Keep in mind that I'm not trying to retrieve it remotely, so I'm just doing it from within Blesta itself and implementing the actual code into my Intercom JavaScript widget code.

If anyone could help, that'd be awesome! Thanks in advance!

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

I should have also mentioned I need it to be formatted into a normal variable, it'll be implemented like this:
 

<script>
  window.intercomSettings = {
    app_id: "app_id",
    phone: "<?php echo $verify_phone; ?>",
    name: "<?php echo $this->Html->_($contact->first_name, true) . ' ' . $this->Html->_($contact->last_name, true);?>",
    email: "<?php echo $verify_email; ?>", // Email address
    user_hash: "<?php echo $email_sig; ?>" // HMAC using SHA-256
  };
</script>

 

Link to comment
Share on other sites

  • 0

Hi there,

I use this on Crisp back in the day.
 

<script type="text/javascript">
            window.$crisp=[];window.CRISP_WEBSITE_ID="ID_HERE";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();
            window.CRISP_READY_TRIGGER = function() {
              if ($crisp.is("chat:opened") === true) {
                    $crisp.push(["set", "session:segments", [["BlestaStore"]]]);
                    <?php if($this->Html->ifSet($logged_in)){ ?>
                    $crisp.push(["set", "user:nickname", "<?php echo $contact->first_name;echo ' '; echo $contact->last_name; ?>"]);
                    $crisp.push(["set", "user:email", "<?php echo $contact->email; ?>"]);
                    $crisp.push(["set", "user:company", "<?php echo $contact->company; ?>"]);
                    $crisp.push(["set", "user:address1", "<?php echo $this->Html->_($contact->address1); ?>"]);
                    $crisp.push(["set", "user:address2", "<?php echo $this->Html->_($contact->address2); ?>"]);
                    $crisp.push(["set", "session:data", ["ipaddress", "<?php echo $ipaddress; ?>"]]);
                    $crisp.push(["set", "user:country", "<?php echo $this->Html->_($contact->country); ?>"]);
                    $crisp.push(["set", "user:city", "<?php echo $this->Html->_($contact->city); ?>"]);
                    $crisp.push(["set", "user:state", "<?php echo $this->Html->_($contact->state); ?>"]);
                    $crisp.push(["set", "user:postcode", "<?php echo $this->Html->_($contact->zip); ?>"]);
                    $crisp.push(["set", "user:id", "<?php echo $this->Html->_($client->id_code); ?>"]);
                    $crisp.push(["set", "user:phonenumber", "<?php echo $this->Html->_($contact->numbers); ?>"]);
                    $crisp.push(["set", "user:role", "<?php echo $this->Html->_($contact->title); ?>"]);
                    $crisp.push(["set", "session:data", ["created", "<?php echo strtotime($client->date_added); ?>"]]);
                    $crisp.push(["set", "session:data", ["company", "<?php echo $this->Html->_($contact->company); ?>"]]);
                    $crisp.push(["set", "session:data", ["contact_type", "<?php echo $this->Html->_($contact->contact_type); ?>"]]);
                    $crisp.push(["set", "session:data", ["date added", "<?php echo $client_created; ?>"]]);
                    <?php } ?>
                 
              }
            };
        </script>

 

Link to comment
Share on other sites

  • 0

Yea, so you would load the Contacts model inside your controller.  You said you want this to be passed to structure.pdt?  I assume this is for client interface?  You can update client_controller.php in the preAction() and load the contacts controller:

$this->uses(['Contacts']);

Then set the numbers to the structure:

$this->structure->set('contact_numbers', $this->Contacts->getNumbers($this->client->contact_id));

That will make the $contact_numbers variable available to app/views/client/bootstrap/structure.pdt

Link to comment
Share on other sites

  • 0

X) How are you outputting it?  $contact_numbers is an array of objects.  I guess in your case you are looking for a particular number so maybe just grab the first one

<?php
$verify_phone = $this->Html->ifSet($contact_numbers[0]->number);
?>
<script>
  window.intercomSettings = {
    app_id: "app_id",
    phone: "<?php echo $verify_phone; ?>",
    name: "<?php echo $this->Html->_($contact->first_name, true) . ' ' . $this->Html->_($contact->last_name, true);?>",
    email: "<?php echo $verify_email; ?>", // Email address
    user_hash: "<?php echo $email_sig; ?>" // HMAC using SHA-256
  };
</script>

You may also want to submit the $type argument to Contacts::getNumbers() to get only 'phone' type numbers.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...