This article implements Azure Automation logic for automatically publishing a LinkedIn post and Twitter’s Tweet using the simplified Azure Logic App.
I am a technical writer publishing blogs on various topics for SQLShack. You need to work on various social platforms such as LinkedIn, Twitter, Facebook, and Instagram to share your articles so that it has a widespread and community member can benefit from it. Usually, you need to manually go on each social platform and share your article with a custom text. Manually, it takes some effort, and you might miss posting articles on a social site if you get occupied in other things.
Therefore, I thought of creating an automatic process. Once an article gets published on SQLShack, I enter a record in my Azure SQL Database table. My requirements for automation in this article are as below.
- I insert a new row is into the Azure SQL Database table, which triggers a workflow for the Azure logic app
- This workflow automatically publishes the post on LinkedIn with a hashtag and post URL
- It also submits a Tweet in the Twitter application
In this article, we implement the automation of LinkedIn posts and Tweets using the Azure Logic App.
I would assume that you have access to the Azure portal in this article. You also require an Azure SQL Database for creating tables, stored procedures for providing inputs. You can refer to SQL Azure articles and configure an active instance of the Azure database.
You also require SQL Server Management Studio (SSMS) or Azure Data Studio to connect with Azure SQL and execute queries in it.
Steps for Azure Automation technique for automating LinkedIn Post and Tweet in the Twitter application
In my earlier articles, we discussed the Azure Logic app for the automation of the following tasks.
- Automatically upload email attachments into Azure Storage Account and import them into the Azure database
- Automatic Scale up and down Azure SQL database with Logic Apps
- Analyze twitter sentiments using Azure Logic Apps and store Tweets into Azure SQL Database
For this article, I created the [AutomaticPostonSocialMedia] logical app in the Azure portal. You can navigate to Azure Portal -> Logical apps -> Create a new logical app.
Click on Edit. We will implement the following workflow using the azure logic app for this article.
Let’s look at the individual component of the configured logic app in detail.
Step 1: When an item is created (V2)
In the logic app templates, select the Blank Logic app template.
As we started our requirement that once we add a new row in the Azure SQL database, it should trigger the workflow. Therefore, search for SQL Server connector and click on When an item is created (V2).
Before we proceed, you can create a table in the Azure SQL database with the following script.
CREATE TABLE PublishSQLShackContents
ID int IDENTITY PRIMARY KEY CLUSTERED,
Add details for your Azure database connection such as SQL Server name, SQL database name, credentials.
Click on Create and select server, database and table name in the next window.
By default, it checks every 3 minutes for the new items in the SQL table. You can adjust it per your requirement. Click on Add new parameter and select the Top Count field.
Enter the top count as 1.
Step 2: Execute stored procedure (V2)
Click on Add new Step and select Execute stored procedure (V2) from the SQL Server connector. For this step, I created the stored procedure that retrieves the latest record from the table.
CREATE OR ALTER PROCEDURE RetreiveLinkedInCOntent
SELECT TOP 1 * FROM PublishSQLShackContents ORDER BY id DESC
In the Execute stored procedure (V2) section, select the SP created for extracting the latest record from the SQL table.
Step 3: Initialize Variable
In this step, we define a variable for preparing our LinkedIn post content using the CONCAT function. Search and select variables in the logic app connector. In the corresponding action, we will use the Initialize variable. In the Initialize variable, enter the following details.
- Name: Enter the name as Body
- Type: Select the type of variable. Here, we require a string variable
- Value: In this value, enter the following CONCAT() function. It concatenates strings for content body and hashtag using the dynamic content fields
You can choose the CONCAT() function and select the required fields for preparing the above formula.
In the Initialize Variable, we enter the value as we specified above.
Step4: Add a LinkedIn connector
Until now, we implemented logic to detect any new row in the azure database table and fetching details of a recently added row using a stored procedure.
Now, search for a LinkedIn V2 connector. It has the following listed actions.
- List my companies V2(preview)
- Share a company update 2(preview)
- Share an article 2(preview)
Here, we select the action – Share an article V2 (preview). It asks for your LinkedIn credentials and permissions to access, post articles on your profile.
In the content URL, select the ResultSets Table from the dynamic content. It switches to a For each container as shown below.
Next, click in Share an article V2 (preview) and do the following column mappings.
- Visible to guest: Yes
- Title: ResultSets Topic
- Description: Enter the following expression in the description field
- Subject: ResultSets HashTags
- Text: Variable named Body that defined in step 3
Step 5: Add Twitter connector
As per our requirement, we want to post a LinkedIn post as well as Tweet automatically. In the previous step, we configure a LinkedIn post. Now, look for a Twitter connector and add it to the logic app.
The azure logic app also requires your credentials and permissions for using Twitter and do the tasks such as Get followers, Get home timeline, Get user, Post a tweet, Retweet, search tweets.
Click on Post a tweet, and you get the following configuration window.
In the add new parameter, select Tweet Text from the drop-down list. Now, enter the following expression of the CONCAT() string function. It prepares a concatenated string from the Body variable and URL from the SQL table. You can also configure a variable for storing your tweet content.
Validate LinkedIn post and Tweet
We have completed the Azure Automation using the Azure logic app’s configuration for automatically post a LinkedIn post and Tweet once a new entry comes in the Azure SQL Database table.
Click on Save and Run. The Logic app waits for a new row in the [PublishSQLShackContent] table of [labazuresql] azure database.
Now, insert a row into the [PublishSQLContents] table with the following query. It puts an entry for my existing article already published on SQLShack.
INSERT INTO PublishSQLShackContents (Topic,[URL],[HashTags],dbo.PublishSQLShackContent.ContentBody)
values (' Difference between Unique Indexes and Unique Constraints in SQL Server',
' #sqlserver',' This article gives you an overview of Unique Constraints in SQL and also the Unique SQL Server index. Along the way, we will look at the differences between them.')
Once the logic app detects a new row in the table, it triggers the logic app’s workflow. As shown below, all the steps are completed successfully within a few seconds.
LinkedIn post validation
It’s time for validations. Open your LinkedIn profile, and you can see a recent post in my profile. It is automatically published by the Azure logic app configuration. It also has a corresponding hashtag in the LinkedIn post.
In the LinkedIn notification as well, you get a message that your post was shared successfully.
Twitter’s Tweet validation
Similarly, you can find a new Tweet in my profile published by the logic app workflow.
Azure Logic App workflow allows you to automate things quickly and efficiently. You can use multiple connectors for data integration, implementing business logic. In this article, we use Azure Automation for posting a LinkedIn post and Tweet automatically. Therefore, next time, you do not manually post the same thing on multiple social platforms. You can quickly automate things, and the logic app takes care of task implementation.
Table of contents
- Exploring Azure SQL Database Geo-Restore - September 2, 2022
- Deploy a SQL Server container using Azure Kubernetes Services (AKS) - August 31, 2022
- Deploy Azure SQL Elastic Pools for Azure SQL Database - August 23, 2022