forked from area31/Telegram-api-msg-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-msg-telegram
executable file
·66 lines (54 loc) · 1.29 KB
/
send-msg-telegram
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
source ${0}.conf
if [ "${DEBUG}" -eq "1" ];then
set -x
fi
TIME=$(date +'%H:%M')
# remove extra whitespace
crunch() {
while read FOO ; do
echo $FOO
done
}
urlencode() {
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf "$c" | xxd -p -c1 | while read x;do printf "%%%s" "$x";done
esac
done
}
case "$1" in
getUpdates)
curl -s "https://api.telegram.org/bot${KEY}/getUpdates"
;;
msg)
while IFS='|' read TIME_MSG TEXT_MSG;do
if [ "${TIME}" = "${TIME_MSG}" ]; then
MSG_HTML=$(urlencode "${TEXT_MSG}")
curl -s "https://api.telegram.org/bot${KEY}/sendMessage?chat_id=${CHAT_ID}&text=${MSG_HTML}"
fi
done < ${MSG_FILE}
;;
msgnow)
MSG_HTML=$(urlencode "$2")
curl -s "https://api.telegram.org/bot${KEY}/sendMessage?chat_id=${CHAT_ID}&text=${MSG_HTML}"
;;
viewmsg)
echo -e "\nAgendamentos:"
while IFS='|' read TIME_MSG TEXT_MSG;do
echo -e "\nHora: ${TIME_MSG}\nMsg: ${TEXT_MSG}"
done < ${MSG_FILE}
echo -e "\nEnd."
;;
*)
echo -e "\nUsage: $0 <options>\n\nOptions:\n"
echo -e "getUpdates - Use this method to receive incoming updates using long polling"
echo -e "Help - This menu"
echo -e "msg - Send messages"
echo -e "viewmsg - View messages\n"
exit 1
;;
esac