|
| 1 | +# Hubspot notes |
| 2 | + |
| 3 | +The code in this directory defines a process that syncs notes from Hubspot associated with Transit Agencies and Vendors into |
| 4 | +Cal-ITP Slack for wider visibility. |
| 5 | + |
| 6 | +Notes are synced into the [`#notify-hubspot-notes`](https://cal-itp.slack.com/archives/C07C3ADGJ4S) channel. |
| 7 | + |
| 8 | +The process is run every hour with a [GitHub Actions workflow](../.github/workflows/notes-sync.yml). |
| 9 | + |
| 10 | +A GitHub [repository variable](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables) is used to maintain the `last_note_id` (the ID of the most recently processed note) between successive runs of the workflow. |
| 11 | + |
| 12 | +## `download.py` |
| 13 | + |
| 14 | +This script is responsible for downloading the latest notes using the Hubspot API: |
| 15 | + |
| 16 | +1. Parse `last_note_id` |
| 17 | + - Initially, `last_note_id` will be empty |
| 18 | +2. Get all notes since `last_note_id` <https://developers.hubspot.com/docs/api/crm/notes> |
| 19 | + - Use `after` parameter with value of `last_note_id` in API call |
| 20 | + - Include `associations` for: `companies` and `vendors` |
| 21 | + - Page through multiple pages, increase `limit` for page size |
| 22 | + - Save new `last_note_id` using the `paging.next.after` property from the last API response |
| 23 | +3. For each note in the API response list: |
| 24 | + - If it has no body, skip |
| 25 | + - If it has no author/creator, skip |
| 26 | + - If it has no associations, skip |
| 27 | + - If it has a `company` association: check if `company_type == Transit Agency`; if not, skip |
| 28 | +4. If the note is not being skipped: |
| 29 | + - Get the user's first name associated to `properties.hs_created_by` (the user's ID) |
| 30 | + - Get a company's name from the associated company ID |
| 31 | + - Get a vendor's name from the associated vendor ID |
| 32 | + - Add an item to the output list |
| 33 | +5. Write the output list to a JSON file |
| 34 | + |
| 35 | +## `post.py` |
| 36 | + |
| 37 | +This script is responsible for posting each downloaded note into Slack using the Slack API: |
| 38 | + |
| 39 | +1. Read the output list from the file |
| 40 | +2. For each note in the output list: |
| 41 | + - Process the HTML from the note body into something usable |
| 42 | + - Generate a Slack message using the note attributes <https://api.slack.com/reference/surfaces/formatting#rich-layouts> |
| 43 | + - Post the message to the channel <https://api.slack.com/messaging/sending> |
0 commit comments