1 of 12

How to create a “Bash” Telegram Bot in 2 minutes in 5 lines

海豹

2 of 12

About me

  • 海豹
  • A High School Student
  • https://seadog007.me

3 of 12

Code

1 while true

2 do

3 who=`who` && [ $? -eq 0 ] && [ "$who" != "$lastwho" ] && curl --data "chat_id=80973595&text=$who" -X GET https://api.telegram.org/bot_token/sendMessage && lastwho=$who

4 sleep 1

5 done

4 of 12

Compressed

while true; do; who=`who` && [ $? -eq 0 ] && [ "$who" != "$lastwho" ] && curl --data "chat_id=80973595&text=$who" -X GET https://api.telegram.org/bot_token/sendMessage && lastwho=$who; sleep 1; done

5 of 12

1. Prepare Bot Token

Telegram: @botfather

Live Demo

6 of 12

2. Get Your User ID

Telegram: @RawDataBot

Live Demo

7 of 12

3. Fetch Your Data

who=`who`

8 of 12

4. Comparing Your Data

[ $? -eq 0 ] && [ "$who" != "$lastwho" ]

9 of 12

5. Send the Message

curl --data "chat_id=id&text=$who" -X GET https://api.telegram.org/bot_token/sendMessage

10 of 12

6. Put it in a Loop

While true�do

done

11 of 12

7. Run it in tmux

Live Demo

12 of 12

Thanks For Listening