Skip to content

Commit

Permalink
Use draft instead of notes to deploy faster
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Jan 14, 2021
1 parent 8c8b2ca commit 39631b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 4 additions & 3 deletions deployer/src/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from . import helpers
from . import fetchers

from .helpdesk_helper import add_note, get_conversation_with_threads, \
from .helpdesk_helper import add_draft, get_conversation_with_threads, \
get_emails_from_conversation, get_conversation_url_from_cuid

from deployer.src.algolia_internal_api import remove_user_from_index
Expand Down Expand Up @@ -100,14 +100,15 @@ def add_config(self, config_name):

# Add email(s) to the private config & grant access
conversation_with_threads = get_conversation_with_threads(cuid)
emails_from_conv = get_emails_from_conversation(conversation_with_threads)
emails_from_conv = get_emails_from_conversation(
conversation_with_threads)
analytics_statuses = emails.add(config_name, self.private_dir,
emails_to_add=emails_from_conv)

note_content = snippeter.get_email_for_config(config_name,
analytics_statuses)

add_note(cuid, note_content)
add_draft(cuid, note_content)

print(
'Email address fetched and stored, conversation updated and available at {}\n'.format(
Expand Down
24 changes: 21 additions & 3 deletions deployer/src/helpdesk_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,34 @@ def get_emails_from_conversation(conversation_with_threads):
return emails


def add_note(cuid, body):
def get_customer_id(cuid):
app_id = get_helpscout_app_id()
app_secret = get_helpscout_app_secret()
hs = HelpScout(app_id, app_secret)

for conversation in hs.hit('conversations', 'get', resource_id=cuid):
customer_id = conversation["createdBy"]["id"]

return customer_id


def add_draft(cuid, body):
app_id = get_helpscout_app_id()
app_secret = get_helpscout_app_secret()
hs = HelpScout(app_id, app_secret)

customer_id = get_customer_id(cuid)

if customer_id is None:
return False

# Inserting HTML code into HTML mail, snippet need to be HTML escaped
body = html.escape(body)

data = {"text": body}
hs.conversations[cuid].notes.post(data=data)
data = {"text": body, "draft": True, "customer": {
"id": customer_id
}, }
hs.conversations[cuid].reply.post(data=data)

return True

Expand Down

0 comments on commit 39631b1

Please sign in to comment.