Need help with API

Need help with API

by Nano A -
Number of replies: 10

Hello,

I am using a live chat software (Zopim) in a Moodle Website.  I would like it to read the user name and email (from the logged user).

I asked their support how can I do this and they told me to add this to the script that calls the chat window:

 

----------

<script>
$zopim(function() {
$zopim.livechat.setName('Logged in name');
$zopim.livechat.setEmail('user@somewhere.com');
});
</script>

----------

They also instructed me to replace the "Logged in name" and "username@somewhere.com" with your own name and email variable, respectively, and it will pickup the username / name of the visitor of your website.

----------

 

Could someone help me by telling me what to put in those two fields?

 

Thank you! smile

 

 

 

 

Average of ratings: -
In reply to Nano A

Re: Need help with API

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi,
not sure where you'll add that client side code but you could try with:

<script>
<?php
global $USER;
?>
    $zopim(function() {
        $zopim.livechat.setName('<?php p(fullname($USER)); ?>');
        $zopim.livechat.setEmail('<?php p($USER->email); ?>');
    });
</script>

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Need help with API

by Nano A -

Thanks Matteo.

The instructions where to put it in a html file after the heading, but as I don't want to mess with moodle files, I have created a HTML block in the home page (?redirect=0) and made that HTML block to be seen though the whole site.

The whole code in that block is:

 

<script type="text/javascript">// <![CDATA[

window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
_.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');
$.src='//cdn.zopim.com/?18U7FwTSpLh07khZcWYifxyRtW9MuelG';z.t=+new Date;$.
type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
// ]]></script>
<script type="text/javascript">// <![CDATA[

 

<?php
global $USER;
?>
$zopim(function() {
$zopim.livechat.setName('<?php p(fullname($USER)); ?>');
$zopim.livechat.setEmail('<?php p($USER->email); ?>');
});
// ]]></script>

 

<script type="text/javascript">// <![CDATA[
$zopim(function() {
$zopim.livechat.setOnStatus(change_chat_img);
});
function change_chat_img(status) {
var img = document.getElementById('chat_img');
if (status=='online')
img.src = https:/ /dl.dropbox.com/u/1704220/icons/Online-chat-icon.png;
else if (status=='away')
img.src = https:/ /dl.dropbox.com/u/1704220/icons/Online-chat-icon.png;
else if (stats=='offline')
img.src = https:/ /dl.dropbox.com/u/1704220/icons/Offline-chat-icon.png;
}
// ]]></script>

<p><a href="javascript:$zopim.livechat.window.show()"><img.src></a></p>

 

 

1) First block is to enable the chat tab at the bottom right side of the screen.

2) Second block should pick up the logged in user from Moodle.

3) Third block should put a variable image (online/offline) in the block so it doesn't look empty.

 

So far only (1) is working.  (2) and (3) are not sad

 

I'm not a developer so I don't undertand the code.  I appreciate any input you can give me.  smile

 

(note that I have added extra space in the url for the image, just for this msg, so it doesn't show the image but the code.

 

In reply to Nano A

Re: Need help with API

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi,
you should code (PHP, developer: easy task) a new block because using an HTML block will prevent you to access those info available from PHP since it's an "HTML block" i.e. running in the browser, client side.

You could ask them if they have any interest in letting people use their product within Moodle to see if they will take the decision to provide a new Zopim block for the Moodle plugins directory.

Matteo

In reply to Matteo Scaramuccia

Re: Need help with API

by Nano A -

Thanks for your input again Matteo.

I did ask them, but it seems that it's not in their plans yet.   And, as far as I can see none of the companies that provide this kind of services is doing it so far.

I have no idea how to code a new block.    Would you like to help me?

Thanks smile

In reply to Nano A

Re: Need help with API

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Nano,
here is a brand new Zopim Live Chat widget block for Moodle: https://github.com/scara/moodle-block_zopim.

Matteo

In reply to Matteo Scaramuccia

Re: Need help with API

by Nano A -

Matteo,

Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! 

It works like a treat!

 

Not sure if I can do anything for you (feel free to ask me), but I promise that at least, I will study what you have done and learn from it!

Very generous of you mate! smile

Cheers!

In reply to Nano A

Re: Need help with API

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Nano,
appreciated smile.
I've changed your initial code after having read the details of the Zopim API and created something that could be used by any user. If everything will work as expected, I'll upload this block to the Moodle Plugins directory too.

Question: who is the owner of the icons under the dropbox URLs you've posted? I wonder if the author could agree to include them into this block, by default.

Matteo

In reply to Matteo Scaramuccia

Re: Need help with API

by Nano A -

Hi Matteo,

Those icons are just drafts I got from google.  I was thinking of developing my own buttons.

I will create a set of standard buttons next week so we can put them in the block files smile