Skip to content

Commit c5ace33

Browse files
committed
feat(notes/post): add link back to Hubspot engagement
1 parent a2517c4 commit c5ace33

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.env.sample

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
HUBSPOT_ACCESS_TOKEN=token
2+
HUBSPOT_INSTANCE_ID=instance
23
HUBSPOT_MAX_PAGES=1
34
HUBSPOT_PAGE_SIZE=10
45
HUBSPOT_VENDORS_RUN_MODE=1

notes/post.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313

1414
ACCESS_TOKEN = os.environ["SLACK_ACCESS_TOKEN"]
15-
CHANNEL_ID = os.environ["SLACK_CHANNEL_ID"]
15+
CHANNEL = os.environ["SLACK_CHANNEL_ID"]
16+
HUBSPOT_INSTANCE = os.environ["HUBSPOT_INSTANCE_ID"]
17+
18+
# Hubspot magic numbers
19+
COMPANIES = "0-2"
20+
VENDORS = "2-22517187"
1621

1722
slack = WebClient(token=ACCESS_TOKEN)
1823

@@ -54,22 +59,29 @@ def create_messages(notes: list[Note]) -> Generator[dict, None, None]:
5459
# see https://api.slack.com/reference/surfaces/formatting
5560

5661
for note in notes:
57-
target_name = note.name_company or note.name_vendor
58-
target_type = "Transit Agency" if note.name_company else "Vendor"
59-
header = f"[{target_type}] {target_name}:"
62+
if note.name_company:
63+
target_name, target_id, target_type, type_id = (note.name_company, note.id_company, "Transit Agency", COMPANIES)
64+
else:
65+
target_name, target_id, target_type, type_id = (note.name_vendor, note.id_vendor, "Vendor", VENDORS)
66+
67+
note_id = note.id_note
68+
url = f"https://app.hubspot.com/contacts/{HUBSPOT_INSTANCE}/record/{type_id}/{target_id}/view/1?engagement={note_id}"
6069

70+
header_text = f"[{target_type}] {target_name}:"
6171
note_text = f"> {note.body}"
6272
created_by_text = f"*Created by:*\n{note.name_user}"
6373
date_fmt = f"<!date^{note.created_at}^{{date_long}} at {{time}}|{note.created_at}>"
6474
created_on_text = f"*Created on:*\n{date_fmt}"
75+
link_text = f"<{url}|View in Hubspot>"
6576

6677
yield dict(
67-
channel=CHANNEL_ID,
68-
text=header,
78+
channel=CHANNEL,
79+
text=header_text,
6980
blocks=[
70-
HeaderBlock(text=header),
81+
HeaderBlock(text=header_text),
7182
SectionBlock(text=MarkdownTextObject(text=note_text)),
72-
SectionBlock(fields=[MarkdownTextObject(text=created_by_text), MarkdownTextObject(text=created_on_text)])
83+
SectionBlock(fields=[MarkdownTextObject(text=created_by_text), MarkdownTextObject(text=created_on_text)]),
84+
SectionBlock(text=MarkdownTextObject(text=link_text)),
7385
],
7486
)
7587

0 commit comments

Comments
 (0)