AutoKhan.js is a nodeJS library that allows your to make your own bot for Khan Academy. Your bot can automatically comment on programs, create programs, and do almost anything that a normal user can. There are a few simple steps required for setup and your bot will be ready.
Here's how all the functions work + setup for your bot.
AutoKhan is in NodeJS and is prefered to be running on replit. You can run this on almost any nodeJS environment if you want to. To download the files, run this code in your terminal:
git clone https://github.com/kqwq/KhanBot.git
index.js is where all your work will be done. The environment should already be a basic async function and an express server. Run npm install in your terminal and you are almost ready to go.
The last step to completing the setup is getting your Khan Academy Account Token (KAAS). You should never share this with anyone and should keep it in an .env file.
To get this secret, make sure you have NodeJS installed at least. Run these following steps in the terminal:
$node
$const { utils } = require('./src/core.js');
$utils.getKAAS("[insert username]","[insert password]");
(Press CTRL+C twice to exit)
You should now have your KAAS secret. Store that in the .env file. If you are on replit, click the lock icon on the left sidebar and name the secret "KAAS" and set its value to your account token.
If you are using this locally, create a new file called .env and insert KAAS=KAAS_SECRET. No quotes.
All of your code has to be in the async function given at startup. For example, to post a comment on a particular program scratchpad, here is the code required:
(async () => {
const { get, post, utils } = require('./src/core.js');
await post.feedback("This is the feedback content", "[program id]")
})();So just to let you know, you will be having to use async/await quite a bit. Let's dive into the docs!
All of the Autokhan functions will be listed here, starting with simple GET requests and then to POST, PUT, and DELETE requests. GET requests will return JSON and the others later on actually do things like posting comments, making programs, etc.
Basic information about the user
console.log(await get.user.profile("kaid_5019699394927714061666523"))Discussion Summary
console.log(await get.user.discussion("kaid_5019699394927714061666523"))Discussion Stats
console.log(await get.user.discussion_stats("kaid_5019699394927714061666523"))Question Summary
console.log(await get.user.questions("kaid_5019699394927714061666523"))Answer Summary
console.log(await get.user.answers("kaid_5019699394927714061666523"))Tips & Thanks Summary
console.log(await get.user.tips_thanks("kaid_5019699394927714061666523"))Widgets
console.log(await get.user.widgets("kaid_5019699394927714061666523"))Comment Summary
console.log(await get.user.comments("kaid_5019699394927714061666523"))Tips & Thanks Summary
console.log(await get.user.projects("kaid_5019699394927714061666523"))Help Request Summary
console.log(await get.user.project_help("kaid_5019699394927714061666523"))How many help requests the user has answered to
console.log(await get.user.project_answers("kaid_5019699394927714061666523"))Badges Summary
console.log(await get.user.badges("kaid_5019699394927714061666523"))Returns a number programs on the hotlist "Hot" page
console.log(await get.browse.hot(30))Returns a number programs on the hotlist "Recent" page
console.log(await get.browse.recent(30))Returns a number programs on the hotlist "Contests" page
console.log(await get.browse.contests(30))Returns a number programs on the hotlist "Top" page
console.log(await get.browse.top(30))Returns full data of a project
console.log(await get.scratchpad.full_data(5095429626609664))Returns the general data of a project
console.log(await get.scratchpad.data(5095429626609664))Returns the spin-offs of a project. limit is an optional argument, default set to 1000
console.log(await get.scratchpad.spinoffs(5095429626609664, 30))Returns the questions asked on a project. limit is an optional argument, default set to 1000
console.log(await get.scratchpad.questions(5095429626609664, 30))Returns the feedback/Tips & Thanks posted on a project. limit is an optional argument, default set to 1000
console.log(await get.scratchpad.feedback(5095429626609664, 30))Returns all the comments in a thread.
console.log(await get.discussion.thread("kaencrypted_ecac7f3960e834a2b08fe89dcf64d9dc_d87d42f98e6da3bdb170c25e7d466841cd5377c29a38ffdf8c7faeb7beb59cc00034ba66237f571b44cbfda37cbebf14192e56b13019ae7e8413950ac18addc0745a9d0faade63259c76b28a6c67798711a0df1b79ef21990dd576dcba0d587f537335f177b9b656582be76d35ba0a3e5cdf9ebf77ffb1db47bbe1fc59d3808953a41466ae212b1fdcd78923f520eaef573dcc2923e643c23e24abb62d2be399498ac10d9854b787c4f3c06ad4c8e4c995fa75894303bce6a5b6fcdf6d02c4e2"))Now comes the fun part - How your bot will actually run.
console.log(await post.comment("Comment Content", "kaencrypted_ecac7f3960e834a2b08fe..."))console.log(await post.feedback("Feedback Content", 5961976947621888))console.log(await post.del_feedback("kaencrypted_ecac7f3960e834a2b08fe...", 5961976947621888))console.log(await post.voteProgram(5961976947621888))base64 is the screenshot of the program. You can customize it or leave the param empty as it sets your program's screenshot to a plain white background by default. type has to be either "pjs" or "webpage". Default set to "pjs".
console.log(await post.scratchpad("//code here", "title!!", "data:image/png;base64,iVBOR...", "pjs"))Update Program post.updateProgram(id: number, newCode: string, newTitle: string, newWidth: number, newHeight: number, base64: string)
newWidth and newHeight are set to 400 by default and base64 sets up a blank white screenshot by default.
console.log(await post.updateProgram(5961976947621888, "//new code here", "new title!!", 600, 600, "data:image/png;base64,iVBOR..."))console.log(await post.deleteProgram(5961976947621888))console.log(await post.updateProfile("AutoKhan [Bot]", "AutoKhanBot", "I am a bot - This is my bio", "kaid_5019699394927714061666523"))console.log(await post.updateAvatar("piceratops_ultimate_style", "kaid_5019699394927714061666523"))console.log(await post.askQuestion("Question Content", 5961976947621888))console.log(await post.answerQuestion("Answer Content", "kaencrypted_ecac7f3960e834a2b08fe..."))logs your account token to the console
utils.getKAAS("username","password123")//posts a feedback post on a program every minute
setInterval(async () => {
await post.feedback("I post feedback every minute on the same program!!", 5961976947621888)
}, 60000);No more examples for now. Sorry!!
Conner1115 (LeviathanProgramming), kqwq (Squishy), Phi-001 (Phi)