# Telnet Javascript API

## Connector functions Telnet JS API guide

This API allows users to execute operations in the Telnet connector from a connector function.

## Telnet Object

The Telnet object is the main object of the Telnet connector. It allows to connect
to a Telnet server, send commands and receive responses, and disconnect from the
Telnet server.

### Telnet Object Properties

| Property | Type   | Default | Description                      |
|----------|--------|---------|----------------------------------|
| ip       | string |         | IP address of the Telnet server. |
| port     | number | 23      | Port of the Telnet server.       |
| retries  | number | 3       | Number of retries.               |
| timeout  | number | 5000    | Timeout in milliseconds.         |

### Telnet Object Methods

#### telnet.connect (waitFor)

Connects to the Telnet server using the properties of the Telnet object and the specified parameters.

| Parameter | Type   | Description                         |
|-----------|--------|-------------------------------------|
| waitFor   | string | String to wait for in the response. |

* `ip`: IP address of the Telnet server.
* `port`: Port of the Telnet server.
* `retries`: Number of retries.
* `timeout`: Timeout in milliseconds.

Returns an object with the following properties:

* `result`: `true` if the connection was successful, `false` otherwise.
* `message`: Empty if the connection was successful, error message otherwise.

Example of use:

```javascript
telnet.ip = "[IP_ADDRESS]";
telnet.port = 23;

var connectResult = telnet.connect(">");

if (connectResult.result) {
    // Connection was successful
} else {
    // Connection failed
}
```

#### telnet.send (command, pattern, waitFor)

Sends a command to the Telnet server and waits for the response with the specified parameters:

| Parameter | Type   | Description                                                               |
|-----------|--------|---------------------------------------------------------------------------|
| command   | string | Command to send to the Telnet server.                                     |
| pattern   | string | String to pattern match in the response. In RegExp format.                |
| waitFor   | string | String to wait for in the response. If not specified, the default is `>`. |

* `retries`: Number of retries.
* `timeout`: Timeout in milliseconds.

Returns the response of the Telnet server in an array of strings.

Example of use:

```javascript
var sendResult = telnet.send("ls -la", "*", ">");
```

#### telnet.disconnect ()

Disconnects from the Telnet server.

Example of use:

```javascript
telnet.disconnect();
```
