|
12 | 12 |
|
13 | 13 |
|
14 | 14 | 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" |
16 | 21 |
|
17 | 22 | slack = WebClient(token=ACCESS_TOKEN)
|
18 | 23 |
|
@@ -54,22 +59,29 @@ def create_messages(notes: list[Note]) -> Generator[dict, None, None]:
|
54 | 59 | # see https://api.slack.com/reference/surfaces/formatting
|
55 | 60 |
|
56 | 61 | 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}" |
60 | 69 |
|
| 70 | + header_text = f"[{target_type}] {target_name}:" |
61 | 71 | note_text = f"> {note.body}"
|
62 | 72 | created_by_text = f"*Created by:*\n{note.name_user}"
|
63 | 73 | date_fmt = f"<!date^{note.created_at}^{{date_long}} at {{time}}|{note.created_at}>"
|
64 | 74 | created_on_text = f"*Created on:*\n{date_fmt}"
|
| 75 | + link_text = f"<{url}|View in Hubspot>" |
65 | 76 |
|
66 | 77 | yield dict(
|
67 |
| - channel=CHANNEL_ID, |
68 |
| - text=header, |
| 78 | + channel=CHANNEL, |
| 79 | + text=header_text, |
69 | 80 | blocks=[
|
70 |
| - HeaderBlock(text=header), |
| 81 | + HeaderBlock(text=header_text), |
71 | 82 | 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)), |
73 | 85 | ],
|
74 | 86 | )
|
75 | 87 |
|
|
0 commit comments