Skip to content

Instantly share code, notes, and snippets.

@kraftwerk28
Created February 5, 2022 22:02
Show Gist options
  • Save kraftwerk28/f903345470878a62ab1401f4c31642d1 to your computer and use it in GitHub Desktop.
Save kraftwerk28/f903345470878a62ab1401f4c31642d1 to your computer and use it in GitHub Desktop.
#!/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