Created
November 30, 2023 19:52
-
-
Save patillacode/9ea075a00b84ec869bcf62337c930dd6 to your computer and use it in GitHub Desktop.
telegram send mesage
This file contains hidden or 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 | |
# credit to: jogerj (https://gist.github.com/dideler/85de4d64f66c1966788c1b2304b9caf1?permalink_comment_id=4327762#gistcomment-4327762) | |
TELEGRAM_BOT_TOKEN="botid:token" | |
CHAT_ID="1234567890" | |
send_telegram () { | |
title="$1" | |
timestamp="$(date -R)" | |
msg="$title\n$timestamp\n\n$(echo "$2" | sed -z -e 's|\\|\\\\|g' -e 's|\n|\\n|g' -e 's|\t|\\t|g' -e 's|\"|\\"|g')" | |
entities="[{\"offset\":0,\"length\":${#title},\"type\":\"bold\"},{\"offset\":$((${#title}+1)),\"length\":${#timestamp},\"type\":\"italic\"}]" | |
data="{\"chat_id\":\"$CHAT_ID\",\"text\":\"$msg\",\"entities\":$entities,\"disable_notification\": true}" | |
curl -s -o /dev/null -H 'Content-Type: application/json' -d "$data" -X POST https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment