Skip to content

Commit

Permalink
added logic for adding reply to old thread
Browse files Browse the repository at this point in the history
davidenders11 committed Oct 30, 2023
1 parent d89029e commit bcf6fd3
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions gmailwrapper.py
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ def get_thread(self, thread_id):
return thread


def new_draft(self, subject, content, other):
def draft(self, subject, content, other, thread_id=None):
"""Create and insert a draft email.
Print the returned draft's message and id.
Returns: Draft object, including draft id and message meta data.
@@ -127,8 +127,11 @@ def new_draft(self, subject, content, other):

# encoded message
encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode()

body = {"message": {"raw": encoded_message}}
# add thread id if replying
if thread_id:
body["threadId"] = str(thread_id)

draft = (
self.service.users().drafts().create(userId="me", body=body).execute()
)
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -47,7 +47,10 @@ def main():
# generate the draft and create it on gmail
content = openai.write_draft(thread, update, gmail.me, address)
logger.info("Draft has been generated, OpenAI call complete")
gmail.new_draft(subject, content, address)
if args.reply:
gmail.draft(subject, content, address, last_thread_id)
else:
gmail.draft(subject, content, address)
logger.info(
f"\nYour draft has been created!\nRecipient: {address}"+
"\nSubject: {subject}\nContent: {content}\n"

0 comments on commit bcf6fd3

Please sign in to comment.