{"id":16366386,"url":"https://github.com/centminmod/telegram-send","last_synced_at":"2025-10-26T07:30:28.580Z","repository":{"id":80280101,"uuid":"383058664","full_name":"centminmod/telegram-send","owner":"centminmod","description":"send messages via linux command line via Telegram Bot API","archived":false,"fork":false,"pushed_at":"2021-07-12T04:42:37.000Z","size":132,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T16:46:25.395Z","etag":null,"topics":["telegram","telegram-bot","telegram-bot-api"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/centminmod.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-07-05T07:52:07.000Z","updated_at":"2024-08-17T04:13:53.000Z","dependencies_parsed_at":"2024-02-08T08:02:18.051Z","dependency_job_id":null,"html_url":"https://github.com/centminmod/telegram-send","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Ftelegram-send","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Ftelegram-send/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Ftelegram-send/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centminmod%2Ftelegram-send/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/centminmod","download_url":"https://codeload.github.com/centminmod/telegram-send/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238284723,"owners_count":19446715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["telegram","telegram-bot","telegram-bot-api"],"created_at":"2024-10-11T02:46:18.768Z","updated_at":"2025-10-26T07:30:28.227Z","avatar_url":"https://github.com/centminmod.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tgsend.sh\n\nSend or update messages or send text files to your own Telegram Bot API created using BotFather:\n\n* https://core.telegram.org/bots#3-how-do-i-create-a-bot\n* https://core.telegram.org/bots/api#sendmessage\n\n## Telegram BotFather\n\n![Telegram BotFather Bot Creation](/images/telegram-botfather-01.png)\n\n# Dependencies\n\nRequires jq json tool install:\n\n```\napt-get -y install jq\n```\nor \n```\nyum -y install jq\n```\n\n# Usage\n\nCreate and populate `tgtoken.ini` file in same directory as tgsend.sh with the following:\n\n```\ntgtoken='YOUR_TELEGRAM_BOT_API_TOKEN'\ntgchatid='YOUR_TELEGRAM_CHATID'\ntgapi=\"https://api.telegram.org/bot$tgtoken\"\n```\n\nYou can find your Telegram chat id to populate variable `tgchatid` using the following command:\n\n```\ntgtoken='YOUR_TELEGRAM_BOT_API_TOKEN'\ntgapi=\"https://api.telegram.org/bot$tgtoken\n\ncurl -4s \"$tgapi/getUpdates\" | jq -r '.result[].message.chat.id'\n```\n\nAvailable commands:\n\n```\n./tgsend.sh \n\nUsage:\n\n./tgsend.sh send \"your message in double quotes\"\n./tgsend.sh sendhtml \"your message in double quotes\"\n\ndisable notifications:\n\n./tgsend.sh sendq \"your message in double quotes\"\n./tgsend.sh sendhtmlq \"your message in double quotes\"\n\nupdate existing message with message_id:\n\n./tgsend.sh update \"your message in double quotes\" message_id\n./tgsend.sh updatehtml \"your message in double quotes\" message_id\n\nupdate existing message with message_id \u0026 disable notifications:\n\n./tgsend.sh updateq \"your message in double quotes\" message_id\n./tgsend.sh updatehtmlq \"your message in double quotes\" message_id\n\nsend file\n\n./tgsend.sh sendf filename\n```\n\n# Examples\n\n## Send messages in plain text or HTML format\n\n```\n./tgsend.sh send \"message text\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-05T08:13:12Z\",\n  \"message\": \"message text\"\n}\n```\n```\n./tgsend.sh sendhtml \"message \u003ci\u003ehtml\u003c/i\u003e\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-05T08:13:20Z\",\n  \"message\": \"message html\"\n}\n```\n```\n./tgsend.sh send \"$(free -mlt)\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-06T00:30:14Z\",\n  \"message\": \"total        used        free      shared  buff/cache   available\\nMem:          31973        7189        2183        2229       22600       22162\\nLow:          31973       29789        2183\\nHigh:             0           0           0\\nSwap:          2045           3        2042\\nTotal:        34019        7192        4226\"\n}\n```\n\n![Telegram Messages](/images/telegram-send-04.png)\n\n## Update an existing message with message_id\n\n```\n./tgsend.sh updateq \"updated message\" 38\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-08T01:05:35Z\",\n  \"message\": \"[msgid: 38 Updated: Thu 08-Jul-21 01:05:34 UTC]  updated message\"\n}\n```\n\n![Telegram Messages](/images/telegram-send-06b.png)\n\n## Send text file\n\n```\n./tgsend.sh sendf test.txt\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-05T08:50:19Z\",\n  \"document\": \"test.txt\",\n  \"mime\": \"text/plain\",\n  \"size\": 2\n}\n```\n\n![Telegram File Send](/images/telegram-send-03.png)\n\n## Send text message with Telegram message_id added\n\nNew feature which by default is enabled is to add the message_id to the messages via option `tg_addmsgid='y'`\n\n```\n./tgsend.sh send \"message v3\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-06T22:33:34Z\",\n  \"message\": \"[msgid: 37] message v3\"\n}\n```\n\n![Telegram File Send](/images/telegram-send-05.png)\n\nSending Centmin Mod LEMP stack cminfo command for JSON formatted cpu and memory statistics\n\n```\n./tgsend.sh send \"$(cminfo sar-json | jq -r '.\"cpu-load\"[]')\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-08T01:16:15Z\",\n  \"message\": \"[msgid: 40] {\\n  \\\"cpu\\\": \\\"all\\\",\\n  \\\"user\\\": 1.21,\\n  \\\"nice\\\": 0,\\n  \\\"system\\\": 0.49,\\n  \\\"iowait\\\": 0.43,\\n  \\\"steal\\\": 0,\\n  \\\"idle\\\": 97.87\\n}\"\n}\n```\n```\n./tgsend.sh send \"$(cminfo sar-json | jq -r '.\"memory\"')\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-08T01:17:09Z\",\n  \"message\": \"[msgid: 41] {\\n  \\\"memfree\\\": 3111888,\\n  \\\"memused\\\": 29629116,\\n  \\\"memused-percent\\\": 90.5,\\n  \\\"buffers\\\": 1323936,\\n  \\\"cached\\\": 17754908,\\n  \\\"commit\\\": 25211564,\\n  \\\"commit-percent\\\": 72.37,\\n  \\\"active\\\": 13057488,\\n  \\\"inactive\\\": 9479208,\\n  \\\"dirty\\\": 84,\\n  \\\"swpfree\\\": 2091768,\\n  \\\"swpused\\\": 3328,\\n  \\\"swpused-percent\\\": 0.16,\\n  \\\"swpcad\\\": 204,\\n  \\\"swpcad-percent\\\": 6.13\\n}\"\n}\n```\n\n![Telegram File Send](/images/telegram-send-07.png)\n\n# Cloudflare Firewall Event log message sent\n\nMy custom `cf-analytics-graphql.sh` script querying [Cloudflare Firewall GraphQL API](https://developers.cloudflare.com/analytics/graphql-api) for a sepcific IP address - `185.34.23.76` and filter only JS Challenge triggered events for past 24hrs of firewall event entries and saving JSON formatted output in file at /home`/cf-graphql-json-output/cf-graphql-ip.json` which we can send via Telegram Bot. Unfortunately, Telegram messages have a 4096 character limit, so larger messages are not supported in `tgsend.sh` yet - working on adding support to paginate longer messages to be send by multiple messages. But for purpose of this example, the JSON output is \u003c 4096 characters.\n\n```\n./cf-analytics-graphql.sh ip-hrs 24 185.34.23.76 jschallenge\n\n\nJSON log saved: /home/cf-graphql-json-output/cf-graphql-ip.json\nCSV converted log saved: /home/cf-graphql-json-output/cf-graphql-ip.csv\n\n\n{ \"query\":\n    \"query {\n      viewer {\n        zones(filter: {zoneTag: $zoneTag}) {\n          firewallEventsAdaptiveGroups(\n            limit: $limit,\n            filter: $filter,\n            orderBy: [datetime_DESC]\n            ) {\n            dimensions {\n              action\n              botScore\n              botScoreSrcName\n              source\n              datetime\n              clientIP\n              clientAsn\n              clientCountryName\n              edgeColoName\n              clientRequestHTTPProtocol\n              clientRequestHTTPHost\n              clientRequestPath\n              clientRequestQuery\n              clientRequestScheme\n              clientRequestHTTPMethodName\n              clientRefererHost\n              clientRefererPath\n              clientRefererQuery\n              clientRefererScheme\n              edgeResponseStatus\n              clientASNDescription\n              userAgent\n              kind\n              originResponseStatus\n              ruleId\n              rayName\n            }\n          }\n        }\n      }\n    }\",\n  \n    \"variables\": {\n      \"zoneTag\": \"zoneid\",\n      \"limit\": 100,\n      \"filter\": {\n        \"clientIP\": \"185.34.23.76\",\n        \"action\": \"jschallenge\",\n        \n        \n        \"datetime_geq\": \"2021-07-11T04:25:24Z\",\n        \"datetime_leq\": \"2021-07-12T04:25:24Z\"\n      }\n    }\n  }\n\n------------------------------------------------------------------\nCloudflare Firewall (enterprise)\n------------------------------------------------------------------\nsince: 2021-07-11T04:25:24Z\nuntil: 2021-07-12T04:25:24Z\n------------------------------------------------------------------\n1 Firewall Events for Request IP: 185.34.23.76\n------------------------------------------------------------------\n      1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME GET HTTP/1.0 892c40e1bef548368f6b37ab2a1dcf37\n------------------------------------------------------------------\n      1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME GET HTTP/1.0\n------------------------------------------------------------------\n      1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME domain.com GET HTTP/1.0\n------------------------------------------------------------------\n      1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME domain.com GET HTTP/1.0 / \n------------------------------------------------------------------\n185.34.23.76 66d11159cf2f7b43 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME 2021-07-11T09:39:59Z domain.com GET HTTP/1.0 / \n------------------------------------------------------------------\n{\n  \"results\": [\n    {\n      \"action\": \"jschallenge\",\n      \"botScore\": 1,\n      \"botScoreSrcName\": \"Heuristics\",\n      \"clientASNDescription\": \"R-LINE-AS\",\n      \"clientAsn\": \"47895\",\n      \"clientCountryName\": \"RU\",\n      \"clientIP\": \"185.34.23.76\",\n      \"clientRefererHost\": \"domain.com\",\n      \"clientRefererPath\": \"\",\n      \"clientRefererQuery\": \"\",\n      \"clientRefererScheme\": \"https\",\n      \"clientRequestHTTPHost\": \"domain.com\",\n      \"clientRequestHTTPMethodName\": \"GET\",\n      \"clientRequestHTTPProtocol\": \"HTTP/1.0\",\n      \"clientRequestPath\": \"/\",\n      \"clientRequestQuery\": \"\",\n      \"clientRequestScheme\": \"https\",\n      \"datetime\": \"2021-07-11T09:39:59Z\",\n      \"edgeColoName\": \"DME\",\n      \"edgeResponseStatus\": 503,\n      \"kind\": \"firewall\",\n      \"originResponseStatus\": 0,\n      \"rayName\": \"66d11159cf2f7b43\",\n      \"ruleId\": \"892c40e1bef548368f6b37ab2a1dcf37\",\n      \"source\": \"firewallrules\",\n      \"userAgent\": \"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3355.4 Safari/537.36\"\n    }\n  ]\n}\n```\n```\n./tgsend.sh send \"$(cat /home/cf-graphql-json-output/cf-graphql-ip.json | jq -r)\"\n{\n  \"from\": \"centmin\",\n  \"to\": \"George\",\n  \"date\": \"2021-07-12T04:31:49Z\",\n  \"message\": \"[msgid: 50] {\\n  \\\"results\\\": [\\n    {\\n      \\\"action\\\": \\\"jschallenge\\\",\\n      \\\"botScore\\\": 1,\\n      \\\"botScoreSrcName\\\": \\\"Heuristics\\\",\\n      \\\"clientASNDescription\\\": \\\"R-LINE-AS\\\",\\n      \\\"clientAsn\\\": \\\"47895\\\",\\n      \\\"clientCountryName\\\": \\\"RU\\\",\\n      \\\"clientIP\\\": \\\"185.34.23.76\\\",\\n      \\\"clientRefererHost\\\": \\\"domain.com\\\",\\n      \\\"clientRefererPath\\\": \\\"\\\",\\n      \\\"clientRefererQuery\\\": \\\"\\\",\\n      \\\"clientRefererScheme\\\": \\\"https\\\",\\n      \\\"clientRequestHTTPHost\\\": \\\"domain.com\\\",\\n      \\\"clientRequestHTTPMethodName\\\": \\\"GET\\\",\\n      \\\"clientRequestHTTPProtocol\\\": \\\"HTTP/1.0\\\",\\n      \\\"clientRequestPath\\\": \\\"/\\\",\\n      \\\"clientRequestQuery\\\": \\\"\\\",\\n      \\\"clientRequestScheme\\\": \\\"https\\\",\\n      \\\"datetime\\\": \\\"2021-07-11T09:39:59Z\\\",\\n      \\\"edgeColoName\\\": \\\"DME\\\",\\n      \\\"edgeResponseStatus\\\": 503,\\n      \\\"kind\\\": \\\"firewall\\\",\\n      \\\"originResponseStatus\\\": 0,\\n      \\\"rayName\\\": \\\"66d11159cf2f7b43\\\",\\n      \\\"ruleId\\\": \\\"892c40e1bef548368f6b37ab2a1dcf37\\\",\\n      \\\"source\\\": \\\"firewallrules\\\",\\n      \\\"userAgent\\\": \\\"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3355.4 Safari/537.36\\\"\\n    }\\n  ]\\n}\"\n}\n```\n\n![Telegram File Send](/images/telegram-send-08.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentminmod%2Ftelegram-send","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcentminmod%2Ftelegram-send","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentminmod%2Ftelegram-send/lists"}