Created
January 19, 2026 01:27
-
-
Save gnh1201/ecb2bf544005968a42f108aaed99849b to your computer and use it in GitHub Desktop.
Analyze Microsoft Outlook data with ChatGPT (Require WelsonJS framework)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Analyze Microsoft Outlook data with ChatGPT | |
| // Require: WelsonJS framework (https://github.com/gnh1201/welsonjs) | |
| // Workflow: Microsoft Outlook -> OpenAI -> Get Response | |
| var Office = require("lib/msoffice"); | |
| var LIE = require("lib/language-inference-engine"); | |
| function main(args) { | |
| var prompt_texts = []; | |
| var keyword = "example.com"; | |
| var maxCount = 10; | |
| var previewLen = 160; | |
| console.log("Searching mails by sender OR recipient contains: '" + keyword + "'."); | |
| console.log("This test uses Restrict (Sender/To/CC/BCC) + Recipients verification."); | |
| console.log("Body preview length: " + previewLen); | |
| var outlook = new Office.Outlook(); | |
| outlook.open(); | |
| outlook.selectFolder(Office.Outlook.Folders.Inbox); | |
| var results = outlook.searchBySenderOrRecipientContains(keyword); | |
| console.log("Printing search results. (max " + maxCount + ")"); | |
| results.forEach(function (m, i) { | |
| var body = String(m.getBody() || ""); | |
| var preview = body.replace(/\r/g, "").replace(/\n+/g, " ").substr(0, previewLen); | |
| var text = "#" + String(i) + | |
| " | From: " + String(m.getSenderEmailAddress()) + | |
| " | To: " + String(m.mail.To || "") + | |
| " | Subject: " + String(m.getSubject()) + | |
| " | Received: " + String(m.getReceivedTime()); | |
| console.log(text); | |
| console.log(" Body: " + preview); | |
| // Add an email data to the prompt text context | |
| prompt_texts.push(text); | |
| // The body to reduce token usage and avoid sending overly large/sensitive content. | |
| var bodyForPrompt = body; | |
| var maxBodyLengthForPrompt = 2000; // Keep the body snippet short | |
| if (bodyForPrompt.length > maxBodyLengthForPrompt) { | |
| bodyForPrompt = bodyForPrompt.substring(0, maxBodyLengthForPrompt) + "..."; | |
| } | |
| prompt_texts.push(" Body: " + bodyForPrompt); | |
| }, maxCount); | |
| outlook.close(); | |
| // build a AI prompt text | |
| var instruction_text = "This is an email exchange between the buyer and me, and I would appreciate it if you could help me write the most appropriate reply."; | |
| prompt_texts.push(instruction_text); | |
| // complete the prompt text | |
| var prompt_text_completed = prompt_texts.join("\r\n"); | |
| //console.log(prompt_text_completed); // print all prompt text | |
| // get a response from AI | |
| var response_text = LIE.create().setProvider("openai").inference(prompt_text_completed, 0).join(' '); | |
| console.log(response_text); | |
| } | |
| exports.main = main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment