Operator sees the issue
2 am does not make sense we need to send last 48 hours of leads and logic app flows

For some reaon there are 2 emails.
Report update now > #
old code #
$startDate = (Get-Date).Date # Start from the beginning of today
$endDate = $startDate.AddDays(1) # End at the beginning of tomorrow
new code
$startDate = (Get-Date).Date.AddDays(-1) # Start from the beginning of today
$endDate = $startDate.AddDays(1) # End at the beginning of tomorrow
Run and check it >
this is problematic

reference > fix

Looks like still failing

output >
no success run is an issue

implementer needs to fix it properly
there ae success why dont i see it

it is there but did not see 10 success why ?

gpt failed but it is there


gpt calls have issue from time to time > https://portal.azure.com/#view/Microsoft_Azure_EMA/LogicAppsMonitorBlade/runid/%2Fsubscriptions%2Fad744a08-2411-4d78-b417-1f1c83f4f741%2FresourceGroups%2FContractorMarketing%2Fproviders%2FMicrosoft.Logic%2Fworkflows%2Fcontractormarketing-gpt-coverletter%2Fruns%2F08584858463217535730491258056CU16
there is a double trigger for some reason

To select leads created between the start of tomorrow and the start of yesterday, you'll need to calculate the start of tomorrow and the start of yesterday. Here is the SQL query that achieves this:
SELECT *
FROM leads
WHERE createdate >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0)
AND createdate < DATEADD(day, DATEDIFF(day, 0, GETDATE()) + 2, 0);
Explanation:
-
DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0)calculates the start of yesterday. -
DATEADD(day, DATEDIFF(day, 0, GETDATE()) + 2, 0)calculates the start of the day after tomorrow. -
The query then selects all leads created between the start of yesterday and the start of the day after tomorrow.
This will give you the leads created in the 48-hour period starting at the beginning of yesterday and ending at the beginning of the day after tomorrow.
implementer role updates it

there is some data there

fix the html structure
To update the Logic App syntax for the body to send a more structured email in a table format, you can use HTML to create the table. Below is the updated version of the Logic App definition for the "Send_an_email_(V2)" action:
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Attachments": [
{
"ContentBytes": "@{base64(binary(body('Parse_JSON_sql')?['ResultSets']))}",
"Name": "leads.json"
}
],
"Bcc": "[email protected]",
"Body": "
Daily Report
| Processed Items | @{variables('mycounter')} |
|---|---|
| Recruiters | @{variables('recruiters')} |
| Logic App Runs | @{body('GetLogsForLogicApp')} |
Logic App: contractormarketing-replygmail-realtime",
"Cc": "[email protected]",
"Importance": "Normal",
"Subject": "Daily Report: Lead Generation and Logic App Runs",
"To": "[email protected]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {
"Scope_Logic_app_Runs": [
"Succeeded"
]
},
"type": "ApiConnection"
}
Key Changes:
-
HTML Table: The email body now includes an HTML table to present the data in a structured format.
-
Styling: The table has a border and collapses borders for better readability.
-
Content Placement: Each piece of data (processed items, recruiters, and logic app runs) is placed in its own table row.
This structure helps in making the email content more readable and professional.
too ugly

one liner to paste

Old Email
New Email
Fix the gpt now that would help as well
Too many errors

{
"error": {
"message": "This model's maximum context length is 16385 tokens. However, your messages resulted in 30408 tokens. Please reduce the length of the messages.",
"type": "invalid_request_error",
"param": "messages",
"code": "context_length_exceeded"
}
}
using the screenshtos is also important

The images you've uploaded show a setup for making an HTTP call to the OpenAI API using what appears to be Microsoft Power Automate. The error you're encountering is due to the maximum context length being exceeded.
Here are some steps you can take to resolve the issue:
-
Check the size of the
messagesvariable: Ensure that themessagesvariable does not exceed the token limit. Thegpt-3.5-turbomodel has a context length of 4096 tokens, including the prompt and the response. -
Split your messages: If the
messagesvariable contains a long conversation, consider splitting it into smaller parts and making multiple API calls. -
Summarize or truncate messages: Summarize longer messages or truncate the conversation history to stay within the token limit.
-
Use a different model: If the token limit is frequently an issue, consider using a model with a higher context length if available.
Example Adjustments
Here’s how you might modify your setup to check and manage the length of your messages:
1. Adjusting the Body Initialization
- Ensure that you’re only sending necessary parts of the conversation.
{
"max_tokens": @{variables('maxtokens')},
"model": @{variables('model')},
"temperature": 0.7,
"messages": @{variables('messages')}
}
2. Truncating Messages (Pseudocode)
- Before sending the API request, truncate or summarize the messages.
if (messages.length > token_limit) {
truncate_messages(messages, token_limit);
}
3. Power Automate Example
Below is an example approach you could take in Power Automate to handle long messages:
-
Initialize a Variable for Truncated Messages
-
Create a new variable to store the truncated messages.
Initialize Variable
Name: truncatedMessages
Type: String
Value: empty
-
Add a Condition to Truncate Messages
-
Use a condition to check the length of the
messagesvariable and truncate if necessary.
Condition: length(variables('messages')) > token_limit
If true: Set variable truncatedMessages to truncate(variables('messages'), token_limit)
Else: Set variable truncatedMessages to variables('messages')
-
Use the Truncated Messages in the HTTP Call
-
Update the HTTP call to use
truncatedMessages.
{
"max_tokens": @{variables('maxtokens')},
"model": @{variables('model')},
"temperature": 0.7,
"messages": @{variables('truncatedMessages')}
}
Summary
By managing the size of the messages variable and ensuring it stays within the token limit, you can avoid the context length error. If you need further assistance, please provide details on the length and structure of your messages variable.
As of my last update in May 2023, the OpenAI model with the largest context length is gpt-4-turbo-32k. This model supports a context length of up to 32,768 tokens, which is significantly larger than the 4096 tokens limit of gpt-3.5-turbo.
Here’s how you can update your setup to use gpt-4-turbo-32k for handling larger input contexts:
Updating the Model in Power Automate
-
Initialize Variable for Model
-
Change the
modelvariable value togpt-4-turbo-32k.
Initialize Variable
Name: model
Type: String
Value: gpt-4-turbo-32k
-
Ensure Other Settings are Compatible
-
Ensure the rest of your setup is compatible with the new model, particularly the token limit in the
max_tokensfield.
Example Adjustments
Here's an example of how you might set up the variables and HTTP call in Power Automate:
1. Initialize Variables
- Adjust the
modelandmax_tokensvariables to align with the capabilities ofgpt-4-turbo-32k.
Initialize Variable
Name: model
Type: String
Value: gpt-4-turbo-32k
Initialize Variable
Name: maxtokens
Type: Integer
Value: 32768
2. Adjust Body Initialization
- Use these variables in your HTTP request body.
{
"max_tokens": @{variables('maxtokens')},
"model": @{variables('model')},
"temperature": 0.7,
"messages": @{variables('messages')}
}
3. Check Message Length (Optional)
- If you still need to manage message lengths, ensure the
messagesvariable is appropriately truncated or summarized.
Example HTTP Call Setup
Here’s a full example of how you might configure the HTTP request in Power Automate:
- HTTP OpenAI Call Configuration
Method: POST
URI: https://api.openai.com/v1/completions
Headers:
Authorization: Bearer YOUR_API_KEY
Content-type: application/json
Body:
{
"max_tokens": @{variables('maxtokens')},
"model": @{variables('model')},
"temperature": 0.7,
"messages": @{variables('messages')}
}
Handling Token Limits in Practice
If you’re dealing with extremely long input texts, you may still need to implement logic to summarize or split input data. Here’s a brief outline of how you can approach this:
-
Summarize Long Messages: Implement a summarization step before sending data to the model.
-
Split Input into Multiple Calls: If summarization is not feasible, consider breaking the input into smaller chunks and making multiple API calls.
Summary
Switching to gpt-4-turbo-32k will allow you to handle much larger contexts, up to 32,768 tokens. This should help mitigate issues with exceeding the token limit. However, it’s still good practice to manage and optimize your input data to ensure efficient use of the API.



4 worked

running one

Also another error >
{
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
**Fix it **

at least it is a stopper before reaching the openai
In Azure Logic Apps, you can use the "Parse JSON" action to verify and work with JSON data within your workflow. Here's a step-by-step guide on how to set this up:
Step-by-Step Guide to Verify JSON String in Azure Logic App
-
Create a Logic App:
-
Go to the Azure portal and create a new Logic App.
-
Add a Trigger:
-
Add a trigger to start the workflow. For example, you can use the "When a HTTP request is received" trigger to receive the JSON string via an HTTP request.
-
Add a "Parse JSON" Action:
-
After the trigger, add the "Parse JSON" action.
-
In the "Content" field of the "Parse JSON" action, select the output of the trigger (the JSON string you want to verify).
-
You will need to provide a JSON schema for the "Parse JSON" action. The schema defines the structure of the JSON data. You can generate this schema based on a sample JSON payload. Example of a JSON schema:
{
"type": "object",
"properties": {
"max_tokens": {
"type": "integer"
},
"model": {
"type": "string"
},
"temperature": {
"type": "number"
},
"messages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"content": {
"type": "string"
}
},
"required": ["role", "content"]
}
}
},
"required": ["max_tokens", "model", "temperature", "messages"]
}
-
Handle the Output:
-
If the JSON string matches the schema, the "Parse JSON" action will succeed, and you can use the parsed data in subsequent actions in your Logic App.
-
If the JSON string does not match the schema, the "Parse JSON" action will fail, and you can handle this failure using a "Scope" action with "Configure run after" settings to catch and manage errors.
Example Workflow
-
Trigger:
-
"When a HTTP request is received"
-
Parse JSON Action:
-
Add the "Parse JSON" action and set up as described above.
-
Condition (Optional):
-
You can add a condition to perform different actions based on the success or failure of the "Parse JSON" action.
-
For example, if the JSON is valid, proceed with further processing; if not, send an error response.
Example JSON Schema for Your JSON String
Given your specific JSON structure, here is a more detailed example of the schema:
{
"type": "object",
"properties": {
"max_tokens": {
"type": "integer"
},
"model": {
"type": "string"
},
"temperature": {
"type": "number"
},
"messages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"content": {
"type": "string"
}
},
"required": ["role", "content"]
}
}
},
"required": ["max_tokens", "model", "temperature", "messages"]
}
Final Workflow Example
Here's a simplified visualization of the Logic App workflow:
-
Trigger: "When a HTTP request is received"
-
Action: "Parse JSON"
-
Content: Body from the trigger
-
Schema: Provided schema above
-
Condition: Check if "Parse JSON" succeeded
-
True Branch: Continue with further processing
-
False Branch: Handle the error (e.g., send an error response)
Testing
-
Send a request to your Logic App's HTTP endpoint with the JSON string to verify if the schema validation works correctly.
-
Check the runs in the Azure portal to see the results of the JSON parsing and handle any errors accordingly.
By following these steps, you can verify and work with JSON strings effectively within an Azure Logic App.

resubmit your errors

it fails before that is great

