Flow Development Assignments - Solutions
Solution 1 - Return Notification Number in Result
Section titled “Solution 1 - Return Notification Number in Result”- We need to add a
JSON Parserstep to extract the Notification Number from theBAPI Save Notifstep - Now select the
BAPI Save Notifnode and click on+and selectJSON Parserto add the JSON parser node. - The
JSON Parsernode is now opened and you can configure it.- Change the title to
Prepare Resultand remember to connect theBAPI Save NotifnodeSuccessconnector to this node (else the expression builder will not display all the possible fields and nodes) - Since we want to work with the previous step results, click on the
Previous Stepsection - For
Map Field NameselectBAPI Save Notif Result - Under
Expressionclick on the :fontawesome-solid-wrench: icon to open the Expression Builder - If not already copied, close the dialog and click on arrow icon next to
Run Flow. FromRun Historyselect the last run. Expand theBAPI Save Notifstep and copy the result - The output from this step is as below:
{"NOTIFHEADER": {"MARKER_DISTANCE_UNIT_ISO": "","MARKER_DISTANCE_UNIT": "","MARKER_DISTANCE_END_POINT": "","MARKER_END_POINT": "","MARKER_DISTANCE_START_POINT": "","MARKER_START_POINT": "","STAT_PROF": "","USERSTATUS": "","USER_ST": "","SYS_STATUS": "","SECOND_OFFSET_UNIT_ISO": "","SECOND_OFFSET_UNIT": "","SECOND_OFFSET_VALUE": "","SECOND_OFFSET_TYPE_CODE": "","FIRST_OFFSET_UNIT_ISO": "","FIRST_OFFSET_UNIT": "","FIRST_OFFSET_VALUE": "","FIRST_OFFSET_TYPE_CODE": "","LINEAR_UNIT_ISO": "","LINEAR_UNIT": "","LINEAR_LENGTH": "","END_POINT": "","START_POINT": "","MATERIAL_VERSION": "","MATERIAL_GUID": "","MATERIAL_EXTERNAL": "","ASSEMBLY_VERSION": "","ASSEMBLY_GUID": "","ASSEMBLY_EXTERNAL": "","SCENARIO": "","ITM_NUMBER": "000000","DOC_NUMBER": "","ADDR_NO_LOC_ACC": "","DIST_CHAN_LOC_ACC": "","DIVISION_LOC_ACC": "","SALES_ORG_LOC_ACC": "","COMP_CODE": "GB01","STLMTORDER": "","STDGORD": "","SUB_NUMBER": "","ASSET_NO": "","WBS_ELEMENT": "","COSTCENTER": "MAINT","CO_AREA": "GB01","BUS_AREA": "","PP_WKCTR": "10000001","PLSECTN": "","MAINTROOM": "","MAINTLOC": "ALBN","MAINTPLANT": "KALB","SORTFIELD": "","ABCINDIC": "","FUNCT_LOC": "A-ALBN-46- Z-4601","NOTIFTMEZ": "INDIA","SALES_GRP": "","SALES_OFFICE": "","DEVICEDATA": "","DELETE_FLAG": "","SERIALNO": "","PM_WKCTR": "10000001","CODING": "","CODE_GROUP": "","CAT_TYPE": "D","CREATED_AT": "09:37:39","CHANGED_AT": "00:00:00","ADDR_NUMBER": "","DISTR_CHAN": "","SALES_ORG": "","DIVISION": "","PURCH_NO_C": "","SALES_ORD": "","REFTIME": "09:37:39","REFDATE": "2024-03-22","PRILANG": "E","LONG_TEXT": "","CATPROFILE": "000000001","COMPTIME": "00:00:00","OBJECT_NO": "QM000010001106","CUST_NO": "","MATERIAL": "","ORDERID": "","DESENDTM": "00:00:00","DESSTTIME": "09:37:38","DESSTDATE": "2024-03-22","REPORTEDBY": "","NOTIF_DATE": "2024-03-22","NOTIFTIME": "09:37:38","CHANGED_BY": "","CREATED_ON": "2024-03-22","CREATED_BY": "INDUSER","PRIORITY": "","PRIOTYPE": "PM","SHORT_TEXT": "Short Text ????????","NOTIF_TYPE": "M1","MAINTITEM": "","MNTCALL_NO": 0,"MNTPLAN": "","PLANGROUP": "46","ISOCODE_UNIT": "","UNIT": "H","DOWNTIME": 0,"ENDMLFNTIME": "00:00:00","STRMLFNTIME": "00:00:00","BREAKDOWN": "","ASSEMBLY": "","EQUIPMENT": "AN-JC-4601","LOC_ACC": "000000002262","PLANPLANT": "KALB","NOTIF_NO": "000010001106"}}
- We now need to extract the NOTIF_NO and prepare the result. Lets use the below expression:
$.NOTIFHEADER.NOTIF_NO
- Paste the expression from the step above into the
Mapping Expressionwindow on the right. The extracted data is now displayed at the bottom. Confirm that what is displayed is correct. - Now Click on
Saveand close the builder, - Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
- Change the title to
- Select the
Prepare Resultnode and click on+and search for response and select theResponsenode. - The
Responsenode is now opened and you can configure it.- Change the title to
Send Notif Resultand remember to connect thePrepare ResultnodeSuccessconnector above to this node (else the expression builder will not display all the possible fields and nodes) - Select the Success option
- Set the
HTTP Codeto 200 to signify HTTP Success - For
Bodyclick on the :fontawesome-solid-wrench: icon to open the Expression Builder - Type in Notification created:. Place the cursor after the message and then Select Result below the
Prepare Resultentry - Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
- Change the title to
- Now click on Publish button to save and compile the flow. If the compilation is successful it will also be published and we can run it to test.
- Run the flow to test it and check the result.
Solution 2 - Change Teams Input
Section titled “Solution 2 - Change Teams Input”- Copy the
Post Message To Teamsflow toPost Message To Teams v2using theCopy Flowoption in the Forms list - Change the
Flow Inputto the format expected by Teams (use attribute name astextinstead ofmessage) - Delete the
JSON Parsernode and connect theSub Flownode directly to theSend Teams Messagenode - Set the
Flow Inputas body parameter directly in theSend Teams Messagenode. Run and check if the message is received - Finally, change the
Save to DatabaseFlow to use thePost Message To Teams v2and change theFlow Inputas above. Run the flow and check if the new message is received
Solution 3 - OpenAI Integration for Teams Chatbot
Section titled “Solution 3 - OpenAI Integration for Teams Chatbot”OpenAI API Key configuration
Section titled “OpenAI API Key configuration”- Login to OpenAI developer portal and obtain an API Key
- Click on the
Morebutton in theComputer Inspectionrow and choose the Environment option - In the Environment dialog, click on the
Addbutton - Set the key to OPENAI_API_KEY and the value to the API key that you obtained from the OpenAI portal
Adding the OpenAI integration
Section titled “Adding the OpenAI integration”- Click on the
Moreoption to open theFlowsand theTeams Chatbotflow again. - Click on the
Extract Equipmentnode and click on the :fontawesome-solid-circle-plus: icon that is displayed below the node - Search for the
Httpnode by typing in http and clicking on it - The
HTTPnode is now opened and you can configure it.- Change the title to
Process OpenAIand remember to connect theWebhook FlownodeSuccessconnector to this node (else the expression builder will not display all the possible fields and nodes) - We will be adding a new system to communicate with the OpenAI Server. Later if we need to work with a different API provided by the OpenAI server we can reuse the server and modify the URL path we are communicating to. Click on :fontawesome-solid-plus: icon next to the Server dropdown.
- You will need to refer to the OpenAI developer documentation
- The
Add Systemdialog is displayed. Enter the following data:- Description: OpenAI (or anything else you desire)
- Identifier: This is a unique identifier for the system, enter open-ai
- URL: Set it to https://api.openai.com
- Set the
Authentication Typeto None, we will configure the API token in the http call itself - Set the
OAuth Providerto None - Save the system
- Now choose the newly added
open-aisystem (or the name that you entered above) - Change the
HTTP Actionto Post Content-TypeandAcceptneeds to be applicaiton/json- For
URL Pathset it to /v1/chat/completions - Lets configure the authentication now. We didn’t use any standard authentication type at system level since a static token only has to be posted. Click on
+icon to add a key value pair- Enter Authorization for the
Key. - For
Valueclick on the :fontawesome-solid-wrench: icon to open the Expression Builder - For expression, first type in ***Bearer *** and then from the list under Environment choose OPENAI_API_KEY
- Enter Authorization for the
- Now we need to configure the message. The OpenAI API expects the message in JSON format in the
Bodyparameter. Scroll down to theBody Dataconfiguration and click on the :fontawesome-solid-wrench: icon to display the expression builder. - Paste the below JSON into the
Expressionfield.{"model": "gpt-3.5-turbo","messages": [{"role": "system","content": "You are an assistant who can extract computer equipment or part names from the content. For e.g for the message <<<Find inventory for memory>>> return the equipment <<<memory>>> as the result. Return the extracted word only and nothing else. If you do not find any equipment return the text <<<notfound>>>. Do not guess any equipment names."},{"role": "user","content": ""}]} - Now carefully place the cursor after the first double quote after the : sign in the text “content”: ""
- Now from the list after
Extract Equipmentselect Result so that the text looks like this now: “content”: “${extractequipment_result}” - Finally set the parameter
Success HTTP Codeto 200 so that any other code returned by OpenAI is treated as an error
- Change the title to
- We now need to extract the OpenAI response. Click on the
Process OpenAInode and click on the :fontawesome-solid-circle-plus: icon that is displayed below the node - Search for the
JSON Parsernode by typing in json and clicking on it - The
JSON Parsernode is now opened and you can configure it.- Change the title to
Extract OpenAIand remember to connect theProcess OpenAInodeSuccessconnector above to this node (else the expression builder will not display all the possible fields and nodes) - Since we want to work with the returned message, click on the
Previous Stepssection - For
Map Field Nameselect Process OpenAI and then Result - We need the message format returned by the
Process OpenAImaster data method. For the response format check OpenAI developer documentation Remember the returned data will be embedded in another JSON as below:{"httpCode": 200,"headers": {},"data": {"model": "gpt-3.5-turbo-0125","choices": [{"index": 0,"message": {"role": "assistant","content": "computer"},"finish_reason": "stop"}],"usage": {}}} - Under
Expressionclick on the :fontawesome-solid-wrench: icon to open the Expression Builder - Copy and paste the JSON above into the
JSONwindow on the left - The expression builder we use for JSON parsing is a tool called Jsonata
- We need to extract the inventory now. However remember that if the equipment was not found an empty array will be returned. So we use the
{'$'}exists*()function to make sure that the attribute exists. Also we will be using data[0] as we want the first returned row.{'$'}.data.choices[0].message.content - Paste the expression from the step above into the
Mapping Expressionwindow on the right. The extracted equipmentcomputeris now displayed at the bottom. Confirm that what is displayed is correct. - Now Click on
Saveand close the builder, - Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
- Change the title to
- Connect the
Extract OpenAInode toRead Inventory - Open the
Read Inventorynode and underFilteropen the expression builder by clicking on the :fontawesome-solid-wrench: icon - In the condition change the value being compared to the Result of the step
Extract OpenAIso that the equipment identified by OpenAI can be used to run the master data query - Additionally select the OR option and add another field by clicking on
+icon. Choose the Equipment Name field and set toggle to Custom and the value again to the Result from the stepProcess OpenAIso that we can check for name or id - Now click on Publish button to save and compile the chatbot flow. If the compilation is successful it will also be published and we can now test it.
- Login to Teams and as before send a more detailed query and if all works well and OpenAI identifies the equipment you should get back the answer.
- Congratulations, you have now successfully built your first GenAI Turbo Apps Chatbot for MS Teams