-
Notifications
You must be signed in to change notification settings - Fork 13
/
register-bot.sh
executable file
·58 lines (49 loc) · 1.4 KB
/
register-bot.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
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Telegram Bot Sample
# ===================
# UWiClab, University of Urbino
# ===================
# Basic script to setup the Telegram API webhook.
# Use with a custom bot token, a webhook HTTPS URL and the HTTPS certificate
# installed onto the webhook's web server.
#
# Note: you *need* a domain and a valid certificate for this to work.
function PrintHelp {
echo -e "usage: $0 -s <script HTTPS URL> -c <certificate path> -t <bot token>"
echo "EXAMPLE: $0 -t 123456789:AAF6me-NAHyXLlZ2eO3d3lEdYKnXuZPd98 -c /home/delpriori/bot/public.pem -s https://botify.it/webhook"
echo ""
}
while getopts ":s:c:t:" opt; do
case $opt in
t)
TOKEN=$OPTARG
;;
c)
CERTIFICATE=$OPTARG
;;
s)
SCRIPT=$OPTARG
;;
\?)
PrintHelp
;;
esac
done
if [ -z "$TOKEN" ]; then
echo -e "\nERROR: missing token argument.\n"
PrintHelp;
exit 1;
fi
if [ -z "$CERTIFICATE" ]; then
echo -e "\nERROR: missing <certificate path> argument.\n"
PrintHelp;
exit 1;
fi
if [ -z "$SCRIPT" ]; then
echo -e "\nERROR: missing <script HTTPS URL> argument.\n"
PrintHelp;
exit 1;
fi
echo "Executing: curl -F \"url=$SCRIPT\" -F \"certificate=@$CERTIFICATE\" https://api.telegram.org/bot$TOKEN/setWebhook"
curl -F "url=$SCRIPT" -F "certificate=@$CERTIFICATE" https://api.telegram.org/bot$TOKEN/setWebhook
echo ""