Sending additonal information to an external tool with LTI

Re: Sending additonal information to an external tool with LTI

by Jake Dallimore -
Number of replies: 4
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Akshay,

Yes, LTI does support sending custom data to the tool during launch. For LTI 1.3 (which I assume you're working with, since the older versions are not currently recommended by IMS), the process is as simple as including user-specific data in the 'custom' claim during launch (http://www.imsglobal.org/spec/lti/v1p3/#custom-properties-and-variable-substitution). But how is this done in Moodle?

Moodle provides an LTI subplugin type called 'ltisource'. Among other things, source plugins can augment the data included in launches, by implementing a component callback 'ltisource_PLUGINNAME_before_launch'. This is called when building the launch data to be sent. Given the standard means of including 'extra' data in LTI 1.3 is via the custom claim, you can simple return an item indexed by the name 'custom_YOURFIELDNAME', and this will automatically be added to the claim, and will be available to your tool during launch.

Here's a link to some source plugins (I find reading code easier that reading a forum post!):
https://moodle.org/plugins/browse.php?list=category&id=64

You'll can check out the source code for each plugin on it's plugin listing page.

Hope that helps
Jake
In reply to Jake Dallimore

Re: Sending additonal information to an external tool with LTI

by Akshay Nayyar -

Hey Jake, 

thank you for the detailed response. I'm clear on how it works on the LTI side. All I need to do is get the information in the custom claim und get the information from the claim to where it is needed. I've successfully received the name and launchid among the other generic information from moodle to my tool. Now, I'm actively working towards getting the required information automatically instead of a student filling it manually. 

However, I'm not sure how to go about it on moodle side. I'm a student working on my bachelor thesis, thus I have no administrative rights on moodle. If anything needs to be installed in the background, I'd need to get in touch with the people responsible for maintaining moodle at my university. The link you provided, I see 2 plug-ins but they don't seem to be what I need. We're you aiming for something specific which has been removed since then? 

Also, let's say that I want the current leaderboard position of a student from Moodle. I'm using the level up plugin to implement leaderboards in my moodle course. Do I simply name course.custom_YOURFIELDNAME as course.custom_leaderboard or do I look for something specific to correctly name the attribute? I'd be grateful if you could guide me a little bit more. Or if you have some spare time, a quick online meeting. 

I'm relatively new to LTI and Moodle, so it could be that my questions are a little silly. Thank you for your time and patience. 

Regards, 

Akshay 

In reply to Akshay Nayyar

Re: Sending additonal information to an external tool with LTI

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Akshay,

Firstly, there are no silly questions when it comes to either Moodle or LTI. it's great that you're exploring the capabilities of the system. It sounds like you're across the LTI specs, which is great too.

The link I provided was to the source plugins listing on the Moodle plugins database. From there, you can click a plugin (e.g. EcoHub LTI Source), then follow the "Source control URL" link to view the source. This was just an attempt at helping you see what sort of plugin code you'd need to write (i.e. what callback needs implementing, plugin structure etc.).

Regarding the naming of the custom params, it sounds like you're perhaps talking about the tool setting "Custom parameters" (a UI field found in the external tool editing form). This can be used to send custom data in the launch, but only if the data is either static (defined in that field as something like 'id=abc123'), or uses one of the predefined substitution variables supported by Moodle. Moodle doesn't provide substitution variables for plugins. Substitution variables are things like 'uname=$User.username', which will pass the username of the user across in a custom 'uname' field. There is also support for things like Course and Context fields.

In order for you to be able to send anything else (like leaderboard results, etc), you will need to create and install an lti source plugin. This is the only way to extend what can be sent in this custom data.

Hope that helps.
Jake


In reply to Jake Dallimore

Re: Sending additonal information to an external tool with LTI

by Akshay Nayyar -
Hey Jake,

thank you for getting back to me so fast.

Please tell me, if i've got this right - Moodle is currently the limiting factor and not LTI. I'll have to create a plugin for moodle which then will be installed and added to moodle. With help of this plugin, on the external tool setting page, i can add custom parameters such as course.custom_leaderboard or course.custom_level among others to the field custom parameters. As soon as moodle goes to the external tool, the custom information will also be sent to the tool along with the generic information that is always sent. Is this correct?

Also, what will be the aim of the plugin - adding more predefined substitution variables for leaderboards, levels, etc, to the already existing variables or something else?

Regards,
Akshay
In reply to Akshay Nayyar

Re: Sending additonal information to an external tool with LTI

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Akshay,

You're right in that Moodle is the limiting factor for you right now. You're also right in that you need to create a plugin, however, implementing the before_launch() callback in the plugin won't allow you to add new substitution vars for use in the Moodle form; it allows you to programatically set custom_xxxx values based on, well, whatever you like (you can fetch this data however you like during the before_launch callback), and include these in tool launches.

You'll likely also want to ensure that whatever custom_xxx properties you need are only being added to launches of your specific tool too - perhaps by inspection/comparison of the tool url in that callback function. The way that plugin callback is designed makes it a global callback that will be called before ALL tool launches. If the logic to fetch your leaderboard data is heavy, you really want to make sure you're only doing it when the appropriate tool URL is seen. The callback receives a few things:https://github.com/moodle/moodle/blob/master/mod/lti/locallib.php#L671
1. The tool type (a record from the PREFIX_enrol_lti_tools table)
2. The tool URL
3. The request params

You should be able to make the relevant decision on whether to add leaderboard information based on the tool url here.

Hope that helps
Jake