jsQuizizz
Overview
jsQuizizz is a NodeJS Wrapper for the Quizizz API.
Installing
This package can be installed using NodeJS's package manager, npm.
npm install jsquizizz
Importing
To use the new esm syntax, set your
typetomodulein yourpackage.json. Click me for more information
You can import the entire package into a single variable (esm)
import * as Quizizz from 'jsquizziz'You can import certain parts of the package into different variables (esm)
import {MemeSet, Quiz, Tag, User, Game} from 'jsquizziz'You can also import this package into non-esm modules (commonjs)
var Quizizz = await import("jsquizizz")
Documentation
MemeSet
Quizizz shows the players memes after every question answered. These memes are stored in MemeSets, and theMemeSetclass allows us to get these MemeSetsMethods
Type Method Parameters Returns Description Example staticgetByIDParameter Type Default Description idstringRequired The MemeSet ID savebooleanfalseWhether to save the memes to memory for faster recall Promise<MemeSet>Gets a MemeSet via it's ID await MemeSet.getByID("abcdef", false)staticgetFromUserParameter Type Description idstringThe User ID Promise<MemeSet[]>Gets a list of MemeSets from a user's ID await MemeSet.getFromUser("abcdef")staticgetFeaturedNone Promise<MemeSet[]>Gets the currently featured MemeSets await MemeSet.getFeatured()dynamicgetMemesParameter Type Default Description savebooleanfalseWhether to save the data to memory for faster recall Promise<Meme[]>Gets the memes from the MemeSet await myMemeSet.getMemes(true)dynamicMeme.getCreatorNone Promise<User>Gets the meme's creator. await (await myMemeSet.getMemes(false))[0].getCreator();Properties
Property Types Description idstringThe memeset's ID memesMeme[]undefinedGets the quizzes that the user has created Meme.idstringThe meme's ID Meme.setIdstringThe ID of the memeset that this meme is included in Meme.creatorIdstringThe ID of the creator of this meme Meme.topProperty Types Description textstringThe text on the top of the meme (May be "")colorstringThe color of the text (May be "")The top text of the meme (if there is any) Meme.bottomProperty Types Description textstringThe text on the top of the meme (May be "")colorstringThe color of the text (May be "")The bottom text of the meme (if there is any) Meme.imagestringThe meme's image Meme.typestringThe meme's type (mainly "correct"and"incorrect", but others do exist)
Quiz
Quizizz is a service based of many, many quizzes. TheQuizclass helps to fetch these quizzes.Methods
Type Method Parameters Returns Description Example staticgetByIDParameter Type Default Description idstringRequired The Quiz ID Promise<Quiz>Gets a Quiz via it's ID await Quiz.getByID("abcdef")staticsearchParameter Types Default Description querystring""The search query filtersParameter Types Default Description grade_type.aggsstring[]N/A The grade types subject.aggsstring[]N/A The subjects lang.aggsstring[]N/A The languages occupationstring[]N/A The creator's occupations clonedboolean[]N/A Whether the quiz is a clone of another isProfaneboolean[]N/A Whether the quiz is profane typestring[]N/A The type of quiz createdBystring[]N/A Who created the quiz {}The search filters Promise<Quiz[]>Searches for quizzes based on the query and filters await Quiz.search("apple", {createdBy: ["abcdef"]})dynamicgetCreatorNone Promise<User>Gets the quiz's creator. await myQuiz.getCreator()Properties
Property Types Description idstringThe quiz's ID creatorProperty Types Description idstringThe user's ID avatarstringThe user's avatar usernamestringThe user's username Gets the quizzes that the user has created tagIdsstring[]A list of tags that this quiz is associated with. (This property's value is []unless the quiz has been generated from theTag.getItems()function)questionsProperty Types Description idstringThe question's ID typestringThe question's type ( "MCQ","MSQ","DRAW","MATCH", etc)queryQuestionContentThe question's question optionsQuestionContent[]The question's options answerstring|number|number[]|undefinedThe question's answer explainQuestionContentThe question's answer explanation (If there even is an explanation) hasCorrectAnswerbooleanWhether the question has a correct answer The quiz's questions subjectsstring[]The subjects that this quiz is associated with subtopicsstring[]The subtopics that this quiz is associated with topicsstring[]The topics that this quiz is associated with imagestringThe quiz's image gradesnumber[]The grades that this quiz is associated with statsProperty Types Description playednumberThe number of times this quiz has been played totalPlayersnumberThe total number of players that have played this quiz totalCorrectnumberThe total number of correct answers that have been submitted in this quiz totalQuestionsnumberThe total number of questions that have been answered in this quiz The statistics of this quiz
Tag
User's can tag their quizzes to group them into sections. TheTagclass canprocessthese sections and quizzesMethods
Type Method Parameters Returns Description Example staticgetByIDParameter Type Default Description idstringRequired The Tag ID savebooleanfalseWhether to save the data to memory for faster recall Promise<Tag>Gets a tag via it's ID await Tag.getByID("abcdef", false)staticgetFromUserParameter Type Default Description idstringRequired The user's ID Promise<Tag[]>Gets a list of tags from a user's ID await Tag.getFromUser("abcdef")dynamicgetItemsParameter Type Default Description savebooleanfalseWhether to save the data to memory for faster recall Promise<Quiz[]>Gets all the items tagged with this tag await myTag.getItems(true)dynamicgetCreatorNone Promise<User>Gets the tag's creator. await myTag.getCreator()Properties
Property Types Description idstringThe tag's ID creatorIdstringThe tag's creator's ID visibilitybooleanThe tag's visibility namestringThe tag's name typestringThe tag's type ( "quiz","game","meme". I am yet to find a tag that does not have the"quiz"type)totalItemsnumberThe number of items enclosed within this tag itemsQuiz[]|undefinedThe items enclosed in this tag. This property will always be undefinedexcept on two circumstances:
1. You call thegetItemsmethod with thesaveparameter set totrue
2. You call thegetByIDstatic method with thesaveparameter set totrue
User
TheUserclass is a class that holds several aliases to the other class methods that get content based on a user idMethods
Type Method Parameters Returns Description Example staticgetByIDParameter Type Default Description idstringRequired The user's ID Promise<User>Gets a user from their ID await User.getByID("abcdef")dynamicgetQuizzesNone Promise<Quiz[]>Gets the quizzes that the user has created await myUser.getQuizzes()dynamicgetMemeSetsNone Promise<MemeSet[]>Gets the memesets that the user has created await myUser.getMemeSets()dynamicgetTagsNone Promise<Tag[]>Gets all the tags that the user has created await myUser.getTags()Properties
Property Types Description idstringThe user's ID numOfQuizzesnumberThe number of quizzes that this user has created numOfTagsnumberThe number of tags (or "collections") that this user has created numOfMemeSetsnumberThe number of memesets that this user has created firstNamestringThe user's first name lastNamestringThe user's last name usernamestringThe user's username occupationstringThe user's occupation avatarstringThe user's avatar coursesAn array of Courseobjects:Property Types Description displayNamestringThe display name of this course internalNamestringThe internal name of this course _idstringThe course's ID uniqueNamestringThe unique name of this course The courses that the user is enrolled with organizationProperty Types Description ---------- ---------- ------------------------------ idstringThe organization ID namestringThe name of the organization typestringThe type of the organization The user's organization (This may be
undefined)
Game
TheGameclass is probably the most complex class in this package. This class allows you to join a Quizizz game as a client.Methods
Type Method Parameters Returns Description Example dynamicjoinGameParameters Types Default Description pinstringnumberRequired The room PIN namestring"jsQuizizz Bot"The name to join the room with avatarIDnumber1The ID of the avatar you would like to join with. TODO: Add Avatar ID's to a new static property within GameoptionsParameters Types Default Description correctPointsnumber1000How many points to give the player if they answer correctly. (0-7500) incorrectPointsnumber0How many points to give the player if they answer incorrectly. (0-5000) timenumber1When Quizizz asks the client how long it took to answer, what should the client respond? streakBoostnumber6When the streak-boostpowerup is used, how far should the streak be boosted? (This parameter is only client-side, and is used for point evaluation, but in our instance, we custom set the points, so this parameter serves no real purpose)The optional parameters for the game Promise<Nothing>Joins the Quizizz game await myGame.joinGame(123456, "Not_A_Robot", { correctPoints: 1000 });dynamicleaveGameNone Nothing Leaves the Quizizz Game. This will cause the disconnectevent to firemyGame.leaveGame()dynamicskipQuestionNone Nothing Skips the current question myGame.skipQuestion()dynamicactivatePowerupParameters Types Default Description pustringRequired The powerup to use. (See the myGame.powerupsarray for the powerups)targetsstring[][]For the send-giftpowerup, you must specify a list of player IDs as targets. See powerups for more information on this unique powerupPromise<Nothing>Activates the powerup provided await myGame.activatePowerup(myGame.powerups["50-50"])dynamicanswerParameters Types Default Description answerstringnumber[]numberRequired The answer to the current question Promise<Nothing>Answers the current question with the answer provided await myGame.answer(1)Properties
Events
Event Data Description disconnectProperty Types Description codenumberThe disconnect code reasonbufferThe disconnect reason The disconnectevent is fired when the client gets disconnected from the websocketstartNone The startevent is fired when the game has starteddoneAnsweringNone The doneAnsweringevent is fired when the client has answered all the questionsjoinNone The joinevent is fired when the client successfully joins the gamepowerupProperty Types Description namestringThe powerup's name visibleOptionsnumber[]undefinedThe new visible options for the current question. Is always undefinedunless the powerup used is50-50oreraserstreakChangeBynumberThe streak boost that the client received. Is always undefinedunless the powerup used isstreak-boosterThe
powerupevent is fired when a powerup has been successfully activatedgameEndedLeaderboard[]The gameEndedevent is fired when the game has endedkickType Description stringThe player's ID The
kickevent is fired when a player has been kicked from the gameanswerProperty Types Description streakProperty Types Description currentStreaknumberThe client's current streak maximumStreaknumberThe client's highest streak in the game The client's streak isCorrectbooleanWhether the client was correct or not attemptnumberThe attempt on the question. (As of my testing, this value is always the same) scorenumberThe client's current score leaderboardLeaderboard[]The game's current leaderboard The answerevent is fired when the client answers a questionquestionProperty Types Description questionQuestionContentThe question query answersQuestionContent[]The answers incorrectAnswers(string|number[]|number)[]The incorrect options. This array populates when immunityis used, and the question is attempted againtypestringThe question type ( MCQ,MSQ,DRAW,MATCH,REORDER,BLANK, and a few others)The
questionevent is fired when the client needs to answer a question. (It is HIGHLY RECOMMENDED that themyGame.answermethod is called within the listener for this event)
Types
-
Property Types Description typestringThe content type mediaAn array of Mediaobjects:Property Types Description typestringThe media type videostringThe media's video metaProperty Types Description widthnumberThe media's width heightnumberThe media's height layoutstringThe layout of the media textstringThe media's text content bgColorstringThe media's background color videoIdstringThe video ID associated with the media startnumberThe start time of the media endnumberThe end time of the media durationnumberHow long should the media run for? kindstringThe kind of media embeddablebooleanWhether the media is embeddable titlestringThe media's title latnumberThe latitude of the media longnumberThe longitude of the media headingstringThe heading of the media pitchnumberThe pitch of the media The media's metadata The content's media textstring[]stringThe content text hasMathbooleanWhether the content has math mathProperty Types Description latexstring[]The latex math templatestringThe template The question's latex math -
Property Types Description namestringThe player's name ranknumberThe player's rank scorenumberThe player's final score
-
Examples
// The only class we need is Game
import { Game } from './src/index.js';
// Everything is async, so we make a holder function
(async function() {
// Create a new game
const myGame = new Game();
// setup the events
myGame.on("disconnect", data => {
console.log(`Oh no! You disconnected with exit code ${data.code}.\n The reason for disconnect was ${data.reason.toString()}`);
})
myGame.on('start', () => console.log("The game is starting"));
myGame.on("doneAnswering", () => console.log("You answered all the questions!"));
myGame.on("join", () => console.log("You're in!"));
myGame.on("powerup", data => {
console.log(`You used the ${data.name} powerup!`);
if (["50-50","eraser"].includes(data.name)) {
console.log(`Now, the possible answers are: ${data.visibleOptions.join(', ')}`)
} else if (data.name === "streak-booster") {
console.log(`Your streak has been boosted by ${data.streakChangeBy}!`)
}
});
myGame.on("gameEnded", data => {
data.forEach(leaderboard => {
console.log(`${leaderboard.name} finished with a rank of #${leaderboard.rank} and a score of ${leaderboard.score}`)
})
});
myGame.on("kick", data => console.log(`${data} was kicked from the game`));
myGame.on("answer", data => {
console.log(`You answered ${data.isCorrect ? "" : "in"}correctly on attempt #${data.attempt}. ${data.score} has been added to your score. Your streak is ${data.streak.currentStreak}.`)
});
myGame.on("question", data => {
switch (data.type) {
case "MATCH":
case "MSQ":
case "REORDER":
myGame.answer(/* my answer */ Array(data.answers.length).fill(0).map((_0, index) => index))
break;
case "MCQ":
myGame.answer(/* my answer */ 0)
break;
case "DRAW":
case "BLANK":
myGame.answer("I <3 RedYetiDev")
break;
default:
console.log(data.type + ": Skipped");
myGame.skip();
}
})
// join the game
myGame.joinGame("560018", "RedYetiDev", 1, {
correctPoints: 2000,
incorrectPoints: 500
})
})();