Banner Image

Using Dialogflow to power Microsoft Teams bot for our WorkinSync App

by MoveInSync | December 5, 2022

WorkinSync is an emerging leader in the Flexible workspace management space. Given our employee first approach, we aim to make the employee side flows such as Desk booking available to employees wherever they are.

Microsoft Teams has emerged as the central communication tool for remote and hybrid teams for a lot of our enterprise clients. So we have been working hard on developing a top quality WorkinSync app for Teams.

Teams bot is one of the key capabilities we want to leverage to give a smooth & modern experience to a Teams user. We also didn’t just wanted to restrict ourselves to a simple command based menu for the bot. Whenever a user hears the term ‘Bot’ they also expect basic Natural language understanding.

The default option to power the NLU layer would have been to go with Microsoft LUIS. However, we realized we have already done the hard work of training a bot for our Google Assistant App. It would make a lot more sense if we can reuse the same agent with Microsoft Teams App. That way we don’t have to create, train, test and maintain our conversation flows on two different platforms. The improvements done for one are automatically available for the other.

This is how the brilliant tech team at MoveinSync went about doing it. [Disclaimer: This is just a preview to illustrate the plumbing and not the actual application code]

Once the user sends a command like
“Book a seat for me for tomorrow 9:00 AM”

The backend service for our Teams App is written entirely in java. The bot which is exposed to Microsoft Team is created using the Azure bot framework. https://azure.microsoft.com/en-in/services/bot-services/
So we are using the Bot Framework SDK for Java from Microsoft.

Once the command lands on our backend we use the Google “Dialogflow client library” for intent detection as shown below.

import com.google.cloud.dialogflow.v2.DetectIntentRequest;
import com.google.cloud.dialogflow.v2.DetectIntentResponse;
import com.google.cloud.dialogflow.v2.QueryInput;
import com.google.cloud.dialogflow.v2.QueryParameters;
import com.google.cloud.dialogflow.v2.QueryResult;
import com.google.cloud.dialogflow.v2.SessionName;
import com.google.cloud.dialogflow.v2.SessionsClient;
import com.google.cloud.dialogflow.v2.SessionsSettings;
import com.google.cloud.dialogflow.v2.TextInput;


public List detectIntentTexts(String wisUserId, String text, String sessionId)
throws IOException, ApiException {
SessionName session = SessionName.of(dialogFlowProjectId, sessionId);
TextInput.Builder textInput =     TextInput.newBuilder().setText(text).setLanguageCode(languageCode);
QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build();
DetectIntentRequest request =     DetectIntentRequest.newBuilder().setSession(session.toString())
.setQueryInput(queryInput)
.setQueryParams(QueryParameters.newBuilder().setPayload(Struct.newBuilder()
.putFields("teamsUser",
com.google.protobuf.Value.newBuilder().setStringValue(wisUserId).build())
.build()))
.build();
DetectIntentResponse response = dialogFlowClient.detectIntent(request);
QueryResult queryResult = response.getQueryResult();
List responseMessages = queryResult.getFulfillmentMessagesList();
return responseMessages;
}

The intent detection in turn also calls our fulfilment webhook (which was originally written for Google assistant app). So the actual call for ‘Seat booking’ to the internal booking service happens via the Dialogflow fulfilment endpoint.

This is how the final interaction looks like for the end user.

We can also pass additional metadata to the Dialogflow intent detection api like the logged in user’s context (as shown in the example above) or indication that the request is from ‘Teams backend’ if separate handling is required.

Another type of popular query to our teams bot from employees is “Where is ‘John doe’ sitting?”
For a teams application the employee will typically use the standard ‘@’ mention to tag the specific user.

In this case, before we pass the command to Dialog flow we find out the users mentioned. We use a ‘Microsoft Graphs’ API call to find more details about the user and using that map the user to the corresponding WiS internal user.

For any queries do write to us at hello@workinsync.io


                        

Leave a Reply

Your email address will not be published. Required fields are marked *