Sending Microsoft Teams messages with vRealize Orchestrator

In this post we’re going to walk through sending a message/notification to Microsoft Teams from within vRealize Orchestrator (vRO).

Create Microsoft Teams Connector

The first thing we need to do is to create a custom incoming webhook in Microsoft Teams to allow vRO to send a message to Teams. Follow the steps listed below or follow the link for setting up a Microsoft Teams connector.

Follow the steps below to see how to send a simple card to a Connector.

  1. From within Microsoft Teams, click … next to the channel name and then select Connectors.
  2. Scroll through the list of connectors to Incoming Webhook, and click Add.
  3. Enter a name for the webhook, upload an image to associate with data from the webhook, and select Create.
  4. Copy the webhook to the clipboard and save it. You’ll need the webhook URL for sending information to Microsoft Teams.
  5. Click Done.

Create vRO Workflow

Now that we’ve created our Microsoft Teams connector we need to create our vRO workflow to send messages.

We’ll start by creating a workflow and add a scriptable task to the workflow.

To make the workflow modular we can add two inputs that will set the title of the message as well as the message body. The variables should be named “messageTitle” and “messageBody“.

Now that we’ve got the scriptable task and inputs taken care of we just need to add the code to actually post our message to Microsoft Teams. The code below can be copied and pasted into the scriptable task and simply adding the Microsoft Teams webhook url that was generated when we created our Microsoft Teams connector.

// Send message to Microsoft Teams

url = '';

// Import SSL certificate
var ld = Config.getKeystores().getImportCAFromUrlAction();  
var model = ld.getModel();  
model.value = url;  
error = ld.execute();

// Set message title and text
var messageTitle = "vRealize Orchestrator Workflow Status";  
var messageText = "vRO workflow completed successfully"

//  Create REST call
var uri = "***INSERT WEBHOOK URL HERE***";  
var method = "POST";  
messageTitle = "'" + messageTitle + "'"  
messageText = "'" + messageText + "'"  
var body = "{'@type': 'MessageCard','@context': '', 'themeColor': '0076D7', 'title': " + messageTitle + ",'text': " + messageText + "}";  
var httpRestHost = null;

//  Create a dynamic REST host:

var restHost = RESTHostManager.createHost("dynamicRequest");  
restHost.operationTimeout = 900;  
httpRestHost = RESTHostManager.createTransientHostFrom(restHost);  
httpRestHost.operationTimeout = 900;

//  Remove the endpoint from the URI:
var urlEndpointSplit = uri.split("/");  
var urlEndpoint = urlEndpointSplit[urlEndpointSplit.length - 1];  
uri = uri.split(urlEndpoint)[0];

httpRestHost.url = uri;  
httpRestHost.hostVerification = false;

//  REST client only accepts method in all UPPER CASE:
method = method.toUpperCase();

var request = httpRestHost.createRequest(method, urlEndpoint, body);  
request.contentType = "application/json";

System.debug("REST request to URI: " + method + " " + request.fullUrl);

var response = request.execute();   //  This should have a 90-second timeout  
System.debug("Response status Code: " + response.statusCode);

if ( response.contentAsString )  
  System.debug("Response: " + response.contentAsString);

With everything in place we can kick off the vRO workflow and provide the title and body for our Teams message.

After our vRO workflow completes we should get a wonderful vRO message in Microsoft Teams similar to the one below.

The message can be greatly extended to include actions and additional formatting.


Setting up a custom incoming webhook

Actionable messages via connectors