Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failures for curls #38

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/commands/getme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ steps:
name: Fetch bot information
shell: /bin/bash
command: |
curl "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/getMe"
STATUS=$(curl -I "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/getMe" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [ $STATUS -ge "400" ]; then
echo "Fetch failed with HTTP response code $STATUS"
fi
5 changes: 4 additions & 1 deletion src/commands/greet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ steps:
name: Greet
shell: /bin/bash
command: |
curl "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendMessage?chat_id=$<<parameters.telegram-chat-id>>&text=Hello from CircleCi!"
STATUS=$(curl -I "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendMessage?chat_id=$<<parameters.telegram-chat-id>>&text=Hello from CircleCi!" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [ $STATUS -ge "400" ]; then
echo "Greetings failed with HTTP response code $STATUS"
fi
5 changes: 4 additions & 1 deletion src/commands/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ steps:
name: Telegram Notification
shell: /bin/bash
command: |
curl "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendMessage?chat_id=$<<parameters.telegram-chat-id>>&parse_mode=<< parameters.parse_mode >>&disable_notification=<< parameters.disable_notification >>&text=<< parameters.message >>"
STATUS=$(curl -I https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendMessage?chat_id=$<<parameters.telegram-chat-id>>&parse_mode=<< parameters.parse_mode >>&disable_notification=<< parameters.disable_notification >>&text=<< parameters.message >>" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [ $STATUS -ge "400" ]; then
echo "Notification failed with HTTP response code $STATUS"
fi
9 changes: 8 additions & 1 deletion src/commands/sendgif.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ steps:
name: Send Animated Image
shell: /bin/bash
command: |
if [ ! "$<<parameters.gif-url>>" == "" ]; then curl "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendAnimation?chat_id=$<<parameters.telegram-chat-id>>&animation=<<parameters.gif-url>>"; else echo GIF URL invalid; fi
if [ ! "$<<parameters.gif-url>>" == "" ]; then
STATUS=$(curl -I "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendAnimation?chat_id=$<<parameters.telegram-chat-id>>&animation=<<parameters.gif-url>>" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [ $STATUS -ge "400" ]; then
echo "Sending GIF failed with HTTP response code $STATUS"
fi
else
echo GIF URL invalid;
fi
9 changes: 8 additions & 1 deletion src/commands/sendphoto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ steps:
name: Send Image
shell: /bin/bash
command: |
if [ ! "$<<parameters.image-url>>" == "" ]; then curl "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendPhoto?chat_id=$<<parameters.telegram-chat-id>>&photo=<<parameters.image-url>>"; else echo Image URL invalid; fi
if [ ! "$<<parameters.image-url>>" == "" ]; then
STATUS=$(curl -I "https://api.telegram.org/bot$<<parameters.telegram-bot-token>>/sendPhoto?chat_id=$<<parameters.telegram-chat-id>>&photo=<<parameters.image-url>>" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [ $STATUS -ge "400" ]; then
echo "Sending image failed with HTTP response code $STATUS"
fi
else
echo Image URL invalid;
fi