Auto Import functionality in ServiceNow for Microsoft Teams.<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #7057C7; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: block; max-width: ; width: auto; height: auto; } } Introduction: Configure request-based chats for IT Service Management integration with Microsoft Teams and HR Service Delivery integration with Microsoft Teams applications to enable the system to auto-import the Microsoft Teams chat conversations between the agents and the employees. A default chat configuration is shipped OOTB to automatically import the Microsoft Teams chats between the agents and the requesters. The System Administrator can extend the auto-import feature to the other tables as required for certain conditions. Setup Auto-import functionality: The tables below capture the configuration required to drive the Microsoft Teams Auto Import chats feature. Requester Mapping (sn_tcm_collab_hook_chat_requester_mapping): Contains Requestor mapping of a table.Each record is a mapping between a table and a sys_user reference field name.This configuration is used to identify if a requestor is part of the Microsoft Teams chat.An interaction is created only if the requester mapping is present for a table and the Requester is part of the chat. Close Conditions (sn_tcm_collab_hook_chat_closing_condition): Contains close conditions of a table.These configurations are used to identify if the source record is closed.If a source record has matching conditions, we will mark the Microsoft Teams chat as closed. Chat Configuration (sn_tcm_collab_hook_chat_config): It contains configurations to specify if a chat should be auto/manually imported and an opening message to be sent in teams.If a condition is specified on a table and a chat is started on that record that matches these conditions, The respective message and auto/manual import configuration will be applied to that chat record. Usage of Auto-import Chat: An Agent can start a chat from a record by clicking the "Start Microsoft Teams Chat" UI action (Visible only if the Microsoft Teams Integration is installed & setup) and you will see a message "Chats will be imported using the auto-import feature" in the pop-up window. A Work Note will be added to the incident stating that the chats will be auto-imported by the system: All Microsoft Teams Chats will be saved in the "sn_tcm_collab_hook_ms_teams_chat" table. All the chat messages from Microsoft Teams will be auto-imported to the ServiceNow instance at an interval of 30 minutes. The system looks for all the new messages across all the chats and imports the messages to the ServiceNow instance. To prevent polling from running indefinitely on inactive conversations, if there are no new messages, the polling interval will gradually lengthen, and eventually, polling stops. The system verifies the Microsoft Teams chat for new messages every 30 minutes. If there are no new messages, the system checks for the new messages at intervals of one hour, two hours, four hours, and eight hours. If there are no new messages in an interval of eight hours for seven days, the Auto Import polling activity is disabled, the auto-import flag will be retained as true when 7 days limit is breached after which when the task gets closed, we will try to pull the chat transcripts one last time and make chat record inactive, since the associated task is resolved/closed (made inactive or matches Close Conditions). If there is any message during any interval, the auto-import timer will look for the new messages in the next interval and import the messages. The timer is then reset to 30-minute intervals and the polling loop kicks in from the start like mentioned above. Polling Approach in Detail: The polling of the new messages from a Microsoft Teams chat happens using subflows, and the reason to go with subflows is The processing time is predictable. A chat will be imported approximately at the time scheduled. The processing time to process the substantial number of chats should also be manageable according to our testing. 1. Approach: When a new Microsoft Teams chat is created from the ServiceNow instance, and auto import is enabled, A business rule will get triggered, which will execute a subflow "Auto Import Messages Subflow" with a timer set to start in 30 minutes from creating the chat record. The subflow will try to perform the "Get MS Teams Messages" action and update the chat in the ServiceNow instance. If we hit the 429 throttling (Too many requests to MSFT) when a subflow is executing, we will wait 3 minutes before we start reissuing rest calls and store these details in a table that tells us if throttling has occurred. When we execute later subflows, we will check this table first, and if we have the throttled flag set to true, we will reschedule the subflows to wait for 3 more minutes before executing. 2. Backoff policy: A backoff policy has been setup to reduce the number of calls made from the ServiceNow Instance to Microsoft Graph API to get the chat messages, thereby reducing the new subflow creation.When a chat is created from the ServiceNow instance, A subflow is created to pull data from the Microsoft Teams chat in the next 30 minutes.If there are no chats, we try for 1 hour, 2 hours, 4 hours, and 8 hours.Once we hit the 8-hour limit, The system will try again after the next 8 hours, and we do this for 7 days (Polling happens 21 times (7 days * 3 [8-hour slots in a day] in the worst case scenario).If no messages are polled within these 7 days, The chats are marked with auto-import as false, and messages will no longer be auto-imported.If new messages are available while polling at any point within the 7 days when a subflow is executed, The counter will be reset, restart the backoff policy from 30 minutes again, and the seven-day timer will also be reset. 3. Ceiling Logic: A default ceiling limit of 500 max chats to be tried in the first 30 minutes and a total limit of 10,000 chats at a given time.If the chats with subflows are higher than the ceiling limit, The new Microsoft Teams chat will be created with auto import false and the agent will be informed on the Start Chat Modal about hitting ceil limits.This will continue until the chats with subflow count are below the ceiling limit.The ceiling limit is controlled by a system property and can be modified beyond 500 if desired: sn_tcm_collab_hook.teams_auto_import_chat_cycle_ceil_limitIt also checks the sn_tcm_collab_hook_ms_teams_chat table for any active records with auto-import enabled & a next_action field set in the future. This is NOT additive and is just another condition checked for the ceiling limit. This should match the number of active subflows, but it is another condition that it checks for before creating a chat with auto-import enabled. 4. Records Archiving: An archival rule is shipped on the Microsoft Teams Chat Table (sn_tcm_collab_hook_ms_teams_chat) with a default time of 6 months, followed by a purge in 3 months. 5. Scenarios: Auto-import when the parent record is reassigned: If a record is reassigned when the auto-import subflow is running... The "Initiated By" field on the Microsoft Teams Chat record[s] linked with this parent record will be updated with the reassigned user.When the polling happens after reassignment, the user token of the reassigned user will be used to get new chat messages.The reassigned user (if valid user in teams) will be added to all the chats linked to the parent record.If the user who has reassigned the record is not a valid Microsoft Teams user (email is not valid or empty) or does not have a valid Microsoft Teams Token available, A message will be added to the work notes of the parent record about the same, and the auto import subflow will be canceled.If the reassigned user is not a valid Microsoft Teams user, The system uses the "Chat Started By" user (user who has started the chat in the first place) token to auto-import the messages. If the "Chat Started By" user token is also invalid, the auto-import stops and a message will be posted in the work notes.Once Auto Import is stopped. There is no way to restart it. Auto-import when the parent record is closed: If the close conditions match the parent record conditions The system tries to pull the latest messages (if present) one last time and tries to close the chat with the "Initiated By" user token if valid or the "Chat Started By" user token. While pulling the messages, it follows the same mechanism as above checking for tokens and posting messages if necessary.All the members in the Microsoft Teams chat are removed essentially making it read-only and no one can post the messages.The Microsoft Teams Chat record is marked with an active field and the auto import field as false makes the chat record read-only.A message will be added in the parent record about the removal of chat members and about the closure of the chat.If there are any active auto-import subflows running, they will be marked as canceled.Once a chat is marked as Active=False or Auto Import=False, there is no way to make it active again or restart it.