About Integrating with Multiple Microsoft Teams Tenants

Ohki_Yamamoto
Tera Guru

ServiceNow for Microsoft Teams is used to build ServiceNow and Microsoft Teams integration.

 

OOTB recognizes that ServiceNow instances and Teams tenants can be integrated in a 1:1 relationship.

Is there a way to integrate one instance of ServiceNow with multiple Teams tenants?


*The method for integrating multiple ServiceNow instances and a single Microsoft Teams tenant was written in the following Docs.

https://www.servicenow.com/docs/ja-JP/bundle/washingtondc-servicenow-platform/page/administer/virtua... single-teams.html

 

1 REPLY 1

Murtaza Saify
Tera Contributor

1. Understand the Limitations

  • OOTB Limitation: The out-of-the-box integration is designed for a single Teams tenant per ServiceNow instance.

  • Custom Solution: To support multiple tenants, you’ll need to extend the OOTB functionality using custom scripts, APIs, and configurations.


2. Custom Integration Approach

To integrate one ServiceNow instance with multiple Teams tenants, follow these steps:

a. Set Up Multiple Microsoft Teams Apps

  1. Register Multiple Apps in Azure AD:

    • For each Teams tenant, register a separate app in the respective Azure Active Directory (Azure AD).

    • Obtain the Client ID, Client Secret, and Tenant ID for each app.

  2. Configure OAuth for Each Tenant:

    • Set up OAuth 2.0 authentication for each Teams tenant in ServiceNow.

    • Navigate to System OAuth > Application Registry and create a new OAuth profile for each tenant.

b. Create a Multi-Tenant Middleware

  1. Develop a Custom Script Include:

    • Create a Script Include in ServiceNow to handle interactions with multiple Teams tenants.

    • Use the Microsoft Graph API to send/receive data from Teams.

    Example:

    javascript
    Copy
    var TeamsIntegration = Class.create();
    TeamsIntegration.prototype = {
        initialize: function(tenantId, clientId, clientSecret) {
            this.tenantId = tenantId;
            this.clientId = clientId;
            this.clientSecret = clientSecret;
        },
    
        sendMessageToTeams: function(channelId, message) {
            var token = this._getAccessToken();
            var request = new sn_ws.RESTMessageV2();
            request.setEndpoint("https://graph.microsoft.com/v1.0/teams/" + channelId + "/messages");
            request.setHttpMethod("POST");
            request.setRequestHeader("Authorization", "Bearer " + token);
            request.setRequestHeader("Content-Type", "application/json");
            request.setRequestBody(JSON.stringify({ body: { content: message } }));
            var response = request.execute();
            return response.getBody();
        },
    
        _getAccessToken: function() {
            var request = new sn_ws.RESTMessageV2();
            request.setEndpoint("https://login.microsoftonline.com/" + this.tenantId + "/oauth2/v2.0/token");
            request.setHttpMethod("POST");
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.setRequestBody("grant_type=client_credentials&client_id=" + this.clientId + "&client_secret=" + this.clientSecret + "&scope=https://graph.microsoft.com/.default");
            var response = request.execute();
            var responseBody = JSON.parse(response.getBody());
            return responseBody.access_token;
        },
    
        type: 'TeamsIntegration'
    };
  2. Store Tenant-Specific Configuration:

    • Use a Custom Table to store tenant-specific details (e.g., Tenant ID, Client ID, Client Secret).

    • Retrieve these details dynamically in your Script Include.

c. Modify the ServiceNow for Microsoft Teams App

  1. Customize the OOTB App:

    • Clone and modify the OOTB ServiceNow for Microsoft Teams app to support multiple tenants.

    • Update the app’s logic to determine which tenant to interact with based on the context (e.g., user, group, or channel).

  2. Add Tenant Selection Logic:

    • Add a UI element (e.g., dropdown) in the Teams app to allow users to select their tenant.

    • Pass the selected tenant information to ServiceNow for processing.

d. Use Microsoft Graph API for Multi-Tenant Communication

  • Leverage the Microsoft Graph API to interact with multiple Teams tenants.

  • Use the access tokens obtained from each tenant’s Azure AD app to send/receive data.


3. Test the Integration

  • Test the integration with each Teams tenant to ensure messages, notifications, and other functionalities work as expected.

  • Use Debug Logs in ServiceNow to troubleshoot issues.


4. Key Considerations

  • Security: Ensure secure storage and handling of OAuth credentials for each tenant.

  • Scalability: Design the solution to handle a growing number of tenants.

  • Maintenance: Regularly update the integration to accommodate changes in the Microsoft Graph API or ServiceNow APIs.


5. Alternative Approach: Use a Third-Party Middleware

If building a custom solution is not feasible, consider using a third-party middleware (e.g., Azure Logic Apps, MuleSoft) to manage the integration between ServiceNow and multiple Teams tenants.