diff options
author | Keuin <[email protected]> | 2022-04-01 13:18:23 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-01 14:28:36 +0800 |
commit | 2e05e37c8f192a62b03f85ffec7e0c9f83e05979 (patch) | |
tree | 49ce769da4bc3b28ac566206ed10b51cdad82b04 | |
parent | 53436ff3530ca1a90ad5c7e0b01432ff222e9a08 (diff) |
-rw-r--r-- | README.md | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -77,4 +77,38 @@ def send_message(token: str, message: str): if __name__ == '__main__': send_message('<your token>', 'Hello, world!') -```
\ No newline at end of file +``` + +If you wish a unix tool instead, use the bash script below: + +```shell +#!/bin/bash + +# Disable globbing (expanding '*'), prevent some leaking exploits for security +set -f + +TOKEN='<your API token>' + +# Replace newline with '\\n', using a bash extension +MESSAGE="${1//$'\n'/\\n}" +# Escape '"' (JSON) +MESSAGE="${MESSAGE//\"/\\\"}" +if [ -z "$MESSAGE" ] +then + # Telegram API refuses to send empty string, so we print a help message instead. + echo "Usage: $0 <message>" + exit +fi +#echo "$MESSAGE" +curl -X POST https://kimikuri.keuin.cc/api/message \ + -H 'Content-Type: application/json' \ + --data "{\"token\":\"$TOKEN\",\"message\":\"$MESSAGE\"}" \ + --connect-timeout 10 --retry 3 +``` + +This script requires [cURL](https://curl.se/), which is shipped with almost all linux distros by default. +Place your API token in `$TOKEN`, then execute the script like this: + +```shell +./kimikuri.sh "Hello, world!" +``` |