# Basic CRM Integration Tutorial

{% hint style="info" %}
Without this integration, Saleschat can still be used via its dashboard, but key features like **number leakage protection** and **programmatic agent assignment** will not be available.
{% endhint %}

## Step-by-step guide

We recommend that you provide the following two buttons on your CRM:

1. Login
2. Chat

> **Where should I provide these buttons?**
>
> The Login button can be provided as an action within accounts or integration section
>
> The Chat button should be provided for each lead, within quick actions for the lead (for ex. next to the dialer).

The functionalities for each of these buttons is explained as below.

### 1. Login

Users can use the “Login” button to login to Saleschat which should open a new Saleschat tab.

When the login button is clicked, the following steps should be performed at the client:

1. [Generate a magic link](/api-documentation/user.md#v1-org-orgid-user-userid-magiclink) for the user.
2. Open the generated magic link in a new tab.

{% hint style="info" %}
Users can be created in Saleschat in advance using the [**Create User API.** ](https://apis.saleschat.pro/public/swagger-ui/index.html#/user-controller/createUserAndAddToOrg)

This can be a batch operation via a script and need not be a part of logic within your CRM.

Do make sure that the userId's of users that are created via the API are recorded in your system.
{% endhint %}

{% hint style="warning" %}
Saleschat's dashboard allows ONLY one tab to be active at any given time. If a new tab is opened up all the previous tabs become inactive.
{% endhint %}

### 2. Chat

Users can use the "Chat" button to get access to the Chatroom with the customer. The access to the Chatroom will be granted basis the business logic.&#x20;

> **Where will the User see the Chatroom?**
>
> If the business logic permits and the API operations are successful, the user will automatically see the Chatroom at the top of the list of Chatroom within Saleschat's chat dashboard. The User should not "Login" to Saleschat for each customer.

We recommend the following business logic:

<table><thead><tr><th width="578">Business logic</th><th>API documentation</th></tr></thead><tbody><tr><td>Create a Contact in Saleschat if not created already.</td><td><a href="/pages/YSgKfe3ppsVxf1T30l35#v2-org-orgid-contact">Link</a></td></tr><tr><td>Assign a contact to a user</td><td><a href="/pages/YSgKfe3ppsVxf1T30l35#post-v3-orgs-orgid-contacts-contactid-assign">Link</a></td></tr></tbody></table>

> #### **What if I want to re-assign a contact to a different user?**
>
> To reassign a contact to a different user, call the **Assign API** again with the new user details. The system will automatically update the assignment.

> #### **How will I create a chatroom for a contact?**
>
> A chatroom is automatically created when you call the **Assign API**, if one does not already exist for the contact. No manual creation is required.

> #### **What if I prefer having manager and agent in the same chatroom with the customer?**
>
> While practices on personal Whatsapp app follow these conventions, it is not scalable for the manager and it leads to a state where it is practically impossible for the manager to keep track of all the conversations.
>
> We recommend having only the agent in the chatroom along with the customer. Each manager has access to agent metrics and chats between the agents and the customers.

> #### **How will the customer know which agent is s/he speaking with?**
>
> We annotate the name of the agent with each chat so as to maintain a personal touch between the agent and the customer.

> #### **How will the agent know which customer the agent is speaking with**
>
> The chatroom name is a combination of CRM\_ID, First Name and Last Name of the Contact that is created.&#x20;

{% hint style="info" %}

#### **Explicit Success & Error Notifications:**

Each of the API to create and assign a Contact responds with appropriate error code and error message in case of a failure and we suggest that you display them explicitly when the user is interacting with the Chat button on your CRM.
{% endhint %}

### Basic Database Schema

| Field             | Description                         |
| ----------------- | ----------------------------------- |
| **User table**    |                                     |
| `id` (PK)         | Primary Key of the User table       |
| `crm_user_id`     | CRM-specific user ID                |
| `sc_user_id`      | Saleschat user ID                   |
| `sc_magic_link`   | Magic link for user login           |
| `sc_expiry_ts`    | Expiry timestamp for the magic link |
|                   |                                     |
| **Contact table** |                                     |
| `id` (PK)         | Primary Key of the Contact table    |
| `crm_customer_id` | CRM-specific customer ID            |
| `sc_contact_id`   | Saleschat contact ID                |
|                   |                                     |


---

# 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.saleschat.pro/getting-started/basic-crm-integration-tutorial.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.
