From 12dd2a95513a2fccb052cb9ef4b2871501b49c98 Mon Sep 17 00:00:00 2001 From: hahahafafa <94551263+hahahafafa@users.noreply.github.com> Date: Tue, 14 Nov 2023 18:51:20 -0500 Subject: [PATCH 1/2] outlook integration 1. outlookintegration.ts created 2. implement outlook api for read and send message 3. export the function to index.ts --- langchain/src/tools/index.ts | 1 + langchain/src/tools/outlookIntegration.ts | 94 +++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 langchain/src/tools/outlookIntegration.ts diff --git a/langchain/src/tools/index.ts b/langchain/src/tools/index.ts index f299550163..3996ea21c2 100644 --- a/langchain/src/tools/index.ts +++ b/langchain/src/tools/index.ts @@ -47,3 +47,4 @@ export { formatToOpenAIFunction, formatToOpenAITool, } from "./convert_to_openai.js"; +export { OutlookIntegration } from "./outlookIntegration.js"; \ No newline at end of file diff --git a/langchain/src/tools/outlookIntegration.ts b/langchain/src/tools/outlookIntegration.ts new file mode 100644 index 0000000000..56f125b4c8 --- /dev/null +++ b/langchain/src/tools/outlookIntegration.ts @@ -0,0 +1,94 @@ +import { Tool, type ToolParams } from "./base.js"; +import fetch from 'node-fetch'; + +export interface Email { + sender: string; + subject: string; + // Add other properties as needed +} + +export class OutlookIntegration extends Tool { + accessToken: string; // Store the OAuth2 access token + + constructor(params: ToolParams, accessToken: string) { + super(params); + this.accessToken = accessToken; // Initialize with an OAuth2 access token + } + + async readEmails(): Promise { + try { + const response = await fetch("https://graph.microsoft.com/v1.0/me/mailFolders('Inbox')/messages?$select=sender,subject", { + headers: { + Authorization: `Bearer ${this.accessToken}`, + }, + }); + + if (!response.ok) { + throw new Error(`Error: ${response.status}`); + } + + const data = await response.json(); + return data.value; // Assuming 'value' contains the array of emails + } catch (error) { + console.error("Failed to read emails:", error); + throw error; + } + } + + async sendEmail(to: string, subject: string, content: string): Promise { + const message = { + message: { + subject: subject, + body: { + contentType: "Text", + content: content, + }, + toRecipients: [ + { + emailAddress: { + address: to, + }, + }, + ], + }, + }; + + try { + const response = await fetch("https://graph.microsoft.com/v1.0/me/sendMail", { + method: "POST", + headers: { + Authorization: `Bearer ${this.accessToken}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(message), + }); + + if (!response.ok) { + throw new Error(`Error: ${response.status}`); + } + + console.log("Email sent successfully"); + } catch (error) { + console.error("Failed to send email:", error); + throw error; + } + } + + // You can add more methods for other features like managing contacts, calendar, etc. + +} + + +// import fetch from "node-fetch"; + +// const accessToken = "YOUR_ACCESS_TOKEN"; + +// const response = await fetch("https://graph.microsoft.com/v1.0/me/messages", { +// headers: { +// Authorization: `Bearer ${accessToken}`, +// }, +// }); + +// const data = await response.json(); + +// console.log(data); \ No newline at end of file From cd66216335ddb7d0a8a7f5b020b91ecc26a9389b Mon Sep 17 00:00:00 2001 From: "local-dev-korbit-ai-mentor[bot]" <130798245+local-dev-korbit-ai-mentor[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:15:54 +0000 Subject: [PATCH 2/2] [skip ci]