{"id":38709,"date":"2020-08-12T15:00:29","date_gmt":"2020-08-12T14:00:29","guid":{"rendered":"https:\/\/www.microsoft.com\/en-gb\/industry\/blog\/?p=38709"},"modified":"2020-08-12T13:17:41","modified_gmt":"2020-08-12T12:17:41","slug":"azure-healthcare-bot-service-logic-app-integration-e-mail","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-gb\/industry\/blog\/technetuk\/2020\/08\/12\/azure-healthcare-bot-service-logic-app-integration-e-mail\/","title":{"rendered":"Azure Healthcare Bot Service Logic App Integration (E-Mail)"},"content":{"rendered":"
<\/p>\n
This tutorial demonstrates how to add Logic App integration<\/strong> to your chatbot<\/strong>, specifically, adding email functionality<\/strong>. It may seem difficult to begin with, but once you are shown how to do it, it is actually quite simple.<\/p>\n This tutorial would not have been made possible without the guidance and support of Saranya Ravichander<\/strong> (CSA), and Gregory Lisiak<\/strong> (Architect).<\/p>\n <\/p>\n The tutorial is split into three parts; Healthcare Bot Scenario Set Up<\/strong>, Logic App Set Up<\/strong> and the Healthcare Bot & Logic App Integration<\/strong>.<\/p>\n I\u2019m using the following resources: Azure Healthcare Bot Service<\/strong> (Azure Marketplace), Logic Apps<\/strong> (Portal), and an Outlook<\/strong> account (Office 365).<\/p>\n You must have:<\/p>\n <\/p>\n To begin, you will need to create the representative JSON payload in order to populate the dynamic content for the Logic App to use for generating the email. This could be as simple as simply sending contact information to the Logic App to send a basic email or as detailed as sending the information collected during the bot conversation as a conversation transcript. At the end of your scenario:<\/p>\n 1. Add an Action element to build an array containing all of the variables needed such as; It may be beneficial to save this in a text file as you will need the array information in a later step. For example:<\/p>\n 1.1 Add a Statement element that simply displays the array information which will be needed by the Logic App to build the dynamic content inventory that it will need to support. The statement element would look like this in the editor:<\/p>\n 1.2 Run the Bot scenario and copy the resulting statement. It will look like this:<\/p>\n Keep a copy of this. We will use this later.<\/p>\n 1.3 You will need to use a text editor to change the quote marks to be consumable by the Logic App. For example:<\/p>\n <\/p>\n Your scenario editor should now have the following new elements: 1 x Action element, 1 x Statement element and 1 x Data Connection element. Take a look at the image below for an example:<\/p>\n <\/p>\n Note: You can ignore the final \u201cThank You\u201d statement element.<\/p>\n <\/p>\n 1. Now go to the Azure Portal and create a Logic App resource.<\/p>\n 1.1.1 Go to the Logic Apps Designer and choose the \u201cWhen a HTTP request is received\u201d as the trigger.<\/p>\n <\/p>\n 1.1.2 Click on \u201cUse sample payload to generate schema\u201d<\/p>\n <\/p>\n 1.1.3 This is where you will paste in the output you generated in the Bot scenario and cleaned up the quotes in the text editor.<\/p>\n <\/p>\n Once you click done, the Request Body JSON Schema will look something like this:<\/p>\n <\/p>\n 1.1.4 Save this step, and the HTTP POST URL will be generated. You should see something like this:<\/p>\n <\/p>\n 1.2 On the Logic App Designer, click on \u201c+ New Step\u201d<\/p>\n 1.2.1 Search for \u201cOutlook\u201d.<\/p>\n 1.2.2 Under Actions, select \u201cSend an email (V2)\u201d \u2014 it will ask you to sign in<\/p>\n <\/p>\n <\/p>\n 1.2.3 Once signed in, you can format the email. The fields from the JSON payload can be selected from the Dynamic Content list.<\/p>\n <\/p>\n You will notice that if you leave this composer and go back into the step, the order of the fields change. You will find that it is much easier to use Word to craft the base message and paste it into the Body before adding the dynamic content. Formatting options are a bit limited (e.g. Tables cannot be added for instance).<\/p>\n 1.2.4 Enter whatever you want in the email body\/subject\/recipient. Regarding the dynamic content, all the blocks you can see in the image below are classed as dynamic content. It will be dependant on the values you input in the bot conversation. The way you input dynamic content is simple: Clicking anywhere in the body\/subject\/to sections leads to a pop-up section on the right-hand side. You can then search for fields that you specified in the sample payload. Now in the email, those fields will show whatever you input in the bot conversation. Here is an example of \u201cSend an email (V2)\u201d step:<\/p>\n <\/p>\n Once you complete the email template, you are ready to return to Bot. Don\u2019t forget to copy the HTTP Post URL before leaving the Logic App Designer.<\/p>\n <\/p>\n 1. Add a Data Connection element to your Bot scenario, choose \u201cPOST\u201d and paste your Base URL (this is the HTTP Post URL we just copied) into the Data Connection Call. If you copied your array assignment to a text file, find it and copy it into the Payload section. If you didn\u2019t, you can save the Data Connection Call, go to the Action Block and copy it and come back to the Data Connection. Assign the variables for the response and error and click OK. For example:<\/p>\n <\/p>\n 1.1 If you haven\u2019t done so already, you can delete the Statement Block created in step 2 and connect the Action Block from Step 1 to your Data Connection Call.<\/p>\n <\/p>\n 1.2 Here is a sample email:<\/p>\n <\/p>\n <\/p>\n Using this tutorial, you should now be able to send a variety of different emails for your use cases. Logic Apps makes the integration and flow between these Azure services incredibly simple, yet effective.<\/p>\n If there are any questions or ideas for a follow up blog, please drop a message.<\/p>\n <\/p>\n This tutorial demonstrates how to add Logic App integration to your chatbot, specifically, adding email functionality. It may seem difficult to begin with, but once you are shown how to do it, it is actually quite simple.<\/p>\n","protected":false},"author":430,"featured_media":23103,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"_classifai_error":"","footnotes":""},"categories":[594],"post_tag":[519],"content-type":[],"coauthors":[1128],"class_list":["post-38709","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technetuk","tag-technet-uk"],"yoast_head":"\nAcknowledgements:<\/h3>\n
Getting started<\/h2>\n
\n
1. Healthcare Bot Scenario Set Up<\/h2>\n
scenario.testVar<\/span> = \r\n{\r\n\"email\":scenario.patientEmail<\/span>,\r\n\"patientID\":scenario.patientID<\/span>,\r\n\"patientAge\": scenario.patientAge<\/span>,\r\n\"smokerOrNot\": scenario.smokerOrNot<\/span>,\r\n\"alcoholAmount\": scenario.patientAlcohol<\/span>.entity<\/span>,\r\n\"riskLevel\": scenario.riskLevel<\/span>,\r\n\"riskScore\": scenario.riskScore<\/span>,\r\n}<\/pre>\n
JSON<\/span>.stringify<\/span>(scenario.testVar<\/span>)<\/pre>\n
{\r\n\"email\":\"johnsmith@notreal.com\",\r\n\"patientID\":5<\/span>,\r\n\"patientAge\":55<\/span>,\r\n\"smokerOrNot\":\"non-smoker\",\r\n\"alcoholAmount\":\"> 14 units\/week\",\r\n\"riskLevel\":\"high level\", \r\n\"riskScore\":0.008245917062178134<\/span>\r\n}<\/pre>\n
2. Logic App Set Up<\/h2>\n
3. Healthcare Bot & Logic App Integration<\/h2>\n
Going Forward<\/h2>\n
Useful Resources<\/h2>\n
\n
More from Jalal Uddin:<\/h3>\n
\n