-
-
Save ultragtx/285bc14bb8f632afc7311fe2519cd535 to your computer and use it in GitHub Desktop.
Allows to send a message to a Telegram contact once configured telegram-cli (vysheng/tg) without entering the telegram-cli and using the contact / group name, not its ide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Uses telegram-cli to send a message to the given destination | |
# Usage: ./telegram_msg <DESTINATION> <MESSAGE> | |
#============================================================== | |
# Constants | |
#============================================================== | |
APP_NAME=telegram_msg | |
# Name of the app as appears in logs | |
APP="/usr/local/bin/telegram-cli" | |
# telegram-cli location | |
PUBKEY="/opt/telegram-cli/tg-server.pub" | |
INIT_TIME=0.5 | |
# Time telegram-cli bootstraps including retrieving | |
# contacts | |
#============================================================== | |
# Arguments | |
#============================================================== | |
DESTINATION=$1 | |
MESSAGE=$2 | |
shift | |
#============================================================== | |
# Code | |
#============================================================== | |
#-------------------------------------------------------------- | |
# 1. Check arguments | |
#-------------------------------------------------------------- | |
# Destination | |
if [[ -z "$DESTINATION" ]]; then | |
>&2 echo "Destination not set" | |
logger -t $APP_NAME "Failed to send: Destination unset" | |
exit 1 | |
fi | |
# Message | |
if [[ -z "$MESSAGE" ]]; then | |
>&2 echo "Message not set" | |
logger -t $APP_NAME "Failed to send: Message unset" | |
exit 2 | |
fi | |
# Join messages | |
# # Make temporal file with all messages | |
tmp_file=$(mktemp) | |
while (( "$#" )); do | |
echo "$1" >> $tmp_file | |
shift | |
done | |
#-------------------------------------------------------------- | |
# 2. Send | |
#-------------------------------------------------------------- | |
((sleep $INIT_TIME && echo send_text $DESTINATION $tmp_file) | \ | |
$APP -k $PUBKEY -W) # &> /dev/null | |
# Log | |
logger -t $APP_NAME "Sent message via Telegram @ bitcoin" | |
# Delete temporaries and finish | |
rm $tmp_file | |
echo "$USER sent a message via Telegram" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment