LTI

Adding the bot to your LMS

To add this tool to your LMS, you need to run it on your own server, let’s say example.com. Currently it is started by running ./bot.py runclient, which starts an OTR bot and the LTI server. The server can then be reached at example.com:5000.

In your LMS, enter example.com:5000 as the launch URL for this LTI application. The “Consumer key” and “Shared secret” are in the settings file for your environment. In our settings.development_sample settings, find PYLTI_CONFIG. You can see that we added one consumer under “consumers”, which has __consumer_key__ as his consumer key, and __lti_secret__ as his secret. It is recommended to change these defaults.

Now it’s time to add your bot to the plugins/apps in your LMS.

Open EdX

To add your bot to a course in Open EdX, follow these steps.

  1. In Open EdX studio, go to Settings -> Advanced Settings
  2. In Advanced Module List, enable the LTI module, by adding "lti" to the list. If you have no other modules enabled, the value of the text field will look like [ "lti" ].
  3. In LTI Passports, add the otrbot. This is done by adding three colon (:) separated values to the list, in 1 string: "otrbot:<consumer_key>:<lti_secret>". Make sure that you fill in <consumer_key> and <lti_secret> with the same values as you entered in the settings file.

Now, in your course:

  1. Add a unit, you will see that you can choose an “Advanced” module. Click that, and choose LTI.
  2. Click the edit button of the LTI module. Here, fill in
    • LTI URL: example.com:5000 (replace example.com with the URL to your OTR bot machine).
    • LTI ID: otrbot
    • Take a look at the other settings. You might want to configure Open in New Page and Display Name as well.

You should now be able to use the LTI otr-bot component

Canvas

In canvas, follow these steps to add the bot to a course:

  • In your course, click Settings and then go to the Apps tab.
  • Click Add App
  • Choose “Manual entry”
  • The only fields that are currently relevant in Canvas are “Consumer key”, “Shared secret” and “Launch URL”. Follow your previously defined settings for the key and secret. The launch URL in our example is example.com:5000. Add a useful name in the “Name” field and keep the other fields empty.
  • Click the Submit button to save the app. Note that Canvas does not typically check any of the fields. To test the application, add the bot to an assignment.

And to add the bot to an assignment:

  • Go to Courses -> Assignments
  • Click + Assignment to add a new assignment and add a new assignment.
  • Click the + next to your new assignment to add a sub-assignment.
  • Click “More options” to be able to add LTI components.
  • Write whatever you want in the screens, an Assignment name is required for the assignment to be saved. Be sure to add “Points” to the assignment if you want to be able to see grades.
  • Under “Submission Type” choose “External Tool” Insert example.com:5000 as the URL for the external tool.
  • Save the assignment. You will now see an example of the course page you just made, with the OTR bot screen that is provided through LTI.
  • Note that the OTR bot only supplies a grade if the assignment is viewed by a student: in the teacher environment, no grade will be passed back to Canvas.

Class documentation

LTI provider that interfaces with the bot. This is a simple setup using Flask, because the PyLTI library already implements Flask decorators.

This module runs a flask server on 0.0.0.0:5000 (which maps to any host, port 5000). It accepts LTI requests using the key and secret in the settings file.

With the playbooks provided, it is also possible to serve these pages via nginx, over port 80.

Adding the bot to your LMS

To add this tool to your LMS, you need to run it on your own server, say example.com. Note that you need to run in production mode, through nginx. This will speed up the server and enable you to use TLS.

In your LMS, enter example.com as the launch URL for this LTI application. The “Consumer key” and “Shared secret” are in the settings file for your environment. In our settings.development_sample settings, find PYLTI_CONFIG. You can see that we added one consumer under “consumers”, which has __consumer_key__ as his consumer key, and __lti_secret__ as his secret. It is recommended to change these defaults.

Now it’s time to add your bot to the plugins/apps in your LMS. In canvas, follow these steps to add the bot to a course:

  • In your course, click Settings and then go to the Apps tab.
  • Click Add App
  • Choose “Manual entry”
  • The only fields that are currently relevant in Canvas are “Consumer key”, “Shared secret” and “Launch URL”. Follow your previously defined settings for the key and secret. The launch URL in our example is example.com. Add a useful name in the “Name” field and keep the other fields empty.
  • Click the Submit button to save the app. Note that Canvas does not typically check any of the fields. To test the application, add the bot to an assignment.

