Generate integrations using AI¶
Did you know that the WSO2 Micro Integrator component of WSO2 Integrator includes an AI-powered assistant to help you effortlessly generate integration flows? In this guide, we are generating an API to retrieve weather information for a specified city and send it via email to a designated recipient.
Check out this video on YouTube to see it in action.
Let's get started!¶
Prerequisites¶
You need Visual Studio Code (VS Code) with the Micro Integrator for VS Code extension installed.
Info
See the Install Micro Integrator for VS Code documentation to learn how to install Micro Integrator for VS Code.
Step 1: Create an integration project¶
The Integration project will contain all the required artifacts for the integration solution.
-
Launch VS Code with the Micro Integrator extension installed.
-
Click on the Micro Integrator icon on the Activity Bar of the VS Code editor.
-
Click Create New Project on Design View.
Next, the Project Creation Form will be opened.
-
In the Project Creation Form, enter
AICodeDemo
as the Project Name. -
Provide a location under the Project Directory.
-
Click Create.
You will now see the projects listed in the Project Explorer.
Step 2: Setup MI Copilot¶
-
Click on the Open AI Panel button in the top left corner.
-
Sign in to MI Copilot via the MI extension.
Step 3: Generate the mediation using MI Copilot¶
-
Describe the scenario that you need to generate the integration.
Example Prompt
Generate a service to fetch weather data from a city name and email the weather details to the given email in the request. Refer to the attached OpenAPI Specifications for more details about the geolocation endpoint and weather endpoint.
-
Add any supporting files that are required to generate this integration such as OpenAPI specifications, schemas, etc., by clicking on the Add Files
button. In this guide, we are using the GeoLocationOAS.yaml and OpenWeatherOAS.yaml OpenAPI specifications.
-
Click on the Generate button and wait for the MI copilot to generate the necessary synapse configurations to work the scenario.
-
Once the configurations are generated, add them to the project using the Add to Project button, which is in line with the artifact name.
The API will resemble the following structure once all the generated artifacts have been added.
Note
The generated view may differ from ours, as AI-generated designs can vary. For example, AI may create separate sequences for the Weather API calls and email operation.
WeatherEmailService API
<api xmlns="http://ws.apache.org/ns/synapse" name="WeatherEmailService" context="/weatherEmail"> <resource methods="GET" uri-template="/getWeather?city={city}&email={email}"> <inSequence> <variable name="API_KEY" type="STRING" value="REPLACE_WITH_YOUR_KEY"/> <http.get configKey="OpenWeather"> <relativePath>/geo/1.0/direct?q=${params.queryParams.city}&limit=1&appid=${vars.API_KEY}</relativePath> <headers>[]</headers> <forceScAccepted>false</forceScAccepted> <disableChunking>false</disableChunking> <forceHttp10>false</forceHttp10> <noKeepAlive>false</noKeepAlive> <responseVariable>http_get_1</responseVariable> <overwriteBody>true</overwriteBody> </http.get> <http.get configKey="OpenWeather"> <relativePath>/data/2.5/weather?lat=${payload[0].lat}&lon=${payload[0].lon}&appid=${vars.API_KEY}</relativePath> <headers>[]</headers> <forceScAccepted>false</forceScAccepted> <disableChunking>false</disableChunking> <forceHttp10>false</forceHttp10> <noKeepAlive>false</noKeepAlive> <responseVariable>http_get_2</responseVariable> <overwriteBody>true</overwriteBody> </http.get> <email.send configKey="EMAIL_CONN"> <from>[email protected]</from> <personalName></personalName> <to>{${params.queryParams.email}}</to> <cc></cc> <bcc></bcc> <replyTo></replyTo> <subject>Weather Update</subject> <content>{${payload}}</content> <contentType>text/html</contentType> <encoding>UTF-8</encoding> <attachments></attachments> <inlineImages>[]</inlineImages> <contentTransferEncoding>Base64</contentTransferEncoding> </email.send> <respond/> </inSequence> </resource> </api>
Email Connection
<?xml version="1.0" encoding="UTF-8"?> <localEntry key="EMAIL_CONN" xmlns="http://ws.apache.org/ns/synapse"> <email.init> <connectionType>SMTPS</connectionType> <host>smtp.gmail.com</host> <port>465</port> <username>REPLACE</username> <password>REPLACE</password> <name>EMAIL_CONN</name> </email.init> </localEntry>
HTTP Connection
<?xml version="1.0" encoding="UTF-8"?> <localEntry key="OpenWeather" xmlns="http://ws.apache.org/ns/synapse"> <http.init> <connectionType>HTTPS</connectionType> <baseUrl>https://api.openweathermap.org/</baseUrl> <authType>None</authType> <timeoutAction>Never</timeoutAction> <retryCount>0</retryCount> <retryDelay>0</retryDelay> <suspendInitialDuration>-1</suspendInitialDuration> <suspendProgressionFactor>1</suspendProgressionFactor> <name>OpenWeather</name> </http.init> </localEntry>
Note
After adding the synapse artifacts to the project, make sure to update the synapse configurations as follows,
- Update the email connection with the credentials of the sender’s email account.
- Update the
API_KEY
variable with the OpenWeather key obtained to retrieve the weather data.
Step 4: Build and run¶
-
Click on the Build and Run button to build and deploy the integration.
-
Runtime Services will open after the server is up and running, and from that panel, select the API that you need to try out using the Try It button.
-
Click the Try it Out button to provide the required query parameters.
-
Provide the required parameters and click the Execute button to invoke the API.
-
Check the response received from the server and confirm that the weather details for the specified city have been successfully sent to the email address provided as a query parameter in the API request.
Automating complex integrations has never been easier. Why spend time doing all this manually when the Micro Integrator Copilot can do it for you? Try it out today and save yourself hours of effort!