I am working worth Azure Logic Apps only to fail.
- When email is arrived,
- Check the size of body of email and remove the HTML tags
- If the email body size is less than 10, want to send warning email(too short contents).
Step 1 is OK as similar cases are in MS docs. For step 2, I designed http trigger app function as follows,
import logging
import azure.functions as func
import json
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
logging.info(req.get_body())
#message = req.get_body().decode()
mess = req.get_body().decode()
message = str(mess)
message = message.replace("\\r\\n", " ")
####
out = remove_html_tags(message)
logging.info(out)
###
# some JSON:
jmess = '{{"name":{0}}}'.format(len(out))
# parse x:
#y = json.loads(jmess)
return func.HttpResponse(str(len(out)))
import re
def remove_html_tags(raw_html):
cleanr = re.compile('<.*?>')
cleantext = re.sub(cleanr, '', raw_html)
return cleantext
and the logic apps design looks like Logic Apps designer capture
As in the capture image, I want to know how to check the return value of http trigger function app in the Logic Apps Designer. In the attached code, return value type is just string, i.e. the length of the email body. (another JSON version return value did NOT work.-- jmess variables in the Python code)
CodePudding user response:
You haven't elaborated what is the exact issue you are facing or what and where is the error.
Looking at just your question, it seems like your condition check should be as below.
int(outputs('TestHttpTrigger'))
The int converts the string response to an integer before checking against the criteria.
CodePudding user response:
Finally I found answers myself.
- I thought that the return value of trigger function was just string(or int). Actually the return value was in JSON form.
- As of writing this post, I modified the return statement.
return func.HttpResponse(str(len(out)), mimetype='application/x-www-form-urlencoded')
- And in Logic Apps designer, I used this expression for checking the size of email body,
int(actionOutputs('TestHttpTrigger')['body']['$formdata'][0]['key'])
The Logic Apps logging shows why I used that expression
{ "statusCode": 200, "headers": { "Transfer-Encoding": "chunked", "Request-Context": "appId=cid-v1:f4f8c55f-e9e7-4f3a-8d3a-a3873d0ee143", "Date": "Mon, 06 Dec 2021 03:45:39 GMT", "Server": "Kestrel", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "1" }, "body": { "$content-type": "application/x-www-form-urlencoded", "$content": "OA==", "$formdata": [ { "key": "8", "value": "" } ] } }
Thanks @Anupam Chand.