Skip to content

feat(content): send pages to the HubSpot blog as draft posts - #2271

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/hubspot-blog-posts
Nov 10, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/hubspot-blog-posts

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #2265 (HubSpot connection). Merge after #2265. This PR's own commits are 1d09202 and 7fb1316, plus a merge of main.

HubSpot, part 4 of #2140: Send to CMS can put a page on the brand's HubSpot blog as a draft post. The owner asked for blog posts first; site and landing pages come in a later PR.

What a person sees:

  • The HubSpot card (Settings › Integrations › CRM):
    • With Send pages to HubSpot as drafts on, admins and managers get Blog posts go to: a picker of the HubSpot account's blogs, with Save.
    • Members see "Send to CMS writes draft posts to {blog}."
    • If HubSpot didn't give Ansvisor its content scope (a sign-in made without it), the card says "HubSpot didn't give Ansvisor access to its blogs…", with Connect again.
  • Send to CMS, in the editor and the Library's bulk send:
    • a HubSpot card, "A draft blog post on {blog}". It shows "Not ready" while no blog is picked, and doesn't show at all while sending pages isn't allowed.
    • The dialog's description, success toast ("Sent to HubSpot as a draft blog post", or "Draft blog post updated in HubSpot") and "last sent" lines.
    • Every refusal has its own words: not set up, not connected, not on the plan, sign-in refused, sending not allowed, no blog picked, already on its way.
  • The Library:
    • shows "In HubSpot as a draft blog post since …";
    • marks a page Published once its post is live in HubSpot, read when the Library opens and once a day, as for Wix.

How it works:

  • Migration 00522 (supabase/schema.sql rebuilt). 00521 stays reserved for contact marking.
    • content_draft_deliveries.target accepts hubspot. target_collection holds the blog's id and external_id the post's.
    • reserve_content_deliveries is re-created as in 00372, with HubSpot among the CMSs a page can't be sent to twice at once. It is service-role only.
  • lib/cms/hubspot-blog.js, through the HubSpot sign-in's Composio proxy:
    • the blogs: GET /cms/v3/blog-settings/settings;
    • a post: POST /cms/v3/blogs/posts, and PATCH /cms/v3/blogs/posts/{id}/draft for later sends;
    • reading a post back, and whether it's live.
    • The post gets the page's title, slug, meta title, meta description and featured image. The JSON-LD goes in the post's head (headHtml) and the body keeps its images.
  • lib/cms/hubspot-delivery.js:
    • A page's next send updates its post's draft. A post deleted in HubSpot gets a new one.
    • A refused sign-in is marked for reconnecting. A missing content scope stops a batch, with its own message. Nothing is published.
  • content-delivery.js NATIVE.hubspot: a page goes only when all of these hold: HubSpot set up, connected, the brand's plan has crm_integrations, consent to send pages, and a blog picked.
  • Routes:
    • GET /api/hubspot/brands/:brandId/blogs and PUT /api/hubspot/brands/:brandId/blog: admins and managers on the plan, who reach the sign-in's brands, with consent to send pages;
    • POST /api/content-drafts/hubspot-status: any member, a brand at most every two minutes;
    • all are on the demo guard; the status route is in write-roles.test.js's open list;
    • a daily sweep runs in runDailyTracking.
  • Web:
    • cms-target.tsx, send-to-cms-dialog.tsx, the Library's bulk dialog, table and status refresh, cms-send-client.ts, cms-names.ts, cms-status.ts;
    • hubspot-client.ts gains the blog calls;
    • all strings are in web/messages/en.json.
  • Not touched: publish, take down, and Chat's push_cms_draft stay Webflow, WordPress and Wix's (and Framer's for drafts).
  • Help: content/send-to-cms, content/connect-a-cms and settings/hubspot describe HubSpot. The two content articles are approved, so approved-articles.json was regenerated.

Merging with #2266: this branch starts from #2265. A few files also change in #2266: the HubSpot card, hubspot-client.ts, lib/hubspot/connection.js, routes/hubspot.js, server.js, en.json and the demo guard. I placed this branch's edits away from #2266's in those files, so both should merge without conflicts.

Live test with Gökhan:

  • The HubSpot answers in the tests (lib/hubspot/__fixtures__/blog-*.json) follow HubSpot's API reference.
  • The blog list endpoint (/cms/v3/blog-settings/settings) and the post states (PUBLISHED, PUBLISHED_OR_SCHEDULED) need checking on a test portal. HubSpot blogs need Content Hub.

Related issue

Part of #2140

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/cms/hubspot-blog.test.js src/lib/content-delivery-hubspot.test.js src/routes/hubspot.test.js src/routes/write-roles.test.js src/middleware/demo-brand.test.js
  2. cd web && yarn vitest run src/components/settings/hubspot-card.test.tsx src/components/content/send-to-cms-dialog.test.tsx src/lib/hubspot-client.test.ts src/lib/help
  3. Apply 00522_cms_hubspot_blog.sql on a dev database.
  4. Live, with HubSpot connected for a Growth brand whose HubSpot has a blog (Content Hub):
    • On the HubSpot card, turn on Send pages to HubSpot as drafts, pick the blog under Blog posts go to and click Save.
    • In the editor, open Send to CMS. HubSpot is offered; send. A draft post appears on that blog in HubSpot, with its slug, meta and featured image, and the JSON-LD in its head.
    • Send the same page again: the same post's draft is updated.
    • Publish the post in HubSpot, then open the Library. The page reads Published at the post's address.
    • With a HubSpot sign-in that lacks the content scope, the card asks to connect again.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — 0 errors; 9 warnings, all in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — see help/README.md

Checks run (on 1d09202; 7fb1316 only reorders a test's mocks, and that test was run again on it):

  • server npm run format:check, npm run lint: pass.
  • server npm test: 452 files, 6213 passed, 4 skipped.
  • web yarn format:check, yarn lint (0 errors), yarn typecheck: pass.
  • web yarn test: 1,064 files, 11,660 passed, 1 skipped. hubspot-card.test.tsx was run again on 7fb1316: 16 passed.
  • web yarn build (CI's placeholder env): pass.
  • bash supabase/build-schema.sh: schema.sql is up to date in this commit.

After merging main (the Slack PRs, through #2265's branch): schema.sql was rebuilt with 00522, the HubSpot, Send to CMS and Help tests pass again, and the branch merges cleanly into current main.


Generated by Claude Code

HubSpot, part 4 of ansvisor#2140 (stacked on ansvisor#2265): Send to CMS can put a page
on the brand's HubSpot blog as a draft post, blog posts first as the owner
asked (site and landing pages come after).

- 00522: content_draft_deliveries.target takes 'hubspot' (the blog's id in
  target_collection, the post's in external_id), and reserve_content_deliveries
  keeps a page from going to HubSpot twice at once. 00521 stays kept for
  marking contacts.
- On the HubSpot card, with "Send pages to HubSpot as drafts" allowed:
  "Blog posts go to", the HubSpot account's blogs (GET/PUT
  /api/hubspot/brands/:brandId/blogs and /blog). Without HubSpot's content
  scope it asks to connect HubSpot again.
- The target (NATIVE.hubspot): only with HubSpot set up, connected, the
  plan's crm_integrations, consent to send pages and a blog picked; each
  refusal named. A post's title, slug, meta title and description and
  featured image go as the post's own, the JSON-LD in its head. A page's
  next send updates its post's draft; one deleted in HubSpot gets a new one.
  Nothing is published.
- Published there since: read when the Library opens (/content-drafts/
  hubspot-status) and once a day, as Wix's are.
- Send to CMS, the bulk send and the Library know HubSpot; publish and take
  down stay Webflow, WordPress and Wix's.
- Help: content/send-to-cms, content/connect-a-cms and settings/hubspot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Brings in upstream/main through ansvisor#2265's branch (the Slack PRs).
schema.sql is rebuilt with 00510, 00515 and 00522.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 10, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants