Skip to content

Instantly share code, notes, and snippets.

@davidlj95
Last active November 7, 2018 21:33
Show Gist options
  • Select an option

  • Save davidlj95/570933a25ea37ff69cf03fc568ddbea0 to your computer and use it in GitHub Desktop.

Select an option

Save davidlj95/570933a25ea37ff69cf03fc568ddbea0 to your computer and use it in GitHub Desktop.
Telegram file sender via CLI
#!/bin/sh
# tgm: TeleGram send Message
# Sends a message via Telegram (using telegram-cli)
# Author: davidlj95
#
# Telegram CLI:
# https://github.com/vysheng/tg
# yay -S telegram-cli-git
# Constants
TELEGRAM_CLI="telegram-cli -W -I -C -e"
# Check enough arguments or help
if [ $# -lt 2 ]; then
echo "Usage: tgm <nickname> <message>"
echo "Sends the message to the Telegram nickname"
exit 1
fi
# Parse arguments
nickname="$1"
shift
message="$@"
# Find user id
userid=$($TELEGRAM_CLI "contact_search $nickname" \
| grep -v '[[:space:]]user#' | grep -Eo 'user#[0-9]+')
if [ $? -ne 0 ]; then echo Nickname \"$nickname\" not found; exit 1; fi
# Do send file
$TELEGRAM_CLI "msg $userid \"$message\"" &> /dev/null
if [ $? -ne 0 ]; then echo Unable to send send messaget 1; fi
@davidlj95

davidlj95 commented Nov 7, 2018

Copy link
Copy Markdown
Author

Telegram File sender

Sends to the Telegram nickname the specified file

Usage

./tgm somebody /home/me/somefile.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment