How to Build an AI-Powered Developer Newsletter with Power Platform and ChatGPT3
Published Feb 11 2023 12:00 AM 14.3K Views
Microsoft

Someleze_Diko_2-1675431070493.png

 

The recent developments with AI have presented several opportunities for developers to build intelligent solutions. How can rising developers take positive advantage of this with the help of Power Platform?
 

You are a rising developer working for a specific company or part of developer/student community that constantly works with new trends and technologies. The key ask from your company/community is to compile a weekly newsletter with the latest trends about a specific technology (.NET, Python, React or Power Platform) for developers to stay up to date and make decisions on what new features, if any, should they deep dive on.

 

Here are key learn materials for this solution make sure to complete them:

You decide to build a solution that will do the heavy lifting for by taking advantage of ChatGPT3 and Power Platform.

Solution Preview

Animation showing solution PreviewAnimation showing solution Preview

 

Watch the Step-by-Step Guide on demand.

 

Building the solution

Pre-steps:

  1. Go to the OpenAI website, click on API on the navigation bar and signup/sign in.
  2. Once signed in, click on your profile and then click on View API Keys.
    Someleze_Diko_1-1675421821585.png
  3. On the API page, click on Create new secret to generate the API key and then copy and paste on a notepad we will use it later.
    Someleze_Diko_2-1675421873502.png
  4. Navigate to the Adaptive Card Designer and then click on New Card.
  5. Paste the following JSON code onto the Card Payload Editor.
    {
        "type": "AdaptiveCard",
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "version": "1.4",
        "body": [
            {
                "type": "TextBlock",
                "text": "Power Platform Weekly Newsletter",
                "wrap": true
            },
            {
                "type": "Input.Text",
                "placeholder": "Please enter the search text for the newsletter",
                "isMultiline": true,
                "id": "txtSearch"
            }
        ],
        "actions": [
            {
                "type": "Action.Submit",
                "title": "Submit",
                "id": "btnSubmit",
                "style": "positive"
            }
        ]
    }
    
  6. The above will generate an adaptive card that you will use when building the solution to take the search text that will be sent to ChatGPT3.
  7. Go to the Stripo website, click on Sign up or Login.
  8. Once logged in, you will be met with a dashboard. Click on New Message to generate a new Newsletter from scratch or from a template.
  9. You will then have the option to choose from a variety of templates, choose the best one for you.
  10. You will be presented with a canvas to edit this template, once done with your edits you can click on Export.
  11. On the export pop-up, choose HTML to export your template.
  12. On the next pop-up, choose Show HTML Code. You will see the html code, then click on Copy to Clipboard. We will use this code later.

Let’s start building the actual solution to generate this newsletter!!!

 

The solution:

  1. Sign in onto Power Automate.
  2. Click on Create and choose a Scheduled Cloud Flow.
    Someleze_Diko_0-1675417368400.png

     

  3. Give your flow a Name, choose the Starting Time and the set the Occurrence to 1 Week then choose Monday.
    Someleze_Diko_1-1675417460243.png

     

  4. After the flow is created click New Step and search for Get an @mention token for a tag then choose it. Provide the Team ID and Tag ID. Please not that you have to set tags on teams for the team you are using.
    Someleze_Diko_2-1675417898041.png

     

  5. Then add a new step, search for Post a message in a chat or channel. For Post as choose User, for Post in choose Channel and then specify the Team and Channel ID. On the message box add the dynamic content from the Get an @mention token for a tag action to mention the tag/team in teams.
    Someleze_Diko_3-1675418094029.png

     

  6. Add a new step, search for Post an adaptive card and wait for a response action. For Post as choose Flow Bot, for Post in choose Channel, for message paste the json code you copied from the pre-steps, then specify the Team and Channel ID. This way you flow will wait for a search text before it generates the newsletter.
    Someleze_Diko_4-1675418194796.png

     

  7. Add a new step, search for OpenAI and choose the ChatGPT3 Completes your prompt action. Provide a chosen and meaningful connection name, for API Key type in Bearer then leave a space and paste in the secret you copied on number 3 of the pre-steps and click Accept.
    Someleze_Diko_5-1675418315683.png
  8. Once the connection is established, make sure you have chosen DaVinci as your engine. For prompt, choose the txtSearch dynamic content of the Post an adaptive card and wait for a response action and put max tokens and 1000. This will enable your flow to generate a newsletter from the text coming from teams using ChatGPT3
    Someleze_Diko_6-1675418422506.png

     

  9. Add a new step, search for Send an Email V2 and provide the Recipient and Subject. For the message/email body, add in the Text dynamic content from the ChatGPT3 Completes your prompt action.
    Someleze_Diko_0-1675419255341.png

     

  10. Save your flow and run it but you might need to adjust your trigger for you to see the results right aways! Congrats you’ve built your Power Platform + Teams + ChatGPT3 solution!
    Someleze_Diko_0-1675420142339.gif

     

