Skip to content

A simple bash wrapper around curl to send messages to Telegram chats

Notifications You must be signed in to change notification settings

alex-bochkarev/tgs-curl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tgs-curl – a simple wrapper around cURL for dead-simple telegram bots

So, these are convenience scripts: a tiny wrapper around a standard cURL program (chances are, you have it already installed on your system, if happens to be certain sorts of GNU/Linux or MacOS – but no specific testing was done). The purpose is to be able to send quick messages to yourself with a Telegram chat, from the command line (making super-simple, not necessarily interactive bots). See a blog post for some details on ‘what and why’.

(Please note that these scripts were intended for internal use, so they come ‘as is’, without any kind of guarantees.)

Installation

No special procedures are needed – just download the files/clone the repo to a local folder and make sure that files tgs and tgs-setup are executable (chmod u+x as necessary – these are just bash scripts). You might want to add this directory to your PATH for easy access.

Usage

The procedure is as follows:

  • first, you create a personal bot (it’s simple), and take a note of your token ID.
  • then, you’d need to save your bot access data to the file named tg.bot (in the same directory as tgs script). You could do this either by running ./tgs-setup <token-ID> (requires curl and egrep, which were already installed on my GNU/Linux system by default), or manually, using the format :
TOKEN=XXX...:YYY...
CHAT_ID=NNN...

After this, sending stuff from the command line can be done as:

tgs -m "hello world" # sends a text message
tgs -i ./my_file.png # sends an image to be shown in the chat.
tgs -f ./my_file.ext # sends any file as an attachment to the chat.
tgs -s HappyCat # sends a sticker

Note that for the last command to work you’d need to find the sticker’s file-id first: run ./tgs -g, send the desired sticker to your bot, and then follow instructions to save it. Some usage info is available from ./tgs -h.

Note that I didn’t do any proper testing, but some more advanced use-cases seem to work out, such as:

  • ./my_arbitrary_program | ./tgs -m - will redirect the output to your chat (note the - symbol in the very end of the command!);
  • ls | ./tgs -m - will send you the contents of the current directory;
  • echo "I have $(ls *.org | wc -l) org files in the dir" | ./tgs -m - will send the text “I have … org files in the dir”, substituting the valid number of *.org files in the corresponding directory,
  • and so on.

In principle, it seems not very difficult to implement progress bars, message updates, and some other nice things – but if you need this, you might want to consider a better/more complicated interface to Telegram bots (which already exist, in Python or even as shell scripts). The purpose of this tool was to get a small-footprint script to get the job done quickly.

Feedback and contributions

… are very welcome – please feel free to open an issue here, or reach out to me, preferably via email.

About

A simple bash wrapper around curl to send messages to Telegram chats

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages