Showing results for 
Search instead for 
Did you mean: 
Community Advocate
Community Advocate

Running Scripts in Canvas

I actually had a student who is a current HS junior, a club officer for our NJROTC,  ask a question that made me feel less than intelligent! He is the 'Teacher' role for the ROTC default course and wanted to know if you could run a script so that when he creates a module it would send a text field out to the club officers as an announcement. He is into coding and I wondered if there was capability with APIs that is just beyond my current comprehension.. I was hoping  @James  might be able to chime in! Smiley Happy

I thought perhaps he could just make an officer group/section in the course and put an announcement out to just them one he created a module to let them know he was going to publish it so they could help spread the word to their platoons.

But I thought I'd ask since it would be cool if he could practice coding within Canvas. Maybe he could teach me!

Tags (2)
2 Replies
Community Champion

 @jayoder ,

There are several things that come to mind. None of which are trivial, but one that is easier than the others and can be done with all of his permissions (as a teacher), and uses supported methods so that it won't break when Canvas changes the layout on a page.

There is no tracking available within the API of when this happens. The course audit log doesn't track changes to content like the addition or publishing of a module.

There is a Canvas Live Event that includes a module_created event. This adds an event to the queue of what has happened and then one could watch for it to happen and do whatever needed done. However, this would not be available to a student or teacher. It needs to be handled at the institutional level and information might be shared as needed with other entities within the organization.

You could write code that runs in the browser and looks for the addition of a new module. This is tricky and you would want to make sure that you don't send 5 announcements if you go on a frenzy and create five modules, so it's not my recommended solution. This involves tapping into the event sequence to look for things like clicks, doing your code, and then letting Canvas do it's code. I did something similar with my QuizWiz program. That would have to be loaded into the users browser using Tampermonkey or another user script manager. I would not install it in the global custom JavaScript, no matter how good the student was, as it has a very limited audience (1 person) and the global JavaScript gets executed for every user on every load. This is a perfect case of what user scripts are for, though.

One could query the list of modules on a periodic basis, looking for new ones, and then send out a message to the people when certain conditions are met. You could send a conversation message to the officers if you had some way of knowing who they were (this could be inside Canvas or via external email). If you sent an announcement, it could contain a list of all of the modules that were recently created or published as a summary, rather than one for each. Announcements can be delivered to specific sections, but not groups, so if you had a section that held the officers and a different section for everyone else, then that would handle the issue of determining who was an officer and you could post an announcement for just the officer section. 

I'd recommend taking the last approach and running it once a day. If the student needs faster notifications, he could run it more frequently, but you may lose the ability to consolidate announcements.

Community Coach
Community Coach

Hi there,  @jayoder ...

I'm reviewing some of the older questions here in the Canvas Community, and I came across your question.  I wanted to check in with you because I noticed we've not heard back from you since you first posted this question on May 31, 2019.  It looks like  @James ‌ gave you some feedback a day later.  Have you had a chance to review James' reply?  If so, did it help to answer your question?  Or, are you still looking for some help from Community members?  If James' response has helped to answer your question, please click on the "Mark Correct" button next to his response.  However, if you are still looking for some help, please post a note below letting Community members know how we might be able to help.  For the time being, I am going to mark your question as "Assumed Answered" because we've not heard back from you and because there hasn't been any new activity in this topic for six months.  However, that won't prevent you or others from posting additional questions and/or comments below that are related to this topic.  I hope that's okay with you, Jonathan.  Looking forward to hearing back from you soon.