Unlisted
Versions
- Open: VersionChanges from v5 to v6+6-2⦚ 63 unchanged lines ⦚});
return completion.choices[0].message.content;}⦚ 10 unchanged lines ⦚`${baseURL}/A1:C1:append?valueInputOption=RAW`,"POST",{ values: [data] },);}⦚ 12 unchanged lines ⦚export async function emailValHandler(email: Email) {console.log("Email received!", email.from, email.subject, email.text);const processedData = await processEmailWithAI(email.text);await logToGoogleSheet(processedData);}⦚ 63 unchanged lines ⦚});console.log(completion);return completion.choices[0].message.content;}⦚ 10 unchanged lines ⦚`${baseURL}/A1:C1:append?valueInputOption=RAW`,"POST",{ values: [...data] },);}⦚ 12 unchanged lines ⦚export async function emailValHandler(email: Email) {console.log("Email received!", email.from, email.subject);const processedData = await processEmailWithAI(email.text);console.log(processedData);await logToGoogleSheet(processedData);} - Open: VersionChanges from v4 to v5+1-1⦚ 12 unchanged lines ⦚const SHEET_ID = "1LABuHTok0SbPc-0IO3ffHn-Ah_1fO76L_je_6A-COHg";
// const openai = new OpenAI({ apiKey: OPENAI_API_KEY });// const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values`;⦚ 86 unchanged lines ⦚⦚ 12 unchanged lines ⦚const SHEET_ID = "1LABuHTok0SbPc-0IO3ffHn-Ah_1fO76L_je_6A-COHg";const openai = new OpenAI({ apiKey: OPENAI_API_KEY });// const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values`;⦚ 86 unchanged lines ⦚ - Open: VersionChanges from v3 to v4+18-10⦚ 57 unchanged lines ⦚role: "system",content:
"Extract key information from this email such as expenses, receipts, and invoices. Categorize the information.",},{ role: "user", content: emailContent },⦚ 16 unchanged lines ⦚`${baseURL}/A1:C1:append?valueInputOption=RAW`,"POST",{ values: [[Date(), Math.random(), 1]] },);}export default async function main(req: Request) {if (req.method !== "POST") {return new Response("Please send a POST request with email content", { status: 405 });}// const emailContent = await req.text();// const processedData = await processEmailWithAI(emailContent);await logToGoogleSheet();return new Response("Email processed and logged successfully", { status: 200 });}⦚ 57 unchanged lines ⦚role: "system",content:"Extract key information from this email such as expenses, receipts, and invoices. Categorize the information so it can be added to a spreadsheet row with the following columns Date, Amount, Currency, Description, Category, Notes",},{ role: "user", content: emailContent },⦚ 16 unchanged lines ⦚`${baseURL}/A1:C1:append?valueInputOption=RAW`,"POST",{ values: [data] },);}// export default async function main(req: Request) {// if (req.method !== "POST") {// return new Response("Please send a POST request with email content", { status: 405 });// }// // const emailContent = await req.text();// // const processedData = await processEmailWithAI(emailContent);// await logToGoogleSheet();// return new Response("Email processed and logged successfully", { status: 200 });// }export async function emailValHandler(email: Email) {console.log("Email received!", email.from, email.subject, email.text);const processedData = await processEmailWithAI(email.text);await logToGoogleSheet(processedData);} - Open: VersionChanges from v2 to v3+9-7⦚ 4 unchanged lines ⦚import { OpenAI } from "https://esm.town/v/std/openai";
import { google } from "npm:googleapis";const OPENAI_API_KEY = Deno.env.get("openai");const GOOGLE_SHEETS_API_KEY = "your-google-sheets-api-key";const SHEET_ID = "1LABuHTok0SbPc-0IO3ffHn-Ah_1fO76L_je_6A-COHg";const openai = new OpenAI({ apiKey: OPENAI_API_KEY });// const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values`;async function fetchAccessToken() {⦚ 68 unchanged lines ⦚}const emailContent = await req.text();const processedData = await processEmailWithAI(emailContent);await logToGoogleSheet(processedData);return new Response("Email processed and logged successfully", { status: 200 });}⦚ 4 unchanged lines ⦚import { OpenAI } from "https://esm.town/v/std/openai";// import { google } from "npm:googleapis";import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";const OPENAI_API_KEY = Deno.env.get("openai");// const GOOGLE_SHEETS_API_KEY = "your-google-sheets-api-key";const accountID = "apn_ygh4lKM";const SHEET_ID = "1LABuHTok0SbPc-0IO3ffHn-Ah_1fO76L_je_6A-COHg";// const openai = new OpenAI({ apiKey: OPENAI_API_KEY });// const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values`;async function fetchAccessToken() {⦚ 68 unchanged lines ⦚}// const emailContent = await req.text();// const processedData = await processEmailWithAI(emailContent);await logToGoogleSheet();return new Response("Email processed and logged successfully", { status: 200 });} - Open: VersionChanges from v1 to v2+57-14⦚ 11 unchanged lines ⦚const openai = new OpenAI({ apiKey: OPENAI_API_KEY });
const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });async function processEmailWithAI(emailContent: string) {const completion = await openai.chat.completions.create({model: "gpt-4",messages: [{ role: "system", content: "Extract key information from this email such as expenses, receipts, and invoices. Categorize the information." },{ role: "user", content: emailContent }],});⦚ 3 unchanged lines ⦚async function logToGoogleSheet(data: string) {await sheets.spreadsheets.values.append({spreadsheetId: SHEET_ID,range: 'Sheet1',valueInputOption: 'USER_ENTERED',requestBody: {values: [[new Date().toISOString(), data]]},});}export default async function main(req: Request) {if (req.method !== 'POST') {return new Response('Please send a POST request with email content', { status: 405 });}const emailContent = await req.text();const processedData = await processEmailWithAI(emailContent);⦚ 11 unchanged lines ⦚const openai = new OpenAI({ apiKey: OPENAI_API_KEY });// const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values`;async function fetchAccessToken() {const response = await fetch(`https://api.pipedream.com/v1/accounts/${accountID}?include_credentials=1`,{headers: {Authorization: `Bearer ${Deno.env.get("pipedream_api_key")}`,},},);if (!response.ok) {throw new Error(`Error fetching access token: ${response.statusText}`);}const { data } = await response.json();return data.credentials.oauth_access_token;}async function makeSheetsRequest(url, method, body = null) {const accessToken = await fetchAccessToken();const options: RequestInit = {method,headers: {Authorization: `Bearer ${accessToken}`,},};if (body) {options.body = JSON.stringify(body); - Open: VersionChanges from v0 to v1+3-2⦚ 6 unchanged lines ⦚import { google } from "npm:googleapis";
const OPENAI_API_KEY = "your-openai-api-key";const GOOGLE_SHEETS_API_KEY = "your-google-sheets-api-key";const SHEET_ID = "your-google-sheet-id";const openai = new OpenAI({ apiKey: OPENAI_API_KEY });const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });async function processEmailWithAI(emailContent: string) {⦚ 33 unchanged lines ⦚⦚ 6 unchanged lines ⦚import { google } from "npm:googleapis";const OPENAI_API_KEY = Deno.env.get("openai");const GOOGLE_SHEETS_API_KEY = "your-google-sheets-api-key";const SHEET_ID = "1LABuHTok0SbPc-0IO3ffHn-Ah_1fO76L_je_6A-COHg";const openai = new OpenAI({ apiKey: OPENAI_API_KEY });const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });async function processEmailWithAI(emailContent: string) {⦚ 33 unchanged lines ⦚ - Open: Version+49-0// This approach will use the OpenAI API to process email content and extract key information.// We'll use the Google Sheets API to log the extracted information.// Tradeoffs: This implementation assumes the email content is already available and doesn't handle email fetching.// It also uses inline API keys for simplicity, which isn't ideal for security in a production environment.import { OpenAI } from "https://esm.town/v/std/openai";import { google } from "npm:googleapis";const OPENAI_API_KEY = "your-openai-api-key";const GOOGLE_SHEETS_API_KEY = "your-google-sheets-api-key";const SHEET_ID = "your-google-sheet-id";const openai = new OpenAI({ apiKey: OPENAI_API_KEY });const sheets = google.sheets({ version: 'v4', auth: GOOGLE_SHEETS_API_KEY });async function processEmailWithAI(emailContent: string) {const completion = await openai.chat.completions.create({model: "gpt-4",messages: [{ role: "system", content: "Extract key information from this email such as expenses, receipts, and invoices. Categorize the information." },{ role: "user", content: emailContent }],});return completion.choices[0].message.content;}async function logToGoogleSheet(data: string) {await sheets.spreadsheets.values.append({spreadsheetId: SHEET_ID,range: 'Sheet1',valueInputOption: 'USER_ENTERED',requestBody: {values: [[new Date().toISOString(), data]]},});
Updated: August 20, 2024