In today’s digital landscape, creating a blog is just the first step in establishing an online presence. To attract readers and build a following, bloggers need to promote their content effectively.
In this blog post, we’ll explore the topic of automated blog promotion and how to use ChatGPT, Twitter API, and AWS to create a blog promotion toolkit that can help bloggers promote their content more efficiently.
The toolkit is designed to automate the promotion process using cutting-edge technologies, making it easier for bloggers to reach their target audience.
By following the steps outlined in this post, you’ll be able to create your own automated blog promotion toolkit and take your blog promotion efforts to the next level. Let’s dive in and see how ChatGPT, Twitter API, and AWS can help you promote your blog like a pro!
Creating high-quality content for a blog is a challenging task, but promoting that content to reach a wider audience can be even more difficult.
Social media platforms like Twitter offer a powerful way to share blog posts and engage with readers, but manually managing a Twitter account and replying to tweets can be time-consuming and repetitive. '
Furthermore, engaging with Twitter users in a way that is polite and respectful can be challenging, particularly when trying to reach a large number of users. These challenges can make it difficult for bloggers to effectively promote their content on Twitter and reach new readers.
In the next section, we will explore how our blog promotion toolkit can help address these challenges and enable bloggers to reach their promotion goals.
Our blog promotion tool aims to simplify the process of promoting blog content on Twitter by automating the process of finding relevant tweets and engaging with Twitter users. The tool takes a list of blog posts, each with its own set of hashtags and metadata.
These hashtags and metadata are configured manually by the author of the blog (using the same ChatGPT usually 😀) and extracted directly from the HTML.
Once the hashtags have been extracted, the toolkit passes them to the Twitter SearchTweets API, which returns a list of relevant tweets from oldest to newest. The toolkit then checks each tweet for various requirements, such as politeness and the author’s audience size.
If a tweet qualifies, the toolkit feeds the tweet URL and blog post URL to the OpenAI API, which generates a relevant reply using the ChatGPT language model. Finally, the toolkit sends the generated reply using the Twitter Manage Tweets API.
We can visualize this flow as a pipeline with the following key components:
By automating the process of finding relevant tweets and generating polite and engaging responses, our blog promotion toolkit can help bloggers save time and effort in promoting their content on Twitter.
Additionally, the ability to extend the toolkit with new promotion tools in the future can provide even more ways to engage with readers and promote blog content.
Our blog promotion toolkit is built using a variety of tools and libraries, including:
GitHub repo: https://github.com/sr-shifu/blog-promo-toolkit
As mentioned earlier, I will use AWS App Composer UI to build my SAM template. I will not go deep into the details (you can find more information about how to work with it in one of my previous posts) — I will just leave my final diagram here:
Infrastructure is pretty simple:
RepliedTweets table. It will be used to store information about tweets that have been already replied — it would be used by both the SearchTweets and TweetFilter components. It will use userId as a partitioning key and tweetId as a range (sort) key.
There are also 2 additional attributes that are worth mentioning:
Initialize Tweepy client:
client = tweepy.Client(
bearer_token=bearer_token,
consumer_key = consumer_key,
consumer_secret = consumer_secret,
access_token = access_token,
access_token_secret = access_token_secret,
wait_on_rate_limit = True
)
With wait_on_rate_limit = True
, the client will swallow all throttling exceptions and wait for the API to cool down.
Generate reply using openAI:
def generate_tweet_reply_message(tweet_url, post_url, lang = 'en'):
prompt = f"Reply to tweet {tweet_url}. Reply must include link to article {post_url} and engage to follow @TheSameTech{' using ' + lang + ' language' if lang != 'en' else ''}. Don't exceed {str(MAX_TWITTER_MESSAGE_LENGTH)} chars"
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=300,
n=1,
stop=None,
temperature=0.7,
)
author_id = re.search(r"twitter\.com/([^/]+)/status", tweet_url).group(1)
# this is one of the weird stuff I noticed - sometimes ChatGPT tags author using their ID, and not account name
return completions.choices[0].text.replace("\n\n", "").replace(f" @{author_id}", "")
Parameters:
engine
: This parameter specifies the ID of the OpenAI language model to use for generating text. In this example, the text-DaVinci-003 model (ChatGPT-3) is used, which is one of OpenAI's most advanced models.
prompt
: This parameter specifies the text prompt to use as input to the language model. In the blog promotion toolkit, the prompt will be the relevant tweet that the ChatGPT algorithm will be generating a response to.
max_tokens
: This parameter specifies the maximum number of tokens (words or punctuation marks) that the language model should generate in its response.
n
: This parameter specifies the number of responses to generate. In this case, only one response will be generated.
stop
: This parameter specifies a sequence of tokens that should be used as a stopping point for the language model's response. In this case, no stopping sequence is specified.
temperature
: This parameter controls the randomness of the language model's responses. A higher temperature value will produce more creative and varied responses, while a lower temperature value will produce more predictable and conservative responses. In this example, a temperature of 0.7 is used, which should produce responses that are creative but not too unpredictable.
UPDATE: OpenAI released a new gpt-3.5-turbo language model a few days after I wrote this post (Mar 7, 2023). It's priced at $0.002 per 1K tokens, which is 10x cheaper than the existing GPT-3.5 models.
Search tweets:
twitter_metadata = extract_twitter_metadata(post_url, tagsSelector='.post-tags')
keywords, hash_tags, description, *rest = twitter_metadata
combos = list(combinations(hash_tags, 2))
for combo in(combos):
hash_tags_string = " ".join(combo)
latest_tweet_id = get_latest_activity(hash_tags_string)
if latest_tweet_id is None and search_days_ago is not None:
start_time=(datetime.datetime.now() - datetime.timedelta(days=search_days_ago)).strftime("%Y-%m-%dT%H:%M:%SZ")
tweets = search_recent_tweets_with_pagination(query=hash_tags_string, max_results = 100, start_time=start_time, latest_tweet_id=latest_tweet_id, tweet_fields=['id', 'author_id', 'created_at', 'in_reply_to_user_id', 'lang'])
# do other stuff (filtering, generating reply, promoting)
After Twitter metadata is extracted from HTML, I use hashtags as search criteria to find relevant tweets. Usually, every blog post has about 4–5 tags associated with it.
If I pass down all of them together, most likely Twitter API will return nothing — that’s why I combine them by pairs and use every pair as a search key (so every blog post will generate from 6 to 10 search requests in general).
With SAM, you don’t need to do a lot. Only execute 3 commands, and you are good to go. If you want to run the local version of DynamoDB, please follow the README instructions in my GitHub repo.
sam build
sam local start-lambda
aws lambda invoke --function-name "EngageTweets" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt
It’s the same simple using a Python executable:
cd src/engage-tweets-lambda
pip install -r requirements.txt
source env/bin/activate
TABLE_NAME=PromotedTweets python engage_tweets.py
Just make sure you have all tokens stored in your local .env
file.
One command you need to know:
sam deploy
These limitations highlight the challenges involved in building and maintaining a blog promotion toolkit that relies on external APIs and platforms. Despite these limitations, I believe that our toolkit can still be effective in promoting our content and engaging with our audience.
By staying informed and adapting to changes as they arise, we can continue to use these tools to achieve our goals.
In conclusion, our blog promotion toolkit is designed to help content creators reach new audiences by engaging with relevant Twitter users.
By leveraging the power of AI language models and Twitter’s API, we are able to generate personalized replies to tweets that mention our blog post’s relevant content in the context of the target tweet message.
However, it’s important to note that there are limitations to this approach, including Twitter API rate limits and monthly search limits, as well as the cost of using OpenAI’s API for language processing.
Overall, I believe that this toolkit can be a valuable asset for bloggers and content creators looking to promote their work on social media. I look forward to continuing to refine and improve this toolkit, and we welcome any feedback or suggestions from the community.
Thank you for considering my toolkit, and I hope it can help you achieve your content promotion goals!
Originally published at https://thesametech.com on March 3, 2023.