Telegram Bot Exec Terminal Command
- Running command on IoT Device through telegram bot
- Transfering Files through telegram bot
-
Prebuilt Binary you can download prebuild binary depends on your os and arch, available prebuilts here:
https://github.com/alfiankan/teleterm/releases/tag/v2.1.0
Once the binary is downloaded, you can move the binary to /usr/local/bin
-
Build From Source If your arch os is not listed in the prebuilt binary you can build from source.
Required :
- Go ^1.18
- gcc
How to build :
- clone
git clone https://github.com/alfiankan/teleterm
- build
go build -o teleterm-bin ./cmd...
Required :
- Telegram bot tokens, to get tokens please refer to Telegram Docs
-
Setting Up Config
To setup fresh teleterm run
teleterm fresh
teleterm will create folder on your home folder with name
.teleterm
contains :-
config.yaml config yaml hold teleterm config :
Key Value telegram_token telegram token from bot father shell_executor /bin/bash
or/bin/sh
.etc default is/bin/bash
example config.yaml
teleterm: telegram_token: "my_tele_token" shell_executor: "/bin/bash"
-
-
Run teleterm
To run teleterm simply run
teleterm
and log info will displayed.
Command | Desc | Example |
---|---|---|
/refresh | Refresh the bot system | /refresh |
/run <command> |
executing command | /run ping -c 5 8.8.8.8 |
/getfile <filepath> |
transfer donwload file from bot server | /getfile /home/raspi/myfile.txt |
/addbutton <button_name>!!<command> |
add button shortcut | /addbutton ping!!ping -c 5 8.8.8.8 |
/deletebutton <button_name> |
delete button shortcut | /deletebutton ping |
To execute commands from telegram just send a message using the following format :
/run <command>
for example :
/run ping -c 5 8.8.8.8
output replied by telegram bot :
To execute commands from the telegram button, you need to add a button, just send a message using the following format :
/addbutton <button_name>!!<command>
for example :
/addbutton ping!!ping -c 5 8.8.8.8
output replied by telegram bot :
a new button will appear :
To run a command using a shortcut just click the telegram button the bot will find the exec command from the database.
To remove a shortcut simply send a message using the following format:
/deletebutton <button_name>
for example :
/deletebutton ping
output replied by telegram bot :
then updated buttons will appear.
To upload a file just send the document on telegram :
By default it will upload in cwd path if you don't add target path on file mention.
output replied by telegram bot :
To download the file simply send a message using the following format :
/getfile <filepath>
Filepath is the filepath where teleterm runs
for example :
/getfile /home/raspi/hello.txt
output replied by telegram bot :