Google document place text under heading

Hello fellow forum members,

I’m in need of some assistance with a unique automation task that I’ve been working on in Google Docs, facilitated by ChatGPT. The goal is to insert bedtime stories under specific headings in a document that are created for children, themed around sleep and the moon, as well as wake-up stories centered around the sun.

Here’s the challenge:

I have separate ChatGPT modules that generate stories—one set for bedtime and another for waking up. Each story needs to be placed under its respective heading within my Google Doc (“Bedtime Stories” and “Wake-Up Stories”).

What I have tried:

  1. Utilizing the “Google Docs - Get Content of a Document” module to extract the document’s content. My challenge has been pinpointing the exact positions (indexes) of the headings.
  2. Employing “Text Parser” modules with regex patterns to identify these headings. Despite setting ‘Global match’ and ‘Multiline’ to ‘Yes’, I’m not getting any matches.
  3. Exploring the possibility of using “Get elements from HTML” after exporting the document to HTML, but I’m unsure if this is the right direction since my document is not originally in HTML.

Details to consider:

  • The document includes a table of contents with headings like “Bedtime Stories” and “Wake-Up Stories”, each followed by a series of underscores.
  • I intend to parse these headings to find their indexes, so I can use the “Google Docs - Insert Text” module for placing the generated stories accurately beneath them.

Attached are screenshots showing the modules’ configurations and the document’s structure from the API perspective.

I would greatly appreciate any tips on how to detect the headings’ positions effectively so that the stories can be inserted correctly. Has anyone encountered a similar issue or can offer insights into what might be going amiss with my setup?

Your advice will be a bedtime boon!

Thank you so much!