topkecleon / telegram-bot-bash

Telegram bot written in bash
Other
426 stars 123 forks source link

send_* fuctions' return value #190

Open enamp opened 2 years ago

enamp commented 2 years ago

Hi Almost all send_* and some other functions from sendMessage.sh are returning non-zero values after successfull execution It breaks sometest && send_* || handle_error scenario I have 2 options to solve it:

  1. add || return 0 to all affected lines: [ -n "${BOTSENT[ERROR]}" ] && processError $ARGS || return 0
  2. rewrite error test statement to [ ! -n "${BOTSENT[ERROR]}" ] ||
gnadelwartz commented 2 years ago

for historical reason the return value for send functions are undefined and later on I added the telegram response to allow checking the telegram response.

I understand it would be better to return a defined return value, let me think about, but it's hard to enshure that the value is correct in all cases as bash return the value of the last exected command.

therefore you always have to check BOTSENT[] values in your script to know what's returned from telegram.

nevertheless I'll think about to improve the situation.

gnadelwartz commented 2 years ago

Thinking more about, currently a non zero return value means bashbot think there is something wrong with your arguments or an internal error happend. a zero return value means nothing bad happend "arguments seems ok and sent to telegram". In theory it should work like this:

if send_xxx then
    # sent to telegram, check telegram response
    echo "Telegram response BOTSENT[*]"
else
   # not sent to telegram, may be wromng argumrents or internal error
   echo "Ups, something wrong"
fi

# or like this
if send_xxx && -n "$[BOTSENT[ERROR]"; then
   echo "Sent to telegram, response: BOTSENT[*]"
fi

but yes it's not perfect :-) and currntly does not work ... I'll try to imporove it in future