Skip to content

Instantly share code, notes, and snippets.

@alexunderboots
Forked from SanariSan/readme.md
Created May 24, 2025 04:39
Show Gist options
  • Select an option

  • Save alexunderboots/a5d994d9592f2313ef1bf0e414b65af1 to your computer and use it in GitHub Desktop.

Select an option

Save alexunderboots/a5d994d9592f2313ef1bf0e414b65af1 to your computer and use it in GitHub Desktop.

Revisions

  1. @SanariSan SanariSan revised this gist Mar 15, 2022. No changes.
  2. @SanariSan SanariSan revised this gist Mar 15, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -69,3 +69,5 @@ _Creating qr code from string, piping stdout to curl, sending it as an **image**
    ---

    ##### More types, as well as required/optional fields for each type, could be found [here](https://core.telegram.org/bots/api#available-methods)

    ##### Some examples that might help you - [here](https://gist.github.com/dideler/85de4d64f66c1966788c1b2304b9caf1)
  3. @SanariSan SanariSan revised this gist Mar 15, 2022. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,10 @@
    #### For getting messages in private chat with bot
    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
    - Start conversation with bot
    - Run following curl command `curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"from":{"id":.+?,'`
    - Run following curl command
    ```
    curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"from":{"id":.+?,'
    ```
    or
    - Go to [@getmyid_bot](https://telegram.me/getmyid_bot) and obtain your account id

    @@ -15,7 +18,10 @@ or
    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
    - Invite your bot to desired chat
    - Write message like this `/test @your_bot_tag`
    - Run following curl command `curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"chat":{"id":.+?,'`
    - Run following curl command
    ```
    curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"chat":{"id":.+?,'
    ```
    You will get output like the one below, keep chat id:
    `"chat":{"id":-1001182736542,`

    @@ -31,6 +37,8 @@ $TOKEN=abc:de123
    $CHAT_ID=12345
    ```

    ###### To supress curl output, add `-s` key + `> /dev/null` in the end

    #### Send text messages

    `curl -X POST -H "Content-Type:multipart/form-data" -F chat_id=$CHAT_ID -F `**text**`="message" "https://api.telegram.org/bot$TOKEN`**/sendMessage**`"`
  4. @SanariSan SanariSan revised this gist Mar 15, 2022. No changes.
  5. @SanariSan SanariSan revised this gist Mar 15, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ $CHAT_ID=12345

    ---

    #### Example of piping image from stdout to curl
    #### Example of piping an image from stdout to curl

    _Creating qr code from string, piping stdout to curl, sending it as an **image**_

  6. @SanariSan SanariSan revised this gist Mar 15, 2022. 1 changed file with 32 additions and 15 deletions.
    47 changes: 32 additions & 15 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    ## Here are some examples on how to use Telegram bot api via curl
    ## Here are some examples on how to use Telegram bot api via CURL

    ### Prerequisites

    #### For getting messages in chat with bot
    #### For getting messages in private chat with bot
    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
    - Start conversation with bot
    - Run following curl command `curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"from":{"id":.+?,'`
    @@ -16,31 +16,48 @@ or
    - Invite your bot to desired chat
    - Write message like this `/test @your_bot_tag`
    - Run following curl command `curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"chat":{"id":.+?,'`
    You will get output like one below, so keep this chat id:
    You will get output like the one below, keep chat id:
    `"chat":{"id":-1001182736542,`

    ---

    ### Now you can send messages either to yourself in the chat with bot or to the group chat
    _Environment variables used, feel free to replace with bare text_
    ### Sending messages either to yourself in the chat with bot or to the group chat
    _Environment variables used in examples_

    ```
    # bot token
    $TOKEN=abc:de123
    # your acc or group chat id
    $CHAT_ID=12345
    ```

    #### Send text messages

    `curl -X POST -H "Content-Type:multipart/form-data" -F chat_id=$CHAT_ID -F `**text**`="message" "https://api.telegram.org/bot$TOKEN`**/sendMessage**`"`

    ---

    #### Send document from disk
    `
    curl -X POST -H "Content-Type:multipart/form-data" -F `**document**`=@"path/to/some.file" "https://api.telegram.org/bot$TOKEN`**/sendDocument**`?chat_id=$CHAT_ID"
    `

    For sending other file types, replace `/sendDocument` and `document` with the following:
    `curl -X POST -H "Content-Type:multipart/form-data" -F `**document**`=@"path/to/some.file" "https://api.telegram.org/bot$TOKEN`**/sendDocument**`"`

    ---

    #### Example of piping image from stdout to curl

    _Creating qr code from string, piping stdout to curl, sending it as an **image**_

    `qrencode -s 6 -o - "Some text to encode" | curl -X POST -H "Content-Type:multipart/form-data" -F chat_id=$CHAT_ID -F `**photo**`=@- "https://api.telegram.org/bot$TOKEN/`**sendPhoto**`"`

    ##### For sending other entity types, replace `/sendPhoto` and `photo` with the following:

    `/sendAudio` `audio`
    `/sendPhoto` `photo`
    `/sendVideo` `video`
    `/sendAnimation` `animation`
    `/sendVoice` `voice`
    `/sendVideoNote` `video_note`

    ---

    Create qr code from string, pipe stdout to curl, send it as an **image**
    ```
    qrencode -s 6 -o - "Some text to encode" | curl -X POST -H "Content-Type:multipart/form-data" -F photo=@- "https://api.telegram.org/bot$TOKEN/sendPhoto?chat_id=$CHAT_ID"
    ```

    More message types could be found [here](https://core.telegram.org/bots/api#sendphoto)
    ##### More types, as well as required/optional fields for each type, could be found [here](https://core.telegram.org/bots/api#available-methods)
  7. @SanariSan SanariSan revised this gist Mar 15, 2022. 1 changed file with 33 additions and 8 deletions.
    41 changes: 33 additions & 8 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,44 @@
    Here are some examples on how to use Telegram bot api via curl
    ## Here are some examples on how to use Telegram bot api via curl

    _Environment variables used, feel free to replace with bare text_
    ### Prerequisites

    #### For getting messages in chat with bot
    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
    - Start conversation with bot
    - Run following curl command `curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"from":{"id":.+?,'`
    or
    - Go to [@getmyid_bot](https://telegram.me/getmyid_bot) and obtain your account id

    Now you can send messages to yourself in a chat with bot:
    ---

    #### For getting messages in public/private chat where bot invited
    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
    - Invite your bot to desired chat
    - Write message like this `/test @your_bot_tag`
    - Run following curl command `curl https://api.telegram.org/bot<TO:KEN>/getUpdates | grep -Po '"chat":{"id":.+?,'`
    You will get output like one below, so keep this chat id:
    `"chat":{"id":-1001182736542,`

    ---

    ### Now you can send messages either to yourself in the chat with bot or to the group chat
    _Environment variables used, feel free to replace with bare text_

    #### Send document from disk
    `
    curl -X POST -H "Content-Type:multipart/form-data" -F `**document**`=@"path/to/some.file" "https://api.telegram.org/bot$TOKEN`**/sendDocument**`?chat_id=$CHAT_ID"
    `

    For sending other file types, replace `/sendDocument` and `document` with the following:
    `/sendAudio` `audio`
    `/sendPhoto` `photo`
    `/sendVideo` `video`
    `/sendAnimation` `animation`
    `/sendVoice` `voice`
    `/sendVideoNote` `video_note`

    Send document from disk
    ```
    curl -X POST -H "Content-Type:multipart/form-data" -F document=@"path/to/some.file" "https://api.telegram.org/bot$TOKEN/sendDocument?chat_id=$CHAT_ID"
    ```

    Create qr code from string, pipe stdout to curl, send it as an image
    Create qr code from string, pipe stdout to curl, send it as an **image**
    ```
    qrencode -s 6 -o - "Some text to encode" | curl -X POST -H "Content-Type:multipart/form-data" -F photo=@- "https://api.telegram.org/bot$TOKEN/sendPhoto?chat_id=$CHAT_ID"
    ```
  8. @SanariSan SanariSan revised this gist Mar 15, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Here are some examples on how to use Telegram bot api via curl

    _Environment variables used, feel free to replace with bare text_

    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
  9. @SanariSan SanariSan renamed this gist Mar 15, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @SanariSan SanariSan created this gist Mar 15, 2022.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    Here are some examples on how to use Telegram bot api via curl
    _Environment variables used, feel free to replace with bare text_

    - Create a bot using [@BotFather](https://telegram.me/BotFather), get it's token
    - Start conversation with bot
    - Go to [@getmyid_bot](https://telegram.me/getmyid_bot) and obtain your account id

    Now you can send messages to yourself in a chat with bot:

    Send document from disk
    ```
    curl -X POST -H "Content-Type:multipart/form-data" -F document=@"path/to/some.file" "https://api.telegram.org/bot$TOKEN/sendDocument?chat_id=$CHAT_ID"
    ```

    Create qr code from string, pipe stdout to curl, send it as an image
    ```
    qrencode -s 6 -o - "Some text to encode" | curl -X POST -H "Content-Type:multipart/form-data" -F photo=@- "https://api.telegram.org/bot$TOKEN/sendPhoto?chat_id=$CHAT_ID"
    ```

    More message types could be found [here](https://core.telegram.org/bots/api#sendphoto)