And to add the bot to an assignment:

  • Go to Courses -> Assignments
  • Click + Assignment to add a new assignment and add a new assignment.
  • Click the + next to your new assignment to add a sub-assignment.
  • Click “More options” to be able to add LTI components.
  • Write whatever you want in the screens, an Assignment name is required for the assignment to be saved. Be sure to add “Points” to the assignment if you want to be able to see grades.
  • Under “Submission Type” choose “External Tool” Insert example.com as the URL for the external tool.
  • Save the assignment. You will now see an example of the course page you just made, with the OTR bot screen that is provided through LTI.
  • Note that the OTR bot only supplies a grade if the assignment is viewed by a student: in the teacher environment, no grade will be passed back to Canvas.

Running LTI in develop mode

By just running ./bot you should have a werkzeug instance of the LTI bot running. Test it by going to http://localhost:5000/is_up

Running LTI in production

The function otrbot.__init__.app() is runnable by gunicorn. You can run a gunicorn instance by simply typing gunicorn otrbot:app. Test the setup by going to http://localhost:8000/is_up.

The ansible playbooks should install a systemd service that runs gunicorn and an nginx configuration that serves this through port 443.

The ansible playbooks assume that you ran certbot on your VPS to install certificates. If you haven’t, please run this (works on debian):

$ sudo apt install certbot
$ certbot standalone
otrbot.lti.lti.app = <Flask 'otrbot.lti.lti'>

The flask decorator (unfortunately does not follow conventions).

otrbot.lti.lti.mock_ltid(_app=None, _request='any', error=None, role='any', *lti_args, **lti_kwargs)

For debug purposes, replace the normal lti decorator with this one, that returns ‘mock-lti’ as nickname and does not verify or authenticate

otrbot.lti.lti.BOT = None

It is important to initialise the bot variable before calling ‘run()’. It should point to an instance of the OtrBot class.

otrbot.lti.lti.get_locale()

Try to set the locale to something sensible

otrbot.lti.lti.error_page(exception=None)

Render error page

Parameters:exception – optional exception
Returns:the error.plim template rendered
otrbot.lti.lti.hello_world(lti=<function lti>)

Indicate the flask app is working. Provided for debugging purposes.

Parameters:lti – the lti object from pylti
Returns:simple page that indicates the request was processed by the lti provider
otrbot.lti.lti.index(*args, **kwargs)

initial access page to the lti provider. This page provides authorization for the user. Contains a button to enter a JID

Parameters:lti – the lti object from pylti
Returns:index page for lti provider
otrbot.lti.lti.enter_jid(*args, **kwargs)

Insert a JID for the bot to add to its roster. The form validates the JID using SleekXMPP’s JID constructor. After that, it tries to add the JID to the bot. If that fails (unlikely), the error page is shown.

Parameters:lti – the lti object from pylti
Returns:Either the form to enter the jid or a redirect to the jid_entered page.
otrbot.lti.lti.jid_entered(*args, **kwargs)

A page that confirms that the jid was added to the bot. Contains a button that directs the user tot he “ask_for_secret” page.

Parameters:lti – the lti object from pylti
Returns:The page confirming the jid was added.
otrbot.lti.lti.ask_for_secret(*args, **kwargs)

Show a form to submit a shared secret. When the secret is submitted, it is utf-8 encoded and added to the bot. The bot then checks if the secret is strong enough. If so, it saves it, else, the user is informed about this through Jabber, and asked to enter a new secret through LTI.

If this function is called when a strong secret is already set, the page is skipped and the next page is loaded, where the user is notified that his secret is added.

Parameters:lti – the lti object from pylti
Returns:Either a page showing the secret form or a page saying that the secret was entered.
otrbot.lti.lti.enter_bot_secret(*args, **kwargs)

Form to enter the secret that the bot shares after SMP is successful

otrbot.lti.lti.run_lti()

For if you want to run the flask development server directly