#!/bin/sh #---------------------------------------------------------------------------------------- # /var/install/bin/telegram-send-test-message - send Telegram test message # # Copyright (c) 2016-2023 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2016-01-05 jed # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------------- # read eislib . /var/install/include/eislib module_name='telegram' # debug mode true/false #debug=true if ${debug:-false} then exec 2> /tmp/${module_name}-send-test-message-trace$$.log set -x ask_debug=true export ask_debug fi act_pmode=`get_printmode` # check if screensize handling is available if [ -n "${_EISLIB_SCREENSIZE_Y}" ] then if check_screensize then # # define maxrownum = _EISLIB_SCREENSIZE # - 3 Header Lines # - 1 Footer Lines # ask line maxcolnum=`expr ${_EISLIB_SCREENSIZE_X} - 1` maxrownum=`expr ${_EISLIB_SCREENSIZE_Y} - 4` true else mecho --info "Return to calling script" exit 1 fi else # default if screensize handling is not available maxcolnum=79 maxrownum=18 fi maxcolnum=60 # load configuration . /etc/config.d/telegram if [ -n "`echo "${TELEGRAM_KEEP_ALIVE_TEXT}" | sed -e 's/^ *//' -e 's/ *$//'`" ] then msg="${TELEGRAM_KEEP_ALIVE_TEXT}" else msg='Hello World!' fi if [ -n "`echo "${TELEGRAM_KEEP_ALIVE_ADDR}" | sed -e 's/^ *//' -e 's/ *$//'`" ] then peer="${TELEGRAM_KEEP_ALIVE_ADDR}" else peer='' fi u_exit=0 until [ ${u_exit} -eq 1 ] do clrhome mecho --info "Send Telegram test message" mecho mecho "Peer example: a users first and last name, separated by '_'. (e.g. John_Doe)" mecho " a secret chat name, prefixed by '!_' and separated by '_'. (e.g. !_John_Doe)" mecho " a chat name, spaces replaced by '_'. (e.g. Eisfair_general_news)" mecho /var/install/bin/ask "Enter peer [q]" "${peer}" '+' > /tmp/ask.$$ rc=$? peer=`cat /tmp/ask.$$ | sed -e 's/^ *//' -e 's/ *$//'` rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then exit 1 fi case "${peer}" in [qQ] ) # quit u_exit=1 ;; * ) /var/install/bin/ask "Enter text [q]" "${msg}" '+' > /tmp/ask.$$ rc=$? msg=`cat /tmp/ask.$$ | sed -e 's/^ *//' -e 's/ *$//'` rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then exit 1 fi case "${msg}" in [qQ] ) # quit u_exit=1 ;; * ) echo if /var/install/bin/ask "Sending message '${msg}' to peer '${peer}'" then echo if [ "${START_TELEGRAM}" = 'yes' ] then # send message using the telegram-cli daemon eval peername="'${peer}'" eval msgtext="'${msg}'" # echo "/usr/bin/send-telegram-message.sh --peer ${peerstr} --msg ${msgstr}" /usr/bin/send-telegram-message.sh --peer ${peername} --msg "${msgtext}" else # send message using the telegram-cli binary program, which # might cause problems when trying to send secret chat messages msgtext="msg ${peer} '${msg}'" # echo "/usr/bin/telegram-cli -W ${msgtext}" /usr/bin/telegram-cli -W ${msgtext} fi echo anykey fi ;; esac esac done exit 0