Fixes?
There are a few issues with your JSON data. Here are the problems and the steps to resolve them:
-
URL Encoding: The URLs in the content should not have escaped slashes. They should be properly formatted as URLs.
-
HTML and JSON formatting: The JSON contains HTML-like elements and URLs that are not escaped properly.
-
Message Content: The content of the user message includes a large block of text that needs to be cleaned up to make it suitable for JSON format.
Here's how to fix it:
Step 1: Properly Format the URLs
Ensure that all URLs are properly formatted without unnecessary escaping.
Step 2: Clean Up Message Content
The message content provided by the user is cluttered with unnecessary details like timestamps and image URLs from emails. Clean it up to keep only the relevant parts.
Step 3: Correct JSON Formatting
Make sure the JSON is formatted correctly, with proper escaping of special characters.
Corrected JSON:
{
"max_tokens": 880,
"model": "gpt-4",
"temperature": 0.7,
"messages": [
{
"role": "system",
"content": "creating a cover letter for Rifat Erdem Sahin for the job spec that is provided"
},
{
"role": "user",
"content": "I see from your job posting that you have been looking for me. My skills in software engineering, building high-performance trading systems, test-driven development, and video production make me an ideal candidate. I have experience working globally in diverse environments and am confident in my ability to contribute effectively to your team."
},
{
"role": "assistant",
"content": "Write a cover letter for Rifat Erdem Sahin who has matched skills for the job spec. Remove not filled placeholders."
},
{
"role": "assistant",
"content": "Based on the cover letter update accordingly for the email response: Use the company name in the job spec, use the job title in the job spec, set [Your Address] : 50 Petersfield Mansions, set [City, State, Zip] : Cambridge, Cambridgeshire, CB11BB, set [Email Address] : [email protected], set [Phone Number] : +447848024173, set [LinkedIn Profile] : https://www.linkedin.com/in/rifaterdemsahin/, set [Date] : today's date, set [Recipient's Name] : Take the name in the job spec, set [Company Name] : Take the company name in the job spec, set [Company Address] : Take the company address in the job spec, set [City, State, Zip] : Take the City, State, Zip in the job spec, set [Job Title] : Take the job title in the job spec."
},
{
"role": "assistant",
"content": "Use the cover letter to generate an HTML document based on the following requirements:\n\n1. Doctype and Head: The document should begin with the <!DOCTYPE html> declaration followed by an <html> tag. Inside the <html> tag, include a <head> section with a <title> tag that says 'Cover Letter'. Also, include a <meta> tag with charset=\"UTF-8\" to ensure proper text encoding.\n\n2. Body Structure: Within the <body>, the page should be divided into three main sections: a header, a main content area, and a footer.\n - The header should contain an <h1> tag with the text from the job spec title.\n - The main content area should have the cover letter (<p> tags) with placeholder text.\n - The footer should contain a paragraph with the text 'Copyright © DevOps Engineering'.\n\n3. CSS Styling: Include a <style> tag within the <head> section. The CSS should specify that the body has a margin of 0, the header text is centered and colored blue, the main content background is light gray, and the footer text is aligned to the center and has a smaller font size.\n\n4. Place the generated cover letter inside HTML."
},
{
"role": "assistant",
"content": "If a placeholder is not filled, omit it from the output or replace unfilled placeholders with relevant information or remove them if not applicable."
}
]
}
Explanation:
-
Role "user" Content: Cleaned up the user content to make it more coherent and relevant.
-
Role "assistant" Contents: Clearly outlined steps and instructions.
-
URLs and Placeholders: Ensured proper formatting for URLs and clarified how to handle placeholders.
This should resolve the issues and make the JSON suitable for use in Logic Apps.
In Logic Apps, you can use expressions and actions to find and fix URLs by encoding them properly. Here's a step-by-step guide to achieve this:
Step 1: Trigger the Logic App
Start with a trigger that initiates the Logic App, such as a new email, HTTP request, or a recurrence.
Step 2: Initialize Variables
Initialize a variable to store the input string and another variable to store the output string.
-
Initialize Variable action to store the input string (e.g.,
inputString). -
Initialize Variable action to store the processed string (e.g.,
outputString).
Step 3: Find and Extract URLs
Use the split and match expressions to find URLs in the input string.
- Add a Compose action to define a regular expression for URLs:
{
"name": "urlRegex",
"value": "(https?:\/\/[^\s]+)"
}
- Use the Compose action to split the input string based on the URL pattern:
{
"name": "splitParts",
"inputs": "@split(variables('inputString'), ' ')"
}
Step 4: Encode URLs
Loop through the split parts and encode any URLs found.
- Add a For Each action to iterate over the parts from the split action:
{
"inputs": "@outputs('splitParts')"
}
- Inside the For Each action, add a Condition action to check if the part matches the URL regex:
{
"inputs": {
"condition": "@match(item(), variables('urlRegex'))"
}
}
- If the condition is true (i.e., the part is a URL), use the Compose action with the
uriComponentfunction to encode the URL:
{
"name": "encodedURL",
"inputs": "@uriComponent(item())"
}
- Append the encoded URL to the
outputStringvariable using the Append to string variable action:
{
"name": "AppendEncodedURL",
"inputs": {
"variableName": "outputString",
"value": "@{outputs('encodedURL')}"
}
}
- If the condition is false (i.e., the part is not a URL), append the original part to the
outputStringvariable:
{
"name": "AppendOriginalPart",
"inputs": {
"variableName": "outputString",
"value": "@{item()}"
}
}
Step 5: Combine Processed Parts
After the For Each action, combine the processed parts back into a single string.
- Use a Compose action to join the processed parts:
{
"name": "joinedString",
"inputs": "@join(variables('outputString'), ' ')"
}
Step 6: Output the Processed String
Finally, output the processed string from the Logic App.
- Add an appropriate action to output or use the processed string, such as sending an email, HTTP response, or another desired action.
Here's a summarized JSON representation of the Logic App structure for reference:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_inputString": {
"inputs": {
"variables": [
{
"name": "inputString",
"type": "String",
"value": "Your input string with URLs here"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_outputString": {
"inputs": {
"variables": [
{
"name": "outputString",
"type": "String",
"value": ""
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Compose_urlRegex": {
"inputs": {
"name": "urlRegex",
"value": "(https?:\/\/[^\s]+)"
},
"runAfter": {},
"type": "Compose"
},
"Compose_splitParts": {
"inputs": "@split(variables('inputString'), ' ')",
"runAfter": {
"Initialize_inputString": [
"Succeeded"
]
},
"type": "Compose"
},
"For_Each_Part": {
"actions": {
"Condition_isURL": {
"actions": {
"AppendEncodedURL": {
"inputs": {
"name": "encodedURL",
"inputs": "@uriComponent(item())"
},
"runAfter": {},
"type": "Compose"
},
"Append_to_outputString_Encoded": {
"inputs": {
"variableName": "outputString",
"value": "@{outputs('encodedURL')}"
},
"runAfter": {
"AppendEncodedURL": [
"Succeeded"
]
},
"type": "AppendToStringVariable"
}
},
"else": {
"actions": {
"AppendOriginalPart": {
"inputs": {
"variableName": "outputString",
"value": "@{item()}"
},
"runAfter": {},
"type": "AppendToStringVariable"
}
}
},
"expression": "@match(item(), variables('urlRegex'))",
"runAfter": {},
"type": "If"
}
},
"inputs": {
"items": "@outputs('Compose_splitParts')"
},
"runAfter": {
"Compose_splitParts": [
"Succeeded"
]
},
"type": "Foreach"
},
"Compose_joinedString": {
"inputs": "@join(variables('outputString'), ' ')",
"runAfter": {
"For_Each_Part": [
"Succeeded"
]
},
"type": "Compose"
}
},
"triggers": {
"manual": {
"inputs": {},
"type": "Request"
}
}
}
}
This example demonstrates how to find and fix URLs in a string by encoding them properly using Logic Apps. Adjust the actions and expressions based on your specific needs.
Yes, you can use a single expression to remove URLs from a string in Logic Apps. You can achieve this using the replace function combined with a regular expression. Here's how you can do it:
Step 1: Define the Input String
You should have an input string variable that contains the text with URLs.
Step 2: Use the replace Function with a Regular Expression
You can use the replace function to remove URLs by replacing them with an empty string. The regular expression pattern for URLs can be used to match and remove them.
Expression to Remove URLs
Here's the expression you can use:
{
"name": "Compose_RemoveURLs",
"inputs": "@replace(variables('inputString'), 'https?://[^\\s]+', '')"
}
This expression uses a regular expression pattern to match URLs and replaces them with an empty string.
Example Implementation
Here's an example of how to implement this in a Logic App:
-
Initialize Variable action to store the input string:
json { "name": "Initialize_inputString", "inputs": { "variables": [ { "name": "inputString", "type": "String", "value": "Your input string with URLs here" } ] } } -
Compose action to remove URLs using the expression:
json { "name": "Compose_RemoveURLs", "inputs": "@replace(variables('inputString'), 'https?://[^\\s]+', '')" } -
Output action to see the result:
json { "name": "Output_CleanedString", "inputs": { "string": "@outputs('Compose_RemoveURLs')" } }
Complete JSON Representation
Here is the complete JSON representation of the Logic App with the steps:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_inputString": {
"inputs": {
"variables": [
{
"name": "inputString",
"type": "String",
"value": "Here is a link https://example.com and another one http://example.org"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Compose_RemoveURLs": {
"inputs": "@replace(variables('inputString'), 'https?://[^\\s]+', '')",
"runAfter": {
"Initialize_inputString": [
"Succeeded"
]
},
"type": "Compose"
},
"Output_CleanedString": {
"inputs": {
"string": "@outputs('Compose_RemoveURLs')"
},
"runAfter": {
"Compose_RemoveURLs": [
"Succeeded"
]
},
"type": "Compose"
}
},
"triggers": {
"manual": {
"inputs": {},
"type": "Request"
}
}
}
}
Explanation
- The
Initialize_inputStringaction initializes theinputStringvariable with the text containing URLs. - The
Compose_RemoveURLsaction uses thereplacefunction with a regular expression to remove all URLs from the input string. - The
Output_CleanedStringaction outputs the cleaned string, which no longer contains URLs.
This approach allows you to remove URLs from a string using a single expression in Logic Apps. Adjust the input string value as needed.
rebutmit failed one

It seems that the replace function in Logic Apps doesn't directly support regular expressions. Instead, you can achieve this by combining multiple actions. Here’s how you can remove URLs from a string in Logic Apps using a series of actions.
Step-by-Step Guide to Remove URLs
-
Trigger the Logic App
-
Start with a trigger that fits your scenario, such as a new HTTP request or email.
-
Initialize the Input String
-
Initialize a variable to hold the input string containing URLs.
-
Split the String
-
Use the
splitfunction to break the string into an array of words. This will help identify parts that are URLs. -
Identify and Remove URLs
-
Iterate through the array and check each part to see if it matches the URL pattern. If it does, remove it.
-
Combine the Cleaned Parts
-
Combine the remaining parts back into a single string without the URLs.
Implementation Details
Here is how you can implement this in Logic Apps:
1. Initialize the Input String
{
"name": "Initialize_inputString",
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "inputString",
"type": "String",
"value": "Here is a link https://example.com and another one http://example.org and some text without URLs."
}
]
}
}
2. Split the Input String
{
"name": "Compose_SplitString",
"type": "Compose",
"inputs": "@split(variables('inputString'), ' ')"
}
3. Iterate and Check Each Part
Add a For Each action to iterate over the array produced by the split operation:
{
"name": "ForEach_Parts",
"type": "Foreach",
"inputs": {
"items": "@outputs('Compose_SplitString')"
},
"actions": {
"Condition_IsURL": {
"type": "If",
"expression": {
"equals": [
"@if(equals(substring(item(), 0, 4), 'http'), true, false)",
true
]
},
"actions": {
"Do_Nothing": {
"type": "Compose",
"inputs": "URL found, doing nothing."
}
},
"else": {
"actions": {
"Append_NonURLPart": {
"type": "AppendToStringVariable",
"inputs": {
"name": "outputString",
"value": "@{item()}"
}
}
}
}
}
}
}
4. Initialize and Append to Output String
Initialize the output string before the loop:
{
"name": "Initialize_outputString",
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "outputString",
"type": "String",
"value": ""
}
]
}
}
Append each non-URL part to the output string within the loop:
{
"name": "Append_NonURLPart",
"type": "AppendToStringVariable",
"inputs": {
"name": "outputString",
"value": "@{item()} "
}
}
5. Output the Cleaned String
Finally, use a Compose action to output the cleaned string:
{
"name": "Output_CleanedString",
"type": "Compose",
"inputs": "@variables('outputString')"
}
Complete JSON Representation
Here is the complete JSON representation of the Logic App:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_inputString": {
"inputs": {
"variables": [
{
"name": "inputString",
"type": "String",
"value": "Here is a link https://example.com and another one http://example.org and some text without URLs."
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Compose_SplitString": {
"inputs": "@split(variables('inputString'), ' ')",
"runAfter": {
"Initialize_inputString": [
"Succeeded"
]
},
"type": "Compose"
},
"Initialize_outputString": {
"inputs": {
"variables": [
{
"name": "outputString",
"type": "String",
"value": ""
}
]
},
"runAfter": {
"Initialize_inputString": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"ForEach_Parts": {
"actions": {
"Condition_IsURL": {
"actions": {
"Do_Nothing": {
"inputs": "URL found, doing nothing.",
"runAfter": {},
"type": "Compose"
},
"Append_NonURLPart": {
"inputs": {
"name": "outputString",
"value": "@{item()} "
},
"runAfter": {},
"type": "AppendToStringVariable"
}
},
"else": {
"actions": {
"Append_NonURLPart": {
"inputs": {
"name": "outputString",
"value": "@{item()} "
},
"runAfter": {},
"type": "AppendToStringVariable"
}
}
},
"expression": {
"equals": [
"@if(equals(substring(item(), 0, 4), 'http'), true, false)",
true
]
},
"runAfter": {}
}
},
"inputs": {
"items": "@outputs('Compose_SplitString')"
},
"runAfter": {
"Compose_SplitString": [
"Succeeded"
]
},
"type": "Foreach"
},
"Output_CleanedString": {
"inputs": "@variables('outputString')",
"runAfter": {
"ForEach_Parts": [
"Succeeded"
]
},
"type": "Compose"
}
},
"triggers": {
"manual": {
"inputs": {},
"type": "Request"
}
}
}
}
Explanation:
-
Initialize Variables: The input string and output string are initialized.
-
Split Input String: The input string is split into parts based on spaces.
-
For Each Loop: Iterates through each part, checks if it starts with "http" or "https", and either ignores it or appends it to the output string.
-
Output Cleaned String: The final cleaned string is outputted, which does not contain any URLs.
This approach removes URLs from a string using Logic Apps without direct support for regular expressions in the replace function.
this one worked?

cleaner method is not so great

old code
`module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (!req.body || typeof req.body !== 'string') {
context.res = {
status: 400,
body: "Invalid input. Please provide a valid text input in the request body."
return;
}
const textInput = req.body;
function removeHtmlTags(text) {
return text.replace(/<[^>]+>/g, '');
}
function removeSensitiveInfo(text) {
const sensitiveInfoRegex = /\[Your Name\]|\[Your Address\]|\[City, State, ZIP Code\]|\[Email Address\]|\[Phone Number\]|\[Date\]/g;
return text.replace(sensitiveInfoRegex, '');
}
function escapeSpecialChars(text) {
return text.replace(/["\\\/\b\f\n\r\t]/g, function(match) {
switch(match) {
case '"':
return '\\"';
case '\\':
return '\\\\';
case '/':
return '\\/';
case '\b':
return '\\b';
case '\f':
return '\\f';
case '\n':
return '\\n';
case '\r':
return '\\r';
case '\t':
return '\\t';
}
}
let sanitizedText = removeHtmlTags(textInput);
sanitizedText = removeSensitiveInfo(sanitizedText);
sanitizedText = escapeSpecialChars(sanitizedText);
const responseMessage = {
status: 200,
body: sanitizedText
context.res = responseMessage;
`
new code
`module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (!req.body || typeof req.body !== 'string') {
context.res = {
status: 400,
body: "Invalid input. Please provide a valid text input in the request body."
return;
}
const textInput = req.body;
function removeHtmlTags(text) {
return text.replace(/<[^>]+>/g, '');
}
function removeSensitiveInfo(text) {
const sensitiveInfoRegex = /\[Your Name\]|\[Your Address\]|\[City, State, ZIP Code\]|\[Email Address\]|\[Phone Number\]|\[Date\]/g;
return text.replace(sensitiveInfoRegex, '');
}
function escapeSpecialChars(text) {
return text.replace(/["\\\/\b\f\n\r\t]/g, function(match) {
switch(match) {
case '"':
return '\\"';
case '\\':
return '\\\\';
case '/':
return '\\/';
case '\b':
return '\\b';
case '\f':
return '\\f';
case '\n':
return '\\n';
case '\r':
return '\\r';
case '\t':
return '\\t';
default:
return match;
}
}
function cleanUrls(text) {
const urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url) {
try {
const urlObj = new URL(url);
return urlObj.origin; // return the origin (scheme + domain)
} catch (e) {
return ''; // return empty string if URL is invalid
}
}
let sanitizedText = removeHtmlTags(textInput);
sanitizedText = removeSensitiveInfo(sanitizedText);
sanitizedText = cleanUrls(sanitizedText);
sanitizedText = escapeSpecialChars(sanitizedText);
context.res = {
status: 200,
body: sanitizedText
`
removed not needed urls


more cleanup

it is coming from my end

matchedskills clean

Fixed your error withg jsonlint so manual and digital gets mixed in the studio
Now it works and updated to gpt 4 with my system errors are taken out thanks to jsonlint ! > https://jsonlint.com/

try another one as implementer make sure it is working we dont want it to turn back from planner and operator

Imported from rifaterdemsahin.com · 2024