Skip to content

Instantly share code, notes, and snippets.

@yetimdasturchi
Created July 5, 2022 00:58
Show Gist options
  • Save yetimdasturchi/ccf3a985de0693a8fd92eb2e666dd65d to your computer and use it in GitHub Desktop.
Save yetimdasturchi/ccf3a985de0693a8fd92eb2e666dd65d to your computer and use it in GitHub Desktop.

Telegram chat botni linux shell orqali boshqarish

Curl kengaytmasini o'rnatish

Debian:

sudo apt install curl

Arch:

sudo pacman -S curl

Foydalanish

chmod a+x bot.sh
bot.sh -h
bot.sh "Salom dunyo"
#!/bin/bash
CHAT_ID="indefikator"
BOT_TOKEN="tokeningiz"
# Ilovadan foydalanish qo'llanmasi
if [ "$1" == "-h" ]; then
echo "Foydalanish: `basename $0` \"xabar matni\""
exit 0
fi
# Xabar kiritilmasa
if [ -z "$1" ]
then
echo "Xabar matnini kiriting"
exit 0
fi
# Argumentlar soni bittadan ortiq bo'lsa
if [ "$#" -ne 1 ]; then
echo "Faqatgina bitta argument qabul qilinadi. Xabar so'zlari alohida argument sifatida qabul qilinmasligi uchun xabarni qo'shtirnoq ichiga oling"
exit 0
fi
# Curl orqali so'rovni yuborish
curl -s --data "text=$1" --data "chat_id=$CHAT_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment