Sync new Hubspot notes to Slack #3086
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync new Hubspot notes to Slack | |
on: | |
workflow_dispatch: | |
inputs: | |
page_size: | |
description: Page size for API requests | |
required: false | |
default: 10 | |
type: number | |
max_pages: | |
description: Maximum number of pages to request | |
required: false | |
default: 1 | |
type: number | |
last_note_id: | |
description: The ID of the last note that was processed | |
required: false | |
type: string | |
slack_channel: | |
description: The ID of the Cal-ITP Slack channel to post the message(s) to | |
type: string | |
required: false | |
schedule: | |
# every hour at HH:10 | |
- cron: 35 * * * * | |
jobs: | |
sync-notes-to-slack: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
cache: pip | |
cache-dependency-path: "pyproject.toml" | |
- name: Install tooling | |
run: pip install -e .[hubspot,notes] | |
- name: Get last_note_id from workflow input | |
if: inputs.last_note_id | |
run: echo ${{ inputs.last_note_id }} > last_note_id | |
- name: Get last_note_id from repository variable | |
if: github.event.schedule | |
run: echo ${{ vars.HUBSPOT_LAST_NOTE_ID }} > last_note_id | |
- name: Download newer notes | |
id: download | |
run: | | |
python notes/download.py | |
echo "last_note_id=$(cat last_note_id)" >> $GITHUB_OUTPUT | |
env: | |
HUBSPOT_ACCESS_TOKEN: ${{ secrets.HUBSPOT_NOTES_ACCESS_TOKEN }} | |
HUBSPOT_MAX_PAGES: ${{ inputs.max_pages || vars.HUBSPOT_MAX_PAGES }} | |
HUBSPOT_PAGE_SIZE: ${{ inputs.page_size || vars.HUBSPOT_PAGE_SIZE }} | |
- name: Post a message for each downloaded note | |
run: python notes/post.py | |
env: | |
SLACK_ACCESS_TOKEN: ${{ secrets.SLACK_ACCESS_TOKEN }} | |
SLACK_CHANNEL_ID: ${{ inputs.slack_channel || vars.SLACK_CHANNEL_ID }} | |
SLACK_RATE_LIMIT: ${{ vars.SLACK_RATE_LIMIT }} | |
HUBSPOT_INSTANCE_ID: ${{ secrets.HUBSPOT_INSTANCE_ID }} | |
- uses: actions/github-script@v7 | |
name: Update last_note_id repository variable | |
if: github.event.schedule | |
env: | |
LAST_NOTE_ID: ${{steps.download.outputs.last_note_id}} | |
with: | |
github-token: ${{ secrets.GH_TOKEN_REPO_VARS }} | |
script: | | |
const { LAST_NOTE_ID } = process.env; | |
github.rest.actions.updateRepoVariable({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: "HUBSPOT_LAST_NOTE_ID", | |
value: LAST_NOTE_ID, | |
}); |