In this guide, I'll dive deep into the dynamics of automating your social media posting strategy. Right from content and image generation with ChatGPT and DALLE respectively, to automated storage on a custom Airtable database, to automated post scheduling on Facebook and Instagram with Zapier.
Although I've chosen to store the generated content on Airtable, you could opt for Google Sheets instead, or even a traditional database while you build a UI around it. As long as you understand how to build out the application logic for your preferred platform, you'll be fine.
Packages Needed
- Airtable
- OpenAI API Key (preferably with a text-davinci model bought)
- Zapier (the free plan would work for our application, for more intensive enterprise usage, consider purchasing a paid plan)
- Facebook Page with a Linked Instagram Account.
- Google Drive Account to Host Generates Images from DALLE
Guide
The guide will be divided into four relevant sections:
Setting Up the Airtable Base
Head over to your Airtable Account and Create a New Base.
Create a table and name it whatever you want. My Table here is named IG Posts. For our Workflow, we require that the following fields need be set up: Date, Captions + Hashtags, Type of Image, Image URL, and Timestamp,
For simplicity and to ensure that we do not overstep Zapier's free plan offerings, we'll post five days a month, at regular intervals, starting on the 5th of the month. As such, our last posting date would be the 25th of any month.
Head over to the Scripting Extension. Here's a script to setup the date parameters in Airtable. We've covered from April till December:
let table = base.getTable('Posts Data');
let { records } = await table.selectRecordsAsync();
const startDate = new Date('March 5, 2023');
const endDate = new Date('December 31, 2023');
const increment = 5; // Increment in days
// Loop through each record in the table
for (const record of records) {
const dateField = record.getCellValue('Date Field');
let currentMonth = startDate.getMonth();
// If the date field is empty or null, set it to the next date in the sequence
if (!dateField) {
let currentDate = startDate;
while (currentDate <= endDate) {
// Check if we're still in the same month
if (currentDate.getMonth() === currentMonth) {
// Set the date field for the current record
await table.updateRecordAsync(record, {
'Date Field': currentDate
});
// Increment the date by the specified increment
currentDate.setDate(currentDate.getDate() + increment);
} else {
// If we've reached the end of the month, move to the next month
currentMonth = currentDate.getMonth();
}
}
}
}
Pull Out Content from ChatGPT
5- Now that our Date field is all setup and we've established our posting dates, we must now generate relevant Captions and Hashtags for the post, alongside keywords to feed into DALLE. The simple script below covers that:
let table = base.getTable('Projects');
let trecords = await table.selectRecordsAsync();
let captions = table.getField("Captions");
const len = trecords.records.length;
const apiUrl = "https://api.openai.com/v1/chat/completions";
const options = {
method: 'POST',
headers: {
'Authorization': 'Bearer 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',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [
{ role: "assistant",
content: "Act like a social media assistant and generate a caption for a social media post scheduled on keep it strictly less than 220 characters. Spice it with emoticons"
}
],
}),
};
console.log(options);
const response = await fetch(apiUrl, options);
const jsn = await response.json();
console.log(jsn);
Scheduling your Posts with Zapier
6- Head over to your Zapier account. If you've got a Paid plan, great! If not, a Free Plan would actually work just fine. We'll post to a Facebook Group, as well as an IG page. The timestamp field would be of relevance here to moderate the scheduling.
7- Connect your Zap to the Airtable Base, as well as the relevant table. Adjust the timestamp field to moderate your automation.
8- To connect the zap to your Facebook group, sign-in to your account. Link the appropriate fields.
Conclusion
Automating your social media content strategy sure would save you a great deal of time and allow you to concentrate on more demanding business activities. Our outline here is more than sufficient to take care of your regular Facebook and Instagram updates. However, you can always extend to other social media platforms including LinkedIn or Twitter. As long as you choose to work with Airtable and Zapier, the code basically would remain the same, or you can tweak to your preferrences.
Top comments (0)