cancel
Showing results for 
Search instead for 
Did you mean: 
ShanmugaRaja

Integration of Power Virtual Agent (with Ask Adaptive Card) with Third-Party API via Custom Connector and Dynamic 365 CE through Power Automate

Integration of Power Virtual Agent (with Ask Adaptive Card) with Third-Party API via Custom Connector and Dynamic 365 CE through Power Automate

 

In my earlier article Power Virtual Agent Integration With Dynamic 365 CRM Using Power Automate, I show how when a customer requests a new connection, the bot swiftly presents a question to gather essential information from the customer. To achieve this, I structured the bot to include an “Ask a question” node that captured customer details. Furthermore, I established corresponding variables to store their responses in dedicated variables for further use.

 

This question node is designed to showcase non-interactive cards that provide information. This can lead to challenges in discerning between mandatory and optional questions. In situations where customers attempt to skip or don’t respond to necessary questions, the bot responds by prompting the question once, and twice if needed, aiming to obtain a suitable answer from the customer. However, this strategy becomes intricate when seeking more comprehensive information from customers.

 

Adaptive Cards play a crucial role within Power Virtual Agents, providing a versatile and interactive method for user engagement. They server to present diverse content, gather user inputs, and deliver dynamic interfaces that adapt according to user interactions. Through the utilization of the Ask with Adaptive Card feature, developers can craft chatbot experiences that are both more captivating and interactive, ultimately enhancing user contentment and elevating the overall effectiveness of the chatbot.

 

Working Principle:
Our main objective is to gather essential customer information, pinpoint the address location on a map, and validate it with the customer. Ultimately, this process results in the creation of lead records in Dynamics 365 containing the customer’s details.

Let’s Start!!!

 

Creating the Adaptive Card:
There are two methods to access the Adaptive Designer portal:

  • Through the website https://adaptivecards.io/designer/
  • In Power Virtual Agent, by clicking the plus symbol for the new node and selecting “Ask with Adaptive Card”. This action opens the Adaptive Card Node properties on the right side. The Adaptive Card property window provides a link to open the Adaptive Card designer at https://adaptivecards.io/designer/

ShanmugaRaja_0-1693199304694.png

 

#1 Design Lead Form:
For the purpose of this article, I will intentionally opt for an application login sample adaptive card, which closely aligns with our needs.

 

ShanmugaRaja_1-1693199352152.png

 

We’ll modify it by substituting “username” with “First Name” and introducing new input fields for “Last Name”, “Mobile Number”, “Email”, and “Address”. Additionally, we’ll eliminate the password input text from the card.

 

ShanmugaRaja_2-1693199381669.png

 

Whenever new elements are introduced, elements are removed, or element properties are updated within the card, the corresponding JSON is generated in the card payload editor.

 

ShanmugaRaja_3-1693199433368.png

 

#2 Static Map Gallery Adaptive Card:

Based on our situation, our requirement involves showing a static map that marks the address, and the location is emphasized with a marker to receive customer confirmation. To achieve this, I’ve introduced an image element within the container. Additionally, a toggle button has been integrated to confirm the highlighting of the location on the static map image.

 

ShanmugaRaja_0-1693199580929.png

Creating Custom Connector:

Since I required access to a Third-Party API, I embarked on a bit of online research to find a solution, leading me to discover Geoapify, a valuable resource for requesting latitude and longitude by configuring the base parameter in the request. Geoapify offers a range of services including maps, address and location search, route optimization, reachability analysis, and geodata access. It provides core maps APIs, Auxiliary APIs, and data services.

The Power Platform empowers developers to easily craft custom connectors in just five steps. If you're interested in learning about custom connectors, I invite you to explore my article, Integrating Dynamic 365 CRM with Third-party API via Custom Connector using Power Automate Part 1. This article offers a comprehensive description of creating Custom Connectors in Power Automate for third-party systems, providing a clearer understanding of custom connectors and their functionality.

Step #1: General Details
I have updated the host to reflect the address for the latitude and longitude API. The connector relies on this API host and the base URL to determine the method of calling the API.

 

ShanmugaRaja_0-1693200022261.png

Step#2: Specify Authentication Type
The Get Latitude Longitude APIs use API key authentication. Under API key section, update a parameter label, name, and location details.

ShanmugaRaja_1-1693200061011.png

Step #3: Create the connector definition.
Under the “General” section, include a summary, description, and operation ID for this action.

ShanmugaRaja_2-1693200096159.png

opt for "import from sample" to provide the required details for API connection. The verb list displays a standard range of API request types (GET, POST, PUT, DELETE PATCH, HEAD, OPTIONS). In our scenario, we've chosen the "GET" method and defined the request URL (https://api.geoapify.com/v1/geocode/search?text=address&format=json) before proceeding with the import.
When importing the sample URL, its query parameters become visible in the request section. Each of these parameters needs to be configured.
Within the response area, relevant information is presented in accordance with the HTTP response of the actions. Choose to “default” button.
Simply input a sample of the response JSON into the body section and then click on “import” button.
The validation section exhibits any identified issues within the API definition.

Step#4: Code (preview)
This step is not mandatory, So I’ve skipped it and am proceeding directly to step 5: Test.

Step#5: Perform a test on the custom connector.
Upon successfully creating and authenticating the custom connector by entering the API key, the connector becomes prepared to make API calls. This allows us to examine the response, which includes the latitude and longitude for the provided address.

ShanmugaRaja_3-1693200220463.png

 

Our Custom connector is now ready for use!

 

Creating Power Automate Flow:

According to our needs, we need to develop two flows:

Flow #1: Get latitude and longitude.
The objective behind establishing this flow is to receive an address from the bot, forward it as a request parameter to the GetLatitudeLongitude API (custom connector), and obtain the corresponding latitude and longitude as a response for the given address.

 

ShanmugaRaja_0-1693200418495.png


Flow #2: Create Lead

The objective of this process is to gather customer information from the bot and create a Lead record within Dynamics 365 CE.

 

ShanmugaRaja_1-1693200464291.png

 

It’s time to build the Power Virtual Agent!!

We will create the bot to gather lead information when a customer requests a New Internet Connection. When the user initiates the conversation with greetings such as Hi, Hello, or Good Morning, the Power Virtual Agent will promptly guide the user to choose from the following options:

  • Need a New Connection
  • Broadband Related Queries

ShanmugaRaja_0-1693200641762.png

New Internet Connection Process Branch:

In the context of a Power Virtual Agent, it's necessary to prompt customers for specific information, including:

  • Enter First Name
  • Enter Last Name
  • Enter Mobile Number
  • Enter Email
  • Enter Address
  • Enter Comments

In a previous article, I manually created six variables corresponding to these questions (Enter First Name, Last Name, Mobile, Email, Address, and Comments). I also incorporated six "Ask a question" nodes to capture customer details, saving their responses in the respective variables for later use. However, this approach becomes complex when gathering more extensive information from customers.

Introducing a new feature, Power Virtual Agent now includes an "Ask with Adaptive Cards" node. This functionality allows you to incorporate text, graphics, and buttons, enhancing conversational capabilities within your bot.

Step#1: Incorporate an Adaptive Card node to accommodate the Lead Form
Click on the “Add node (+)” option, then choose “Ask with Adaptive Card” you can access the property pane for the node by selecting the card icon.

ShanmugaRaja_0-1693200878469.png


Alternatively, choose the Node Menu ( : ), and then opt for properties.


ShanmugaRaja_1-1693200915216.png


In the “Edit JSON” area, input the JSON code for our card. To access a more extensive view of the JSON editor, click on the “Expand” icon. I’ve included the Lead Form JSON code within the editor. Click anywhere outside the editor to proceed.

ShanmugaRaja_2-1693201092829.png


Based on the inputs detected in the card, Power Virtual Agents automatically create output variables.

ShanmugaRaja_3-1693201129683.png

