Jump to content

Show active services on Crisp.chat


Juanzo

Recommended Posts

We are enjoying Crisp.chat as a front desk for our WHMcs support tickets (great since it integrates chat and social networks).

Their integration with WHMcs made things easier, but now I'm trying to improve their code to be able to show actvice services for identified clients.

Any ideas on how could we insert active services?
This is their hook now:

<?php
if(!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}
use WHMCS\Database\Capsule;
function hook_crisp_footer_output($vars)
{
    $website_id = Capsule::table('tbladdonmodules')->where('module', 'crisp')->where('setting', 'website_id')->value('value');
    if(!$website_id) {
        return;
    }
    $output = "<script type='text/javascript'>
        window.CRISP_READY_TRIGGER = function() {
    ";
    if ($vars['clientsdetails']['email']) {
        $email = $vars['clientsdetails']['email'];
        $output .= "\$crisp.set('user:email', '$email');";
    }
    // First and last name
    if ($vars['clientsdetails']['firstname']) {
        $name = $vars['clientsdetails']['firstname'] . " " . $vars['clientsdetails']['lastname'];
        $output .= "\$crisp.set('user:nickname', '$name');";
    }
    // Information apart from First & Lastname that should be imported. Must exist in the clientsdetails-array.
    if(isset($vars['clientsdetails'])) {
        $merge_fields = [
            'id',
            'companyname',
            'address1',
            'address2',
            'city',
            'state',
            'postcode',
            'country',
            'phonenumber'
        ];
        foreach($merge_fields as $merge_field) {
            if(isset($vars['clientsdetails'][$merge_field])) {
                $output .= "\$crisp.set('session:data', ['" . $merge_field . "', '" . $vars['clientsdetails'][$merge_field] . "']);";
            }
        }
    }
    $output .= "};</script>
    <script type='text/javascript'>CRISP_WEBSITE_ID = '$website_id';(function(){d=document;s=d.createElement('script');s.src='https://client.crisp.chat/l.js';s.async=1;d.getElementsByTagName('head')[0].appendChild(s);})();</script>
    ";
    return $output;
}
add_hook('ClientAreaFooterOutput', 1, 'hook_crisp_footer_output');

 

Link to comment
Share on other sites

On 25/12/2019 at 18:53, Juanzo said:

Any ideas on how could we insert active services?

the client would need to be logged in, and then their services would have to be queried from the database - either by capsule (the hook already uses capsule), model or API

if they'll logged in you'll have their user id from...

$vars['clientsdetails']['userid']

then it's just a case of using that in a capsule query to tblhosting, and looping through the resulting array to output it.. though bear in mind that this would just get their services - not their domains or any product addons.

Link to comment
Share on other sites

  • 3 years later...

Join the conversation

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

Guest
Reply to this topic...

×   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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated