-
-
Save alexunderboots/a5d994d9592f2313ef1bf0e414b65af1 to your computer and use it in GitHub Desktop.
Revisions
-
SanariSan revised this gist
Mar 15, 2022 . No changes.There are no files selected for viewing
-
SanariSan revised this gist
Mar 15, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) -
SanariSan revised this gist
Mar 15, 2022 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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":.+?,' ``` 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":.+?,' ``` 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**`"` -
SanariSan revised this gist
Mar 15, 2022 . No changes.There are no files selected for viewing
-
SanariSan revised this gist
Mar 15, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ $CHAT_ID=12345 --- #### Example of piping an image from stdout to curl _Creating qr code from string, piping stdout to curl, sending it as an **image**_ -
SanariSan revised this gist
Mar 15, 2022 . 1 changed file with 32 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ### Prerequisites #### 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 the one below, keep chat id: `"chat":{"id":-1001182736542,` --- ### 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**`"` --- #### 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` --- ##### More types, as well as required/optional fields for each type, could be found [here](https://core.telegram.org/bots/api#available-methods) -
SanariSan revised this gist
Mar 15, 2022 . 1 changed file with 33 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ### 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 --- #### 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` 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" ``` -
SanariSan revised this gist
Mar 15, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
SanariSan renamed this gist
Mar 15, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
SanariSan created this gist
Mar 15, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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)