update-draft.ts
1 import * as pronote from "../../src"; 2 import { credentials } from "../_credentials"; 3 4 void async function main () { 5 const session = pronote.createSessionHandle(); 6 await pronote.loginCredentials(session, { 7 url: credentials.pronoteURL, 8 kind: pronote.AccountKind.STUDENT, 9 username: credentials.username, 10 password: credentials.password, 11 deviceUUID: credentials.deviceUUID 12 }); 13 14 if (!session.user.authorizations.canDiscuss) 15 throw new Error("This account can't discuss, review the permissions."); 16 17 if (!session.user.authorizations.canDiscussWithTeachers) 18 throw new Error("This account can't discuss with teachers, review the permissions."); 19 20 const discussions = await pronote.discussions(session); 21 22 // Select the first discussion available. 23 const discussion = discussions.items[0]; 24 25 console.info("Opening discussion:", discussion.subject); 26 console.log("Containing", discussion.numberOfDrafts, "draft(s) !"); 27 28 // Fetch the messages from the discussion. 29 const messages = await pronote.discussionMessages(session, discussion); 30 31 for (const draft of messages.drafts) { 32 draft.content = "Updated @ " + Date.now() + " ; Original: " + draft.content; 33 await pronote.discussionRemoteMutateDraft(session, discussion, draft); 34 35 console.log("Updated:", draft.content); 36 } 37 }(); 38