Created
February 5, 2022 22:02
-
-
Save kraftwerk28/f903345470878a62ab1401f4c31642d1 to your computer and use it in GitHub Desktop.
Telegram bot for https://t.me/tiling_wm_mastery
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 characters
#!/bin/bash | |
[[ -z $TOKEN ]] && { echo "No bot token provided" >&2; exit 1; } | |
URL="https://api.telegram.org/bot$TOKEN" | |
while :; do | |
res=$(curl -s "$URL/getUpdates" -F offset="${last_upd_id:-0}") | |
last_upd_id=$(jq -r '.result[-1].update_id + 1' <<<"$res") | |
while read -r msg; do | |
mention=$(jq -r \ | |
'.new_chat_members[0] | |
| if .username then "@\(.username)" | |
else "<a href=\"tg://user?id=\(.id)\">\(.first_name)</a>" | |
end' <<<"$msg") | |
text="Привет, $mention, какой <code>WM</code> используешь?" | |
curl -s "${URL}/sendMessage" \ | |
-F chat_id="$(jq -r '.chat.id' <<<"$msg")" \ | |
-F text="$text" \ | |
-F parse_mode="HTML" \ | |
-F reply_to_message_id="$(jq -r '.message_id' <<<"$msg")" | |
done < <(jq -c \ | |
'.result[].message | select(has("new_chat_members"))' <<<"$res") | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment