Skip to main content

Disconnect

Closes the Telegram bot connection and cleans up resources. This node should be used at the end of your flow to properly terminate the bot 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.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Input

  • Client Id - The unique identifier for the bot client connection obtained from the Connect node.

Output

  • n/a - No output

How It Works

The Disconnect node terminates the Telegram bot connection and releases associated resources. When executed, the node:

  1. Retrieves the Client Id from the input
  2. Validates that the Client Id exists and corresponds to an active connection
  3. Stops any running pollers (for bots listening to messages)
  4. Closes the bot client instance
  5. Removes the connection from the connection pool
  6. Frees up system resources

Requirements

  • A valid Client Id from an active Connect node
  • The connection must not have already been closed

Error Handling

The node will return errors in the following cases:

  • Empty or invalid Client Id
  • Client Id that doesn't correspond to an existing connection
  • Connection that has already been closed

Usage Example

Complete Bot Flow:

Connect → Send Message → Send Photo → Disconnect

Error Handling with Disconnect:

Try {
Connect → Send Message → Disconnect
}
Catch {
Log Error → Disconnect
}
Finally {
Disconnect
}

Best Practices

  • Always disconnect - Place a Disconnect node at the end of every Telegram flow
  • Use Finally blocks - Put Disconnect in a Finally node to ensure cleanup even if errors occur
  • One disconnect per connection - Each Connect node should have a corresponding Disconnect
  • Check Client Id - Ensure the Client Id is properly passed from the Connect node
  • Handle errors gracefully - Even if Disconnect fails, the connection will eventually timeout

Common Patterns

Single Message Flow:

Connect → Get Bot Info → Send Message → Disconnect

File Processing Flow:

Connect → Receive Message → Download File → Process File → Send Document → Disconnect

Notification Broadcast:

Connect
→ Send Message (to Chat 1)
→ Send Message (to Chat 2)
→ Send Message (to Chat 3)
→ Disconnect

Resource Management

The Disconnect node is important for:

  • Memory management - Frees memory used by the bot client
  • Connection limits - Telegram has limits on concurrent connections
  • Clean shutdown - Ensures all pending operations complete before closing
  • Poller cleanup - Stops message listeners to prevent memory leaks

Troubleshooting

Connection Already Closed:

  • Ensure you're not calling Disconnect twice on the same Client Id
  • Check that the Client Id hasn't been modified between Connect and Disconnect

Client Id Not Found:

  • Verify the Client Id is being properly passed from the Connect node
  • Check that the Connect node executed successfully
  • Ensure the Client Id variable name matches between nodes

Resource Leaks:

  • If you forget to disconnect, connections may remain open
  • This can lead to memory issues in long-running flows
  • Use the Finally node pattern to guarantee cleanup

Tips

  • Always pair each Connect with a Disconnect
  • Use error handling to ensure Disconnect runs even if the flow fails
  • The Disconnect node is idempotent - calling it multiple times on an already closed connection won't cause issues (though it will log a warning)
  • For flows using Receive Message (which runs continuously), Disconnect will be called automatically when the flow stops