0

Create Draft Reply

by
Published today

Create a draft reply (or reply-all) to a message without sending it. Returns the draft; send it with Send Draft. Requires Mail.ReadWrite (a connection default).

Script outlook Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 hours ago
1
//native
2

3
/**
4
 * Create Draft Reply
5
 * Create a draft reply (or reply-all) to a message without sending it. Returns the draft; send it with Send Draft. Requires Mail.ReadWrite (a connection default).
6
 */
7
export async function main(
8
  auth: RT.Outlook,
9
  message_id: string,
10
  comment: string | undefined,
11
  reply_all: boolean = false,
12
  mailbox: string | undefined
13
) {
14
  const base = `https://graph.microsoft.com/v1.0/${
15
    mailbox != null && mailbox !== ""
16
      ? `users/${encodeURIComponent(mailbox)}`
17
      : "me"
18
  }`
19
  const response = await fetch(
20
    `${base}/messages/${encodeURIComponent(message_id)}/${
21
      reply_all ? "createReplyAll" : "createReply"
22
    }`,
23
    {
24
      method: "POST",
25
      headers: {
26
        Authorization: `Bearer ${auth.token}`,
27
        "Content-Type": "application/json",
28
        Accept: "application/json",
29
      },
30
      body: JSON.stringify(
31
        comment != null && comment !== "" ? { comment } : {}
32
      ),
33
    }
34
  )
35

36
  if (!response.ok) {
37
    throw new Error(`${response.status} ${await response.text()}`)
38
  }
39

40
  return await response.json()
41
}
42