Accelerate Daily Supplemental Recipe #2 - AI Email Responses

The following codeblock was referenced on Accelerate Daily on May 22, 2023.


// GPT-4 Auto Email Responder
// 1. create imap email accessor
var imap = new Imap({
  user: 'mygmailname@gmail.com',
  password: 'mygmailpassword',
  host: 'imap.gmail.com',
  port: 993,
  tls: true
});
// imap enables an imap.openBox function where we can fetch emails
// 2. prepare GPT-4
const primingMessage = {
 role: "system",
 content: "You are an email answering AI named Assistant. You work at a company called GPTBoss. GPTBoss is an AI tools for business company run by a developer. You can answer email questions about cancelling accounts, media appearances for the founder, and technical questions about GPT-4 development."};
const primingSequence = [
  primingMessage,  
  {role: "user", content: `Hey, I got this email from ${mostRecentEmail.header.from}. It's this: "${mostRecentEmail.body}". Can you draft a response, please?`}];
const options = {
  model: "gpt-4",
  messages: primingSequence
};
// send to openai
let openAiResponse = await openAI.createChatCompletion(options);
let  msg = mimemessage.factory({contentType: 'multipart/alternate', body: []});
let plainEntity = mimemessage.factory({body: openaiResponse?.data?.[0]?.message?.content});
msg.header('To', mostRecentMessage.from);
msg.header('Subject', `RE: ${mostRecentMessage.subject}`);
msg.body.push(plainEntity);
imap.append(msg.toString());

This blog post will have further supplemental notes in the future. You can find the audio recording from Mission Control on Youtube at: https://www.youtube.com/@UseMissionControl

Contact
  • mackenzie@gptboss.com
OTHER
  • Our Sponsors
  • Hire Us as Developers
SOCIALS

GPTBoss 2.0 Beta

|