From 314fc060d315cf35383980761c22a0c4c89e54b4 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 27 Nov 2023 09:44:24 +1100 Subject: [PATCH] Initial checkin --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 1 + README.md | 36 +++++++++++++++++++++++++++++++++++ img/this_is_a_test.png | Bin 0 -> 7449 bytes telegram-send.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100755 README.md create mode 100644 img/this_is_a_test.png create mode 100755 telegram-send.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..940e942902c4c95c53cc11d73aa9ce43019c31f2 GIT binary patch literal 6148 zcmeH~J!%6%427R!7lt%jx}3%b$PET#pTHMLVK4#Pfk0Bv(ew1vWSu%J;R&QS(yZ9s zuh>}uu>I%x1(*PA=&sm#n3*wO;SD!jzD^(a>-+t}idTWBh?%i6VYXk}5)lvq5fA|p z5P<~|$Wt7f=LJ2J9z_I1U>OAb`_SmFy>z6;r-LCz0P33MFs@^kpf)d1d+A7Jg=RH9 zShZS=AzqJmYOCvd=}66XSPdUmcQ&75XqN4;#)M`)L_q{ZU`Ak-`Q+#Sk^bBKKWkAc z0wVCw2-x~?I_&vUb+$gdp4VTi>gz$L#^nq@egc^IQM{#xaliS3+Dk_&D>VHG1O^2W H_)`MkK;;pJ literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md new file mode 100755 index 0000000..3a9dd8a --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Overview + +Super simple curl wrapper to send Telegram messages. + +# Requirements + + - [jq](https://jqlang.github.io/jq/) + - curl + +# Usage + +```text +usage: ./telegram-send.sh "text to send" + +Instructs telegram bot to send the supplied message to a chat. + +Needs these files to work: +File with telegram bot token: /Users/rob/.telegram/bottoken +File with telegram chat id: /Users/rob/.telegram/chatid +``` + +# Example + +## CLI command + +```text +rob@crom:telegram-send$ ./telegram-send.sh "this is a test" +rob@crom:telegram-send$ +``` + +## Telegram output + +![telegramoutput](img/this_is_a_test.png "telegram output") + + + diff --git a/img/this_is_a_test.png b/img/this_is_a_test.png new file mode 100644 index 0000000000000000000000000000000000000000..6ed4f5f710b030b0160846ef0d08a7f47d909c93 GIT binary patch literal 7449 zcma)gbyQr-viIN)!68Tpt~0p15AIHI3+@)&-8I<3J-9mr4W8icPJqCK!5+Eye&?R` zy?@?bt9Dga)vv0ny4PO2J4!`K1_SjiDgXe$0Lx0Mz4GB#VnjxKeIJog7XtvO3pNrG zDqsl-3KbVeOB*{206;b>EdxnMU6&y6()T!yKvY!ji0l|X5l0-2f`UwvhB_z|$4vZ9 zJyi%5D}jcjimC>@s*@W%JHb#ef~v}puoxn?I~ntm$}$qOiRInuy5sbN!_jA@={gqIR41r&UI)4AQiJPYqhS zu_Z`zAF$;tlE7}Cx5CECWfS=IKBz?<0342leLVZ&bG&}z-i50grYvK+geR>iZBkKS! zNJO5TE(V`#QZUMBk25Aia&%D+n}c}%8^LrnlVU>p>b+pPpg&NA(IdMNf$gt(W^e*} z-j&Jtxv5R4U_c&gpOvLyfcJS;vd9l6aQLlj~THX7&awKhScUgCV~ z_Fno4nVxidDuavZ3FO38n&qVHcHPnKoGcRH<{+ns%5TmP*)0I6*c&Ht^1V>YE0+e^ zXk#EY3n7}?y)GxB%e)t7dZL+`RAXziC%|}TLy0WR6GD4QRUDsRZ;>Y%?*s(Y-NnY~ zql?CnyBIorTZ;97Er`t7p6?;8;Po93&->jEpj3gc6vaJ)l`uxE4ia)gyyzqO{oXq~ zi2e;00Sx9=hyn%TM4wz8CSD+A9l{x4zW|36z_mrh3zOY%<3w(NxY*A!gGLTZOau?= zNB#{Mra&GL!;3_<5%)=CGe=pLa2v(F4iPUvrYDyRR(t=RI!sIa^e@VCc*cl3iRPK< z8HOW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@}M()GQ-$kben)wy_||GA9;ODRd#iW>+252tA6ng9R* literal 0 HcmV?d00001 diff --git a/telegram-send.sh b/telegram-send.sh new file mode 100755 index 0000000..60e4399 --- /dev/null +++ b/telegram-send.sh @@ -0,0 +1,42 @@ +#!/bin/bash +TOKENFILE=${HOME}/.telegram/bottoken +CHATFILE=${HOME}/.telegram/chatid + +function die() { + echo "FATAL: $*" >&2 + exit 1 +} + +function usage() { + echo "usage: $0 \"text to send\"" + echo + echo "Instructs telegram bot to send the supplied message to a chat." + echo + echo "Needs these files to work:" + echo "File with telegram bot token: ${TOKENFILE}" + echo "File with telegram chat id: ${CHATFILE}" +} + +if [[ $1 == "-h" || $# -ne 1 ]]; then + usage + exit 1 +fi + +[[ ! -e ${TOKENFILE} ]] && die "bot token file '${TOKENFILE}' doesn't exist"; +[[ ! -e ${CHATFILE} ]] && die "chat id file '${CHATFILE}' doesn't exist"; + +TOKEN=$(egrep -v '^#' "$TOKENFILE") +CHAT=$(egrep -v '^#' "$CHATFILE") + +[[ -z ${TOKEN} ]] && die "bot token file '${TOKENFILE}' appears empty"; +[[ -z ${CHAT} ]] && die "chat id file '${CHATFILE}' appears empty"; + +msg="$*" + +res=$(curl -s --data "text=$msg" --data "chat_id=$CHAT" 'https://api.telegram.org/bot'$TOKEN'/sendMessage' 2>&1) +rv=$? +[[ $rv -ne 0 ]] && fatal "curl failed" +status=$(jq -r .ok <<<"${res}") +[[ $status != "true" ]] && die "telegram API returned failure: ${res}" +exit 0 +