api = azure function (included chatgpt)

yo office 

 

 

taskpane.js

 

export async function run() {
  /**
   * Insert your Outlook code here
   *
   */
  let body = ''

  async function outputResult(body){
    console.log(body)
    let response = await runAzure(body)
    console.log(response.output)
  }
  async function getBody(){
    Office.context.mailbox.item.body.getAsync("text", function(result) {
      if (result.status == Office.AsyncResultStatus.Succeeded) {
        body = result.value
        outputResult(body)
      }
    })

  }

  async function runAzure(body) {
  const Url = 'your api site address';
  const otherParam = {
    body: '{"model":"text-davinci-003","prompt":"summarize the following in 50 words or less: ' + body.replace(/['"]+/g, '').trim().replace(/(\r\n|\n|\n)/gm, "") + '","max_tokens":200,"temperature":0}',
    method: 'POST'
  };
  const response = await fetch(Url,otherParam);
  var output = await response.text()
  return {output}

  }

  await getBody()
}
 
 
위 내용을 조금 다르게...  로그내용 출력
 
export async function run() {
  /**
   * Insert your Outlook code here
   *
   */
  let body = ''

  async function outputResult(body){
    console.log(body)
    let response = await runAzure(body)
    console.log(response.output)
  }
  async function getBody(){
    Office.context.mailbox.item.body.getAsync("text", function(result) {
      if (result.status == Office.AsyncResultStatus.Succeeded) {
        body = result.value
        outputResult(body)
      }
    })

  }

  async function runAzure(body) {
  const Url = 'your api address';
  const bodyjson = '{"model":"text-davinci-003","prompt":"summarize the following in 50 words or less: ' + body.replace(/['"]+/g, '').trim().replace(/(\r\n|\n|\n)/gm, "") + '","max_tokens":200,"temperature":0}'
  console.log(bodyjson)
  const otherParam = {
    body: bodyjson,
    method: 'POST'
  };
  const response = await fetch(Url,otherParam);
  var output = await response.text()
  return {output}

  }

  await getBody()
}

your api address = azure function [for chatgpt api : post]

 

메일 내용을 요약해서 보여줌

 

/*
 * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
 * See LICENSE in the project root for license information.
 */

/* global document, Office */

Office.onReady((info) => {
  if (info.host === Office.HostType.Outlook) {
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = run;
  }
});

export async function run() {
  /**
   * Insert your Outlook code here
   *
   */
  let body = ''

  async function outputResult(body){
    console.log(body)
    let response = await runAzure(body)
    console.log(response.output)
    document.getElementById('app-body').innerHTML = "<b>Summary: </b><br/>" + response.output
  }
  async function getBody(){
    Office.context.mailbox.item.body.getAsync("text", function(result) {
      if (result.status == Office.AsyncResultStatus.Succeeded) {
        body = result.value
        outputResult(body)
      }
    })

  }

  async function runAzure(body) {
  const Url = 'your ajpi site address';
  const bodyjson = '{"model":"text-davinci-003","prompt":"summarize the following in 50 words or less: ' + body.replace(/['"]+/g, '').trim().replace(/(\r\n|\n|\n)/gm, "") + '","max_tokens":200,"temperature":0}'
  console.log(bodyjson)
  const otherParam = {
    body: bodyjson,
    method: 'POST'
  };
  const response = await fetch(Url,otherParam);
  var output = await response.text()
  return {output}

  }

  await getBody()
}

 

Summarize This Email 선택시 기존에서는 콘솔(개발자모드)에서 내용이 보였으나 이젠 그냥 화면에 보임

 

 

Full+code+in+task_pane.js.txt
0.00MB
Fake+email.txt
0.00MB
CORS+policy.txt
0.00MB

 

회신기능

 

export async function run() {
  /**
   * Insert your Outlook code here
   */

  const item = Office.context.mailbox.item
  async function getBody(){
    Office.context.mailbox.item.body.getAsync("text",function(result){
      if (result.status == Office.AsyncResultStatus.Succeeded){
        let body =  result.value
       
        PutItAllTogether(body)
     
      }
    })
  }
async function RunAPI(body){
  const Url = 'https://~'
  const bodyJson ='{"model":"text-davinci-003","prompt":"Reply to the following email and  politely and professionally manner while saying no '+  body.replace(/['"]+/g, '').trim().replace(/(\r\n|\n|\r)/gm, "") +'","max_tokens":400,"temperature":0}'
  console.log(bodyJson)
  const otherParam = {
    body: bodyJson,
    method: 'POST'
  }
  const response = await fetch(Url, otherParam)
  var output = await response.text()

  return {output}

}

async function PutItAllTogether(body){

  console.log(body)
  let response = await RunAPI(body)
  console.log(response)
  item.displayReplyForm(response.output)
}

await getBody()
}

 

Generate Reply 클릭시 - 자동회신 양식을 띄우고 회신 내용을 자동으로 채워줌 

 

+ Recent posts