# Javascript

### Robin for Messaging with Javascript

Add live messaging to your Javascript applications with the Core Javascript SDK. Take advantage of the Robin API and deploy messaging solutions in very little time.

{% embed url="<https://github.com/robin-io/robin.io-js>" %}

### Prerequisites

For this integration, you would need an API Key - Learn about how to get your API Keys in [Setting up your Robin account](/messaging-with-robin/guides/setting-up-your-robin-account.md)

### Install the Javascript SDK

{% tabs %}
{% tab title="NPM" %}

```bash
npm install robin.io-js --save
```

{% endtab %}

{% tab title="Yarn" %}

```bash
yarn add robin.io-js
```

{% endtab %}
{% endtabs %}

## Sending your first message

Follow the step-by-step instructions below to send your first message using the Javascript SDK

### Step 1: Create a Robin Instance

To create a `Robin` instance, pass the `apiKey` as the first argument, and the optional `tls` argument as the second in the `Robin(apiKey, tls)` constructor.

```jsx
const robin = new Robin('YOUR_API_KEY', true);
```

{% hint style="warning" %}
Initializing the Chat SDK at the top of your Javascript file is recommended.
{% endhint %}

### Step 2: Connect to Robin Server

You can connect to the Robin server using the `connect(user_token)` method from the `Robin` instance. If you do not have a [Robin User Token](/messaging-with-robin/guides/what-is-the-robin-user-token-rut.md) (user\_token), you would have to create one. [What is the Robin User Token (RUT)?](/messaging-with-robin/guides/what-is-the-robin-user-token-rut.md)(specific link to create user token) is a good place to start.

```jsx
robin.connect('YOUR_RUT');
```

{% hint style="info" %}
All messages sent on Robin go through channels, you can learn more about channels on [Robin Fundamentals](/fundamentals.md)
{% endhint %}

### Step 3: Create a Conversation

Before sending a message, you need to create a `Conversation`

```jsx
const response = await robin.createConversation({
  sender_name: string,
  sender_token: string,
  receiver_token: string,
  receiver_name: string
})
```

### Step 4: Send a message to Conversation

Now, you can send a message to a conversation with the `robin.sendMessageToConversation()` method.

```jsx
robin.sendMessageToConversation(msg: object, conn: WebSocket, channel:string,conversation_id: string, senderToken?: string);
```

### Browser Compatibility

This SDK is supported on the following browser versions.

| Browser           | Supported Versions     |
| ----------------- | ---------------------- |
| Internet Explorer | 10 or higher           |
| Edge              | 13 or higher           |
| Chrome            | 16 or higher           |
| Firefox           | 11 or higher           |
| Safari            | 7 or higher            |
| Opera             | 12.1 or higher         |
| iOS Safari        | 7 or higher            |
| Android Browser   | 4.4 (Kitkat) or higher |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.robinapp.co/messaging-with-robin/add-messaging-with-core-sdks/javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
