I’ve got a scenario with a ChatGPT module. The response from ChatGPT is a list with some text that’s bold, but instead of bold text it’s putting asterisks on either side of the text (see screenshot).
I’m mapping this response into a Google Doc and rather than getting bold text in my Google Doc it’s showing up with the asterisks and it looks messy. How do I preserve the bold text so that when ChatGPT replies with bold text, it shows up in my Google Doc as bold text?
Can I do this with a text parser in Make and a script in my Google doc?
After the document is created from template you can try and use the get contents from document module to retrieve the html code. Then run another create a document module.
Hi @LaurenK
You can use download a doc module to get the html code of template doc and then replace the test_varible with the Markdown converted html code.
Workflow:
Set variable to convert the data to string:
Create a doc:
In my case I have added “[add]” variable to add new content there, so i am replacing the html code of this part .In your case it will be “test_variable”.
First, you need to create a script in Google Scripts. The instructions and the code to do this are below. Deploy the script as a web app to get the URL.
Then in your Make.com scenario it’ll go like this (also see picture below):
All of your ChatGPT modules → Create Google Doc → HTTP module with the web app URL & the docId passed through as JSON (see screenshot below)
To create a Google Apps Script that will search for text between double asterisks and make it bold in a Google Doc, you can follow these steps. I’ll include an example script that you can adapt.
In the script editor, replace the default content with the following code:
javascript
Copy code
function makeTextBold(docId) {
// Open the document by ID
var doc = DocumentApp.openById(docId);
var body = doc.getBody();
// Regular expression to find text between double asterisks
var pattern = /\*\*(.*?)\*\*/g;
var text = body.getText();
var match;
while (match = pattern.exec(text)) {
var start = match.index;
var end = start + match[0].length;
var boldText = match[1];
// Replace the asterisks and apply bold formatting to the text inside them
var boldTextLength = boldText.length;
body.replaceText(escapeRegExp(match[0]), boldText);
// Find the newly replaced text and apply bold styling
var searchResult = body.findText(escapeRegExp(boldText));
while (searchResult) {
var thisElement = searchResult.getElement();
var thisElementText = thisElement.asText();
var startPos = searchResult.getStartOffset();
var endPos = searchResult.getEndOffsetInclusive();
thisElementText.setBold(startPos, endPos, true);
searchResult = body.findText(escapeRegExp(boldText), searchResult);
}
}
// Save the changes
doc.saveAndClose();
}
// Helper function to escape special characters for regular expression
function escapeRegExp(string) {
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\DISCOURSE_PLACEHOLDER_1');
}
Deploy as Web App:
Go to the menu: Deploy > New deployment.
Click on Select type and choose Web app.
Fill in the description.
Under Execute as, select Me.
Under Who has access, choose Anyone.
Click Deploy. You might need to authorize the script by logging into your Google account and allowing permissions.
Get the Web App URL:
Once deployed, copy the URL provided. This is the endpoint you will call from make.com.
In your make.com scenario, use an HTTP module to make a POST request to the Web App URL.
Pass the Google Doc ID as a parameter or within the request body, depending on how you set up the HTTP module.
This script and deployment method will allow your Google Script to be triggered via HTTP requests from make.com, applying bold formatting to the text that’s between double asterisks in the specified Google Doc. Adjust the script according to the specifics of how you send data from make.com if necessary.