Disconnect
Disconnects from Microsoft Teams and releases the connection session.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- Client Id - The client ID returned by the Connect node that you want to disconnect.
Output
- n/a - No output
How It Works
The Disconnect node:
- Removes the connection from the active sessions pool
- Releases any resources associated with the connection
- Prevents further use of the client ID
After disconnecting, the client ID cannot be used for any Teams operations. You must create a new connection using the Connect node.
Examples
Basic Disconnect
Clean up after completing Teams operations:
// Use Connect to get client_id
client_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
// Perform Teams operations
// ... send messages, create channels, etc.
// Disconnect when done
// Use Disconnect node with client_id
Disconnect in Error Handling
Ensure connection is closed even if errors occur:
// Try block
try {
// Connect
client_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
// Perform Teams operations
// ... operations ...
// Disconnect on success
// Disconnect node
} catch (error) {
// Also disconnect on error
// Disconnect node
throw error
}
Flow Pattern
Recommended flow structure:
[Connect] --> [Teams Operations] --> [Disconnect]
| | |
v v v
client_id use client_id cleanup
Tips for Effective Use
- Always disconnect: Make it a habit to disconnect when operations are complete to free resources
- Use Finally blocks: Place Disconnect in Finally blocks to ensure cleanup even after errors
- One disconnect per connection: Each Connect requires exactly one Disconnect
- Flow organization: Keep Connect and Disconnect nodes visible in your flow for clarity
- Resource management: Disconnecting prevents accumulation of unused connections
Common Errors and Solutions
"Client Id cannot be empty"
Cause: No client ID was provided to the Disconnect node.
Solution: Ensure you pass the client ID from the Connect node:
// Store client_id from Connect
client_id = message.client_id
// Use it in Disconnect
// Input: client_id
"Client Id not found"
Cause: The client ID doesn't exist in the active sessions or was already disconnected.
Solution:
- Verify the client ID is correct
- Ensure Connect was successful
- Check that you haven't already called Disconnect for this client ID
- Make sure the client ID hasn't been modified
Connection Already Closed
Cause: Attempting to disconnect a client ID that was already disconnected.
Solution:
- Use a flag variable to track connection state
- Only disconnect once per connection
- Check if client_id exists before disconnecting
Best Practices
- Cleanup pattern: Always pair Connect with Disconnect in your flows
- Error handling: Use Try-Catch-Finally to ensure Disconnect runs even on errors
- Clear flows: Keep Connect at the top and Disconnect at the bottom of your flow
- Resource awareness: Disconnect promptly when operations complete
- Single responsibility: One Disconnect per connection, no reuse after disconnect
- State tracking: Use variables to track whether connection is active
- Documentation: Comment flows to indicate connection lifecycle
Example: Complete Connection Lifecycle
┌─────────────────────────────────────────────┐
│ 1. Connect │
│ Output: client_id │
└──────────────┬──────────────────────────────┘
│
v
┌─────────────────────────────────────────────┐
│ 2. Try Block │
│ - ListTeams (use client_id) │
│ - SendMessage (use client_id) │
│ - GetMessages (use client_id) │
└──────────────┬──────────────────────────────┘
│
v
┌─────────────────────────────────────────────┐
│ 3. Finally Block │
│ - Disconnect (input: client_id) │
└─────────────────────────────────────────────┘
This pattern ensures proper resource management and connection cleanup in all scenarios.