use Login Name and Email variables in script on pageload

use Login Name and Email variables in script on pageload

de către Stefan Schoch-
Număr de răspunsuri: 5
Fotografia lui Particularly helpful Moodlers

Since nobody answered to this question in the 'General Forum', I give it another try here:


Hi there,

I am using a Chat-Tool (tawk.to) to be able to chat with my visitors / students.

Currently they have to enter their name manually so I can identify them.

There is an option to pass the Username and Email to the tawk.to script by adding the following script to the 'additional HTML' section:

<script type="text/javascript">
var Tawk_API=Tawk_API||{};
Tawk_API.visitor = {
name : 'visitor name',
email : 'visitor@email.com'
};

var Tawk_LoadStart=new Date();
</script>
This works fine, but now I need to know how I can access the variable 'username' and 'email' that are used by Moodle within that script (instead of visitor name above, because few of my students are called 'visitor name' zwinkernd)

How can I pass these variables to the script?

Stefan

Moodle 3.8.3


Media aprecierilor: -
Ca răspuns la Stefan Schoch

Re: use Login Name and Email variables in script on pageload

de către Howard Miller-
Fotografia lui Core developers Fotografia lui Documentation writers Fotografia lui Particularly helpful Moodlers Fotografia lui Peer reviewers Fotografia lui Plugin developers
Where is this bit of Javascript going?

It may be possible (in theory) to make an Ajax call to a Moodle webservice but I've not done it - it won't be easy.
Ca răspuns la Howard Miller

Re: use Login Name and Email variables in script on pageload

de către Stefan Schoch-
Fotografia lui Particularly helpful Moodlers
Hey Howard,

thx for your reply. I don't really understand what you ask by 'where is this javasript going'.

I placed in into the 'additional html' section where it is triggered and does it's job so far: the 'username' used by the tawk.to chatbox is replaced with 'visitor name'.
What I need to do now is call the corresponding Moodle API that gives me back the username and emailadress of the current logged in user so I can put it into the variables.

Ususally (i.e. on my Joomla site) this is no problem at all, I only need to know the script I have to call.

Stefan
Ca răspuns la Stefan Schoch

Re: use Login Name and Email variables in script on pageload

de către Luis de Vasconcelos-
Fotografia lui Particularly helpful Moodlers
Perhaps you could get it from the $USER object?
Ca răspuns la Luis de Vasconcelos

Re: use Login Name and Email variables in script on pageload

de către Stefan Schoch-
Fotografia lui Particularly helpful Moodlers

I assume that is true.

But - how do I get the user object?

I have no idea how to call the API.

Any tips?

Ca răspuns la Stefan Schoch

Re: use Login Name and Email variables in script on pageload

de către Michael Milette-
Fotografia lui Core developers Fotografia lui Documentation writers Fotografia lui Particularly helpful Moodlers Fotografia lui Plugin developers Fotografia lui Testers Fotografia lui Translators
Hi Stefan,

If your theme supports filtering in the Additional HTML fields, an easy solution would be to use the FilterCodes plugin. It includes two plain text tags which will be of interest to you: {fullname} and {email}. The easiest way to find out if it will work is to simply install and activate the plugin, and add the tags.

You will find it at https://moodle.org/plugins/filter_filtercodes

If it doesn't work, you can always contact the theme developer and ask them to add support for this. Additional information on what they would need to do is included in the readme file.

Hope you find this useful,

Michael Milette
Media aprecierilor:Useful (1)