-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_functions.sh
executable file
·49 lines (42 loc) · 1.14 KB
/
common_functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Function to fetch updates from the bot
fetch_updates() {
local bot_token="$1"
curl -s -X GET "https://api.telegram.org/bot${bot_token}/getUpdates"
}
# Function to check if the update list is empty
is_empty_updates() {
local updates="$1"
[[ $(echo "$updates" | jq '.result | length') -eq 0 ]]
}
# Function to check if a value is in an array
contains() {
local n=$#
local value=${!n}
for ((i=1; i < $#; i++)); do
if [ "${!i}" == "${value}" ]; then
return 0
fi
done
return 1
}
# Function to get the last update_id
get_last_update_id() {
local updates="$1"
echo "$updates" | jq -r ".result[$(echo "$updates" | jq '.result | length') - 1].update_id"
}
# Function to send request with offset
send_offset_request() {
local bot_token="$1"
local next_offset="$2"
curl -s -X GET "https://api.telegram.org/bot${bot_token}/getUpdates?offset=${next_offset}"
}
# Function to send message via bot
send_message() {
local bot_token="$1"
local chat_id="$2"
local text="$3"
curl -s -X POST "https://api.telegram.org/bot${bot_token}/sendMessage" \
-d "chat_id=${chat_id}" \
-d "text=$(echo -e "${text}")"
}