---
# System prepended metadata

title: API Documentation for CRM Integration

---


# API Documentation for CRM Integration

## General Information
- **Authentication**: All requests require Bearer Token authentication.
- **Error Response Format**: 
```json
{
    "status": "fail",
    "error": "Error description here"
}
```

---

## Endpoint: `/message_from_chat` (POST)
### Description
This endpoint allows the backend of the CRM system to send a notification to the bot backend about a new message in a chat.

### Payload
- `channel` (str): The channel. Currently, only "telegram" is supported.
- `message_type` (str): Type of the message (`text`, `sticker`, `voice`, `media`). Currently, only "text" is processed.
- `message_id` (str): ID of the message.
- `message_metadata` (dict): Metadata for non-text messages.
- `chat_type` (str): Type of the chat.
- `from_chat_id` (str): ID of the chat where the message is coming from.
- `from_user` (dict): Information about the user who sent the message.
    - `user_id` (str): User ID.
    - `username` (str, optional): Username.
    - `user_first_name` (str): User's first name.
    - `user_last_name` (str): User's last name.
    - `metadata` (dict): Additional metadata.
- `conversation_history` (list[Message]): Conversation history.
- `timestamp` (float): Timestamp of the message.
- `text` (str): Text of the message.

---

## Endpoint: `/send_to_chat` (POST)
### Description
This endpoint allows sending a message to a chat.

### Payload
- `channel` (str): The channel. Currently, only "telegram" is supported.
- `message_type` (str): Type of the message (`text`, `sticker`, `voice`, `media`). Currently, only "text" is processed.
- `message_metadata` (dict): Metadata for non-text messages.
- `to_chat_id` (str): ID of the chat to send the message to. If `to_chat_id` is equal to `to_user_id`, the message will be sent to DM.
- `to_user_id` (str): ID of the user to send the message to.
- `text` (str): Text of the message.
- `reply_to_message_id` (str): ID of the message to reply to.
- `from_user_id` (str): ID of the sender. It can be the ID of the bot or a regular Telegram account.

### Response
```json
{
    "status": "ok",
    "message_id": "Message ID from Telegram server",
    "timestamp": "Timestamp"
}
```

---

## Endpoint: `/get_contact` (GET)
### Description
This endpoint retrieves a client's contact card.

---

## Endpoint: `/update_contact_field` (POST)
### Description
This endpoint updates a field/tag/status in a client's contact card.

### Payload
- `field_name` (str): Name of the field to update.
- `field_value` (str): New value for the field.

---

## Endpoint: `/get_rates` (GET)
### Description
This endpoint retrieves exchange rates.

### Parameters
- `from_currency` (str): Source currency.
- `to_currency` (str): Target currency.
- `from_amount` (str or null): Amount in the source currency (to avoid float rounding).
- `to_amount` (str or null): Amount in the target currency (for reverse exchanges).

### Response
```json
{
    "from_currency": "Source currency",
    "to_currency": "Target currency",
    "from_amount": "Amount in source currency",
    "to_amount": "Amount in target currency"
    "valid_until": ... (float)
}
```

---

## Endpoint: `/get_discount` (GET)
### Description
This endpoint retrieves available discounts.

### Parameters
- `from_currency` (str): Source currency.
- `to_currency` (str): Target currency.
- `from_amount` (str): Amount in the source currency.
- `to_amount` (str): Amount in the target currency.
- `contact_id` (str): ID of the contact to retrieve discounts for.


### Response
```json
{
    "discount": "0.005",  # 5%
    "from_currency": ...,
    "to_currency": ...,
    "from_amount": ...,
    "to_amount": ...,
    "valid_until": ... (float)
}
```