Note: Card must contain at least one submit button, as it must be an interactive card that allows a user to submit information back to the bot. If it does not and is only intended to show information to the bot user, we should add card as an attachment to a Message node.

Step #4: To trigger a custom connector via Flow.

An action node has been included and choose the “Get latitude and longitude” flow from the available options. This specific flow is designed to take an address as input and provide latitude and longitude as two separate outputs.

ShanmugaRaja_0-1693201234683.png


The Getlatitudelongitude API (custom connector) is called based on the address as input, which returns the longitude and latitude for the address. This return values are stored in variables (latitude and longitude) for further process.


Step#5:

To render the map according to the provided latitude and longitude, I intend to utilize the pre-designed static Map gallery adaptive card. I have incorporated the “Ask with Adaptive Card” node and pasted the JSON of the prepared Static Map gallery adaptive card.

Geoapify provides an API that enables us to retrieve a static map image by utilizing latitude and longitude coordinates.

"https://maps.geoapify.com/v1/staticmap?style=osm-carto&width=800&height=600&center=lonlat:<lat_valu...

 

As per our requirement we need to plugin latitude and longitude variables within adaptive card. This can achieve by using Power FX to make our adaptive card dynamic.

Select the Edit JSON button, then choose Formula. This automatically converts any card the JSON has already presented into Power Fx.

Below is a JSON of a Map gallery card and the resulting Power Fx, where two variables Topic.latitude and Topic.longitude are used instead of a hard-coded value.

ShanmugaRaja_0-1693201754047.png


Ultimately, the Geoapify API URL (with latitude and longitude values dynamically included) is assigned to the URL of the Map gallery image element. This setup aims to showcase a static map image reflecting the customer’s provider address within the lead form.

Toggle element is added, which allows customers to verify and confirm the location, which is indicated by a highlighted marker in Map.


Step#6:

A conditional node is implemented to determine whether the customer had confirmed the location or not.

Step#7:

An action node has been included and choose the “Lead Creation” flow from the available options. This specific flow is designed to take the customer details, along with the associated latitude and longitude coordinates.

ShanmugaRaja_1-1693201821235.png


Step#8:

A Message node is integrated to exhibit the statement “Our technical team will be in touch shortly”. and lastly, an End node is incorporated to conclude the chat session.

 

Test your Bot:

To examine the changes made in Power Virtual Agents, access the Test Bot pane and ensure that “Track between topics” is enabled. The bot will initiate the conversation by displaying message “Hello, I’m internet broadband Company!”.


When the user initiates the conversation with greetings such as Hi, Hello, or Good Morning, the Power Virtual Agent will promptly guide the user to choose from the following options:

  • Need a New Connection
  • Broadband Related Queries

ShanmugaRaja_2-1693201954055.png


When the customer chooses the “Need a New Connection” option, the bot will immediately display an adaptive card (“Lead form”). This approach facilitates the gathering of all customer information with a single form, along with the validation of responses and storage of answers in dedicated variables.


ShanmugaRaja_3-1693202007894.png

The bot exhibits an adaptive card with a map showing the area designated by the provided address. The location is marked with a highlighted marker. Customers can verify the location by using the “confirm the location” toggle button and submitting their confirmation.

ShanmugaRaja_4-1693202044359.png


Upon confirmation, a lead record is created in the backend by using the customer's details and along with the latitude and longitude coordinates.

After confirmation, a lead record created using the customer’s information, along with the associated latitude and longitude coordinates.


ShanmugaRaja_5-1693202075854.png


Finally, an email is sent to the customer, notifying them that the technical team will be in touch shortly.

Concluding the technical article, it’s evident that integration of Power Virtual Agent (with Ask Adaptive Card) with external APIs via Custom Connectors and Dynamic 365 CE through Power Automate significantly enhances the capabilities of automated interaction. This integration empowers businesses to engage users more intelligently and efficiently, facilitating seamless data flow and streamlined processes.

Happy Learning and Happy Sharing. Cheers!!

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/