# Quick Start

## Installation

Installing Gramjs is a straight forward process:

```
$ npm i telegram
```

{% hint style="info" %}
&#x20;If you want to use gramjs in a browser please check the advanced installation page.
{% endhint %}

Once you've installed gramjs you'll need an API ID and an API hash (read more in [Authorization](https://painor.gitbook.io/gramjs/getting-started/authorization)). Get them from <https://my.telegram.org/apps>:\
Afterward, you can use the following code to send a message to yourself.

{% tabs %}
{% tab title="JavaScript" %}
{% code title="hello.js" %}

```javascript
const { TelegramClient } = require('telegram')
const { StringSession } = require('telegram/sessions')
const input = require('input') // npm i input

const apiId = 123456
const apiHash = '123456abcdfg'
const stringSession = new StringSession(''); // fill this later with the value from session.save()
(async () => {
    console.log('Loading interactive example...')
    const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5 })
    await client.start({
        phoneNumber: async () => await input.text('number ?'),
        password: async () => await input.text('password?'),
        phoneCode: async () => await input.text('Code ?'),
        onError: (err) => console.log(err),
    });
    console.log('You should now be connected.')
    console.log(client.session.save()) // Save this string to avoid logging in again
    await client.sendMessage('me', { message: 'Hello!' });
})()


```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="hello.ts" %}

```typescript
import { TelegramClient } from 'telegram'
import { StringSession }  from 'telegram/sessions'
import input from 'input'; // npm i input

const apiId = 123456
const apiHash = '123456abcdfg'
const stringSession = new StringSession(''); // fill this later with the value from session.save()
(async () => {
    console.log('Loading interactive example...');
    const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5 });
    await client.start({
        phoneNumber: async () => await input.text('number ?'),
        password: async () => await input.text('password?'),
        phoneCode: async () => await input.text('Code ?'),
        onError: (err) => console.log(err),
    });
    console.log('You should now be connected.');
    console.log(client.session.save()) // Save this string to avoid logging in again
    await client.sendMessage('me', { message: 'Hello!' });
})()

```

{% endcode %}
{% endtab %}
{% endtabs %}

Using session strings is the most reliable way to save your session for now.&#x20;

## Full API

gramjs is still in its early stages but it can access all API methods from telegram using the following

{% tabs %}
{% tab title="JavaScript" %}
{% code title="fullapi.js" %}

```javascript
const {Api} = require("telegram/tl");

const result = await client.invoke(new Api.channels.CheckUsername({
    username: "testing"
}));
console.log("Result is ",result);

```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="fullapi.ts" %}

```typescript
import {Api} from "telegram/tl";

const result = await client.invoke(new Api.channels.CheckUsername({
    username: "testing"
}));
console.log("Result is ",result);

```

{% endcode %}
{% endtab %}
{% endtabs %}

All methods and classes are accessible under Api. for a full list of them check out <https://gram.js.org/>


---

# 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/master.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.