Advanced steps for a precise newsletter

This part is more of extra stuff that you can do make your newsletter a bit more accurate from ChatGPT3.

  1. First up, let’s update the action in step 8. For the prompt add in the text shown in the image below. This will extract key entities from the search text, example "What's up with PowerApps and Power Automate lately " and the PowerApps and Power Automate entities will be extracted to get accurate results either from official PowerApps or Power Automate twitter accounts or from credible Power Platform developer's tweets.
    Someleze_Diko_2-1675420521672.png
  2. Then add a new step, search for Search Tweets and add that action. For search text, add in the Text dynamic content from ChatGPT3 Completes your prompt action. Click on show advanced options and set the max results to 10. This will search tweets that match the extracted entities from the previous steps, i.e if you were generating a newsletter for Power Platform news it would search all tweets using the #PowerPlatform or tweets from the official Power Platform twitter account.
    Someleze_Diko_4-1675420627375.png

     

  3. Add a new step, search for Filter Array. For the From, add in the Body dynamic content from the Search Tweets action. For the Map, you can map it similar to the following image or to your choosing. We are doing this to reduce the number of tokens from the tweets so that we do not exceed the ChatGPT3 token limit which is 4000.
    Someleze_Diko_5-1675420673816.png

     

  4. Add a new step, search for Compose add in the Outputs dynamic content from the Filter Array action as input.
    Someleze_Diko_6-1675420719510.png

     

  5. Add a new step, search for OpenAI and choose the ChatGPT3 Completes your prompt action. This time for the Prompt you will give it a command similar to the following image or to your choosing and set the max token to 2000. Set the Stop Item – to Tweets and Stop Item – 2 to Newsletter This step will generate the newsletter for you based on the command.
    Someleze_Diko_7-1675420799778.png

     

  6. Add a new step, search for Compose and add in the Text dynamic content from the ChatGPT3 Completes your prompt 2 action as your Input. Rename your action from Compose to Get ChatGPT Outputs.

    Someleze_Diko_0-1675770860841.png

     

  7. Add a new step, search for Compose and add in the following expression as your Input. This will convert the output from ChatGPT to a string and we want to extract only the text. Rename this action to Convert Outputs to String.

    string(split(outputs('Get_ChatGPT_Output'),'\n'))
    Someleze_Diko_1-1675770896822.png
  8. Add a new step, search for Compose and add in the following expression as your Input. This will allow you to remove the HTML New Line (“\n”) and replace it with HTML Line Breaks tag (<br>) so that you can have a proper format for your newsletter. Rename this action to Replace New Line with Line Breaks.
    replace(outputs('Convert_Output_to_String'),'\n','<br>')

    Someleze_Diko_3-1675771131227.png
  9. Add a new step, search for Compose and add in the following expression as your Input. This will allow you to remove unwanted characters from the text, so that the newsletter is properly formatted. Rename this action to Remove Unwanted Characters.
    substring(outputs('Replace_new_line_with_line_breaks'),2,sub(length(outputs('Replace_new_line_with_line_breaks')),3))​

    Someleze_Diko_4-1675771226958.png
  10. Add a new step, search for Send an Email V2 and provide the Recipient and Subject. For the message/email body, paste in the HTML code copied from step 12 on the pre-steps and add in the Outputs dynamic content from the Remove Unwanted Characters action (the previous one). Make sure you add the dynamic content in the right place for a nice looking, well formatted Newsletter.
    Someleze_Diko_0-1675771548076.png

     

Congratulations! You have completed a Power Platform + Teams + ChatGPT3 solution! Would love to see how you can enhance this solution or a new solution that you have built using ChatGPT3 and Power Platform. Share in the comments.
 

Someleze_Diko_0-1675421311859.gif

 

10 Comments
Version history
Last update:
‎Apr 05 2023 05:45 AM
Updated by: