Google Docs to Oktopost Draft Agent Setup Guide
Set up an automated Custom Agent in Oktopost that converts highlighted text from Google Docs into draft social posts on your editorial calendar using a Google Docs sidebar.
Prerequisites
- Access to Google Docs with Apps Script
- Permission to create and activate Custom Agents in Oktopost
Step 1: Create and Configure Your Agent in Oktopost
- In Oktopost, open Agent Builder and click Create Agent
- Add a Webhook node as your trigger and configure the settings panel on the right:
- Vendor: Select Generic
- Label: Enter Google Docs Draft Trigger
- Copy the Webhook URL and Secret key values to a temporary text document
- Paste the following JSON block into the Sample Payload field inside the Webhook panel:
{
"title": "Sample Marketing Document",
"content": "Highlighting key product updates and user interface improvements.",
"source": "Google Docs Sidebar"
}
- Add an AI Action node and connect it to your Webhook node
- Set the Permissions dropdown to Read and write
- In the Instructions box of the AI Action, paste the following text:
You are an AI assistant that converts incoming text from a Google Doc into an Oktopost draft social post.
Use the provided text content variable from the webhook.
INSTRUCTIONS:
1. Extract the main points or key takeaways from the provided text content.
2. Write a clear, engaging social media post tailored for LinkedIn.
3. Include 1-2 relevant hashtags.
4. Schedule the draft post directly onto the Oktopost editorial calendar for today.
5. Assign the post to your preferred campaign (for example, "Amy K LinkedIn Drafts").
- Use the dynamic Search variables menu (triggered when clicking into the instructions) to map the content field directly from your Webhook node
- Click Activate in the top-right corner to turn your agent on
Step 2: Install the Sidebar in Google Docs
- Open the Google Doc where you create social media copy
- Go to the top menu and select Extensions > Apps Script
- In the left panel under Files, open Code.gs. Delete any existing text and paste the following script:
function onOpen() {
DocumentApp.getUi()
.createMenu('Oktopost')
.addItem('Open Sidebar', 'showSidebar')
.addToUi();
}
function showSidebar() {
const html = HtmlService.createHtmlOutputFromFile('Sidebar')
.setTitle('Oktopost Agent');
DocumentApp.getUi().showSidebar(html);
}
function processSelection() {
const doc = DocumentApp.getActiveDocument();
const selection = doc.getSelection();
if (!selection) {
throw new Error('Please highlight some text first.');
}
let selectedText = '';
const elements = selection.getRangeElements();
elements.forEach(element => {
if (element.getElement().asText()) {
const textElement = element.getElement().asText();
if (element.isPartial()) {
selectedText += textElement.getText().substring(element.getStartOffset(), element.getEndOffsetInclusive() + 1);
} else {
selectedText += textElement.getText();
}
selectedText += '\n';
}
});
// PASTE YOUR OKTOPOST DETAILS HERE
const webhookUrl = 'YOUR_OKTOPOST_WEBHOOK_URL';
const secretKey = 'YOUR_OKTOPOST_SECRET_KEY';
const payload = {
title: doc.getName(),
content: selectedText.trim(),
source: 'Google Docs Sidebar'
};
const options = {
method: 'post',
contentType: 'application/json',
headers: {
'x-webhook-secret': secretKey,
'Authorization': secretKey
},
payload: JSON.stringify(payload)
};
UrlFetchApp.fetch(webhookUrl, options);
return 'Success! Draft sent to Oktopost.';
}
- Replace
YOUR_OKTOPOST_WEBHOOK_URLandYOUR_OKTOPOST_SECRET_KEYinside Code.gs with the exact keys saved from Step 1 - In the left panel, click + (Add a file) > HTML. Rename the file to Sidebar (capital S)
- Clear any existing code in Sidebar.html and paste the following block:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
body { font-family: Arial, sans-serif; padding: 15px; }
button {
background-color: #0052CC;
color: white;
border: none;
padding: 10px 15px;
font-size: 14px;
border-radius: 4px;
cursor: pointer;
width: 100%;
margin-top: 10px;
}
button:hover { background-color: #003d99; }
#status { margin-top: 15px; font-size: 13px; color: #333; }
.error { color: #d93025; }
.success { color: #188038; }
</style>
</head>
<body>
<h3>Create a Draft</h3>
<p>Highlight text in your document, then click below to trigger the AI Agent.</p>
<button id="sendBtn" onclick="sendToOktopost()">Send Selected Text</button>
<div id="status"></div>
<script>
function sendToOktopost() {
const btn = document.getElementById('sendBtn');
const status = document.getElementById('status');
btn.disabled = true;
btn.innerText = 'Sending...';
status.innerText = '';
status.className = '';
google.script.run
.withSuccessHandler(function(msg) {
status.innerText = msg;
status.className = 'success';
resetButton(btn);
})
.withFailureHandler(function(err) {
status.innerText = 'Error: ' + err.message;
status.className = 'error';
resetButton(btn);
})
.processSelection();
}
function resetButton(btn) {
btn.disabled = false;
btn.innerText = 'Send Selected Text';
}
</script>
</body>
</html>
- Click Save (floppy disk icon), select onOpen from the top function dropdown, click Run, and approve the security permissions when prompted
Step 3: Generate Draft Posts
- Refresh your Google Doc
- Select Oktopost > Open Sidebar from the top Google Docs menu
- Highlight any passage or draft sentence inside your document
- Click Send Selected Text in the right sidebar panel
- Open your Oktopost Calendar, select your campaign from the filter menu, and view your AI-generated draft post on today's calendar view