# messages.sendEncryptedFile

Sends a message with a file attachment to a secret chat

## Example

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

```javascript
const {Api, TelegramClient} = require('telegram');
const {StringSession} = require('telegram/sessions');

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result = await client.invoke(new Api.messages.sendEncryptedFile({
        silent: true,
        peer: new Api.InputEncryptedChat({...}),
        randomId: 5730016,
        data: Buffer.from('some bytes here'),
        file: new Api.InputEncryptedFile({...}),
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import {Api, TelegramClient} from 'telegram';
import {StringSession} from 'telegram/sessions';

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result: Api.messages.SentEncryptedMessage = await client.invoke(new Api.messages.sendEncryptedFile({
        silent: true,
        peer: new Api.InputEncryptedChat({...}),
        randomId: 5730016,
        data: Buffer.from('some bytes here'),
        file: new Api.InputEncryptedFile({...}),
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}
{% endtabs %}

## TL schema

```
messages.sentEncryptedMessage#560f8935 date:int = messages.SentEncryptedMessage;
messages.sentEncryptedFile#9493ff32 date:int file:EncryptedFile = messages.SentEncryptedMessage;
---functions---
messages.sendEncryptedFile#5559481d flags:# silent:flags.0?true peer:InputEncryptedChat random_id:long data:bytes file:InputEncryptedFile = messages.SentEncryptedMessage;
```

## Parameters

|      Name      | Type                                                                                                                              | Description                                                                                                                                             |
| :------------: | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|    **flags**   | [#](https://core.telegram.org/type/%23)                                                                                           | Flags, see [TL conditional fields](https://core.telegram.org/mtproto/TL-combinators#conditional-fields)                                                 |
|   **silent**   | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields).0?[true](https://core.telegram.org/constructor/true) | Whether to send the file without triggering a notification                                                                                              |
|    **peer**    | [InputEncryptedChat](https://core.telegram.org/type/InputEncryptedChat)                                                           | Secret chat ID                                                                                                                                          |
| **random\_id** | [long](https://core.telegram.org/type/long)                                                                                       | Unique client message ID necessary to prevent message resending                                                                                         |
|    **data**    | [bytes](https://core.telegram.org/type/bytes)                                                                                     | TL-serialization of [DecryptedMessage](https://core.telegram.org/type/DecryptedMessage) type, encrypted with a key generated during chat initialization |
|    **file**    | [InputEncryptedFile](https://core.telegram.org/type/InputEncryptedFile)                                                           | File attachment for the secret chat                                                                                                                     |

## Result

[messages.SentEncryptedMessage](https://core.telegram.org/type/messages.SentEncryptedMessage)

## Possible errors

| Code | Type                   | Description                      |
| :--: | ---------------------- | -------------------------------- |
|  400 | DATA\_TOO\_LONG        | Data too long                    |
|  400 | ENCRYPTION\_DECLINED   | The secret chat was declined     |
|  400 | MD5\_CHECKSUM\_INVALID | The MD5 checksums do not match   |
|  400 | MSG\_WAIT\_FAILED      | A waiting call returned an error |

## Can bots use this methd ?

### yes

## Related pages

### [DecryptedMessage](https://core.telegram.org/type/DecryptedMessage)

Object describes the contents of an encrypted message.


---

# 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://painor.gitbook.io/gramjs/working-with-secret-chats/messages.sendencryptedfile.